|
@@ -16,31 +16,44 @@ def plotSquares(ctx):
|
|
|
for i in range(0,w-1):
|
|
|
rsum += i*rs # add to the random value
|
|
|
ctx.save()
|
|
|
- ctx.translate(s*i+1.1**i*dp, 0)
|
|
|
- for j in range(0,h-1):
|
|
|
-
|
|
|
- rv = random.uniform(-rsum, rsum)
|
|
|
- # here comes the box :-)
|
|
|
- #box = shapes.square(s)
|
|
|
-
|
|
|
- # box position
|
|
|
- #curr_cx = - w*s/2 + i*s + rv*dp ; curr_cy = - h*s/2 + j*s + rv*dp
|
|
|
- # transforms.center_at(box, [curr_cx, curr_cy])
|
|
|
+ ctx.translate(s*i + deltaX(i), 0)
|
|
|
+ for j in range(0,h):
|
|
|
#
|
|
|
- # # rotate the box of rv degrees around its center
|
|
|
- # transforms.rotate(box, rv, pivot=(curr_cx, curr_cy))
|
|
|
- # draw the damn box
|
|
|
- # plotter.write(box)
|
|
|
- #
|
|
|
- #ctx.rotate(math.pi * 1 / 4)
|
|
|
- ctx.translate(0, s)
|
|
|
- ctx.save()
|
|
|
- ctx.rotate(rv)
|
|
|
- ctx.rectangle(0,0, s, s)
|
|
|
- ctx.restore()
|
|
|
- ctx.stroke()
|
|
|
+ rv = random.uniform(-rsum, rsum)
|
|
|
+ print str(abs(rv))
|
|
|
+ #grey = translate(abs(rv),0,2,0,0.7)
|
|
|
+ #ctx.set_source_rgb(grey,grey,grey)
|
|
|
+ ctx.save()
|
|
|
+ #remove 0 or relace it with 1 if ypu want Y devercence
|
|
|
+ ctx.translate(0, s*j + deltaY(i,j) * 0.8 )
|
|
|
+ ctx.rotate(rv)
|
|
|
+ ctx.rectangle(s/2,s/2, s, s)
|
|
|
+ ctx.restore()
|
|
|
+ ctx.stroke()
|
|
|
+ #ctx.fill()
|
|
|
ctx.restore()
|
|
|
|
|
|
+def deltaY(i,j):
|
|
|
+# return float(1.1*translate(j,0,h-1,-i*0.3,i*0.3)**2)
|
|
|
+# print "nterpolazione di "+ str(j) + " : " + str(translate(j,-h/2,h/2,-math.pi/2,math.pi/2))
|
|
|
+# return float(math.tan(translate(j,0,h-1,-math.pi/2,math.pi/2)))
|
|
|
+ return float(math.tan(translate(j,0,h,-1.37,1.56))*i)
|
|
|
+
|
|
|
+def deltaX(i):
|
|
|
+ return float(1.31**i*dp)
|
|
|
+
|
|
|
+def translate(value, leftMin, leftMax, rightMin, rightMax):
|
|
|
+ # Figure out how 'wide' each range is
|
|
|
+ leftSpan = leftMax - leftMin
|
|
|
+ rightSpan = rightMax - rightMin
|
|
|
+
|
|
|
+ # Convert the left range into a 0-1 range (float)
|
|
|
+ valueScaled = float(value - leftMin) / float(leftSpan)
|
|
|
+
|
|
|
+ # Convert the 0-1 range into a value in the right range.
|
|
|
+ if(value==h/2):
|
|
|
+ return 0
|
|
|
+ return rightMin + (valueScaled * rightSpan)
|
|
|
|
|
|
if len(sys.argv) < 2:
|
|
|
print("Plz specify output file as argument")
|
|
@@ -49,27 +62,26 @@ if len(sys.argv) < 2:
|
|
|
config = configparser.ConfigParser()
|
|
|
config.read('cfg.ini')
|
|
|
#float RGB touple
|
|
|
-FG_RGB_COLOR=(config['DEFAULT']['FG_R_COLOR'],config['DEFAULT']['FG_G_COLOR'],config['DEFAULT']['FG_B_COLOR'])
|
|
|
-print type(config['DEFAULT']['FG_R_COLOR'])
|
|
|
+FG_RGB_COLOR=(float(config['DEFAULT']['FG_R_COLOR']),float(config['DEFAULT']['FG_G_COLOR']),float(config['DEFAULT']['FG_B_COLOR']))
|
|
|
#A4 in 300 DPI
|
|
|
-width, height = 3508,2480
|
|
|
-offsetX, offsetY = 100,500
|
|
|
+width, height = int(config['DEFAULT']['PAGE_W']),int(config['DEFAULT']['PAGE_H'])
|
|
|
+offsetX, offsetY = int(config['DEFAULT']['OFFSET_X']),int(config['DEFAULT']['OFFSET_Y'])
|
|
|
|
|
|
-w = 22 # width (how many squares - es. 22)
|
|
|
-h = 12 # height (how many squares - es. 12)
|
|
|
-s = 100 # square size (es. 15)
|
|
|
+w = int(config['DEFAULT']['GRID_W']) # width (how many squares - es. 22)
|
|
|
+h = int(config['DEFAULT']['GRID_H']) # height (how many squares - es. 12)
|
|
|
+s = int(config['DEFAULT']['SQUARE_SIZE'])# square size (es. 15)
|
|
|
|
|
|
-rs = 0.01 # random step (rotation increment in degrees)
|
|
|
-dp = 2.25 # dampen (soften random effect for position)
|
|
|
+rs = float(config['DEFAULT']['RANDOM_STEP']) # random step (rotation increment in degrees)
|
|
|
+dp = float(config['DEFAULT']['DAMPEN']) # dampen (soften random effect for position)
|
|
|
rsum = 0 # dummy initial value for rsum
|
|
|
|
|
|
-line_width = 2
|
|
|
+line_width = int(config['DEFAULT']['LINE_WIDTH'])
|
|
|
|
|
|
|
|
|
surface = cairo.PDFSurface (sys.argv[1],width,height)
|
|
|
ctx = cairo.Context (surface)
|
|
|
|
|
|
-ctx.set_source_rgb(config['DEFAULT']['FG_R_COLOR'],config['DEFAULT']['FG_G_COLOR'],config['DEFAULT']['FG_B_COLOR'])
|
|
|
+ctx.set_source_rgb(FG_RGB_COLOR[0],FG_RGB_COLOR[1],FG_RGB_COLOR[2],)
|
|
|
ctx.set_line_width(line_width)
|
|
|
ctx.translate(offsetX, offsetY)
|
|
|
plotSquares(ctx)
|