#!/usr/bin/python ''' Schotter pdf reproduction It design SchotterR Author: Luca COnte '' Website: polybius.fyi Last edited: June 2019 ''' import math,cairo,random,sys,configparser def plotSquares(ctx): global rsum for i in range(0,w-1): rsum += i*rs # add to the random value ctx.save() ctx.translate(s*i + deltaX(i), 0) for j in range(0,h): # 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") sys.exit(1) config = configparser.ConfigParser() config.read('cfg.ini') #float RGB touple 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 = int(config['DEFAULT']['PAGE_W']),int(config['DEFAULT']['PAGE_H']) offsetX, offsetY = int(config['DEFAULT']['OFFSET_X']),int(config['DEFAULT']['OFFSET_Y']) 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 = 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 = int(config['DEFAULT']['LINE_WIDTH']) surface = cairo.PDFSurface (sys.argv[1],width,height) ctx = cairo.Context (surface) 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) ctx.show_page()