|
@@ -0,0 +1,81 @@
|
|
|
|
+from PIL import Image, ImageDraw, ImageOps
|
|
|
|
+import math
|
|
|
|
+
|
|
|
|
+class Pipe:
|
|
|
|
+ def __init__(self, **params):
|
|
|
|
+ self.pos = (params.get("posX",0), params.get("posY",0))
|
|
|
|
+ self.size = params.get("size",100)
|
|
|
|
+ self.resolution = params.get("resolution",300)
|
|
|
|
+
|
|
|
|
+ def draw(self, im):
|
|
|
|
+ draw = ImageDraw.Draw(im)
|
|
|
|
+ offset = (0,-self.size)
|
|
|
|
+ draw.arc(((self.pos[0]+offset[0])*self.resolution, (self.pos[1]+offset[1])*self.resolution, (self.pos[0]+self.size+offset[0])*self.resolution, (self.pos[1]+self.size+offset[1])*self.resolution), start=0, end=180, fill=255, width=2)
|
|
|
|
+
|
|
|
|
+class Series:
|
|
|
|
+ def __init__(self, **params):
|
|
|
|
+ self.pos = (params.get("posX",0), params.get("posY",0))
|
|
|
|
+ self.size = params.get("size",100)
|
|
|
|
+ self.resolution = params.get("resolution",300)
|
|
|
|
+ self.stepSize = params.get("stepSize",20)
|
|
|
|
+ self.spacer = params.get("spacer",10)
|
|
|
|
+ self.sequence = params.get("sequence",(3,2,1,0))
|
|
|
|
+
|
|
|
|
+ def draw(self, im):
|
|
|
|
+ draw = ImageDraw.Draw(im)
|
|
|
|
+ idx = 0
|
|
|
|
+ end = (0,0)
|
|
|
|
+ prevEnd = (self.pos[0]-self.spacer, self.pos[1]-self.sequence[0]*self.stepSize-self.size/2)
|
|
|
|
+ for height in self.sequence:
|
|
|
|
+ stepBios = height*self.stepSize
|
|
|
|
+ idxBios = idx*self.size
|
|
|
|
+ spacerBios = idx*self.spacer
|
|
|
|
+ pipe = Pipe(posX=self.pos[0]+idxBios+spacerBios+self.spacer, posY=self.pos[1]-stepBios, size=self.size, resolution=self.resolution)
|
|
|
|
+ pipe.draw(im)
|
|
|
|
+
|
|
|
|
+ end = (pipe.pos[0]+pipe.size, pipe.pos[1]-pipe.size/2)
|
|
|
|
+ shape = [(end[0]*self.resolution,end[1]*self.resolution), ((end[0]+self.spacer)*self.resolution, end[1]*self.resolution)]
|
|
|
|
+ draw.line(shape, fill =255, width = 2)
|
|
|
|
+
|
|
|
|
+ shape = [((prevEnd[0]+self.spacer)*self.resolution,prevEnd[1]*self.resolution), ((end[0]-pipe.size)*self.resolution,end[1]*self.resolution)]
|
|
|
|
+ draw.line(shape, fill =255, width = 2)
|
|
|
|
+
|
|
|
|
+ prevEnd = end
|
|
|
|
+ idx+=1
|
|
|
|
+
|
|
|
|
+ shape = [(self.pos[0]*self.resolution,(self.pos[1]+10)*self.resolution), ((end[0]+self.spacer)*self.resolution, (self.pos[1]+10)*self.resolution)]
|
|
|
|
+ draw.line(shape, fill =255, width = 2)
|
|
|
|
+
|
|
|
|
+ shape = [((end[0]+self.spacer)*self.resolution,(self.pos[1]+10)*self.resolution), ((end[0]+self.spacer)*self.resolution, end[1]*self.resolution)]
|
|
|
|
+ draw.line(shape, fill =255, width = 2)
|
|
|
|
+
|
|
|
|
+ shape = [(self.pos[0]*self.resolution,(self.pos[1]+10)*self.resolution), (self.pos[0]*self.resolution, (self.pos[1]-self.sequence[0]*self.stepSize-self.size/2)*self.resolution)]
|
|
|
|
+ draw.line(shape, fill =255, width = 2)
|
|
|
|
+
|
|
|
|
+def crop(im, imSize, x_dpi, y_dpi, resolution=10, tileSize=(280, 180)):
|
|
|
|
+ numTilesX = math.ceil((imSize[0] / resolution) / tileSize[0])
|
|
|
|
+ numTilesY = math.ceil((imSize[1] / resolution) / tileSize[1])
|
|
|
|
+ for y in range(0,numTilesY):
|
|
|
|
+ for x in range(0,numTilesX):
|
|
|
|
+ x0=x*tileSize[0]*resolution
|
|
|
|
+ y0=y*tileSize[1]*resolution
|
|
|
|
+ x1=x0+tileSize[0]*resolution
|
|
|
|
+ y1=y0+tileSize[1]*resolution
|
|
|
|
+ subIm = im.crop((x0, y0, x1, y1))
|
|
|
|
+ ImageOps.invert(subIm).save("out%s-%s.png"%(x,y), dpi=(x_dpi, y_dpi))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def main():
|
|
|
|
+ imSize = (7000, 1800)
|
|
|
|
+ resolution = 10
|
|
|
|
+ im = Image.new('L', imSize, 0)
|
|
|
|
+ #aSide = Series(posX=50, posY=150, sequence=(4,4,2,2,0), resolution=resolution, size=110)
|
|
|
|
+ #aSide.draw(im)
|
|
|
|
+ bSide = Series(posX=50, posY=160, sequence=(5,3,3,1,1), resolution=resolution, size=110)
|
|
|
|
+ bSide.draw(im)
|
|
|
|
+ x_dpi = resolution * 25.4
|
|
|
|
+ y_dpi = resolution * 25.4
|
|
|
|
+ ImageOps.invert(im).save("out.png", dpi=(x_dpi, y_dpi))
|
|
|
|
+ crop(im, imSize, x_dpi, y_dpi)
|
|
|
|
+
|
|
|
|
+main()
|