divergenza/divergenza.py

95 lines
2.8 KiB
Python
Raw Permalink Normal View History

2019-06-03 17:43:30 +02:00
#!/usr/bin/python
'''
Schotter pdf reproduction
It design SchotterR
2019-06-03 23:49:40 +02:00
Author: Luca COnte ''
Website: polybius.fyi
Last edited: June 2019
2019-06-03 17:43:30 +02:00
'''
2019-06-06 18:10:32 +02:00
import math,cairo,random,sys,configparser
2019-06-03 17:43:30 +02:00
def plotSquares(ctx):
global rsum
2019-06-03 23:49:40 +02:00
for i in range(0,w-1):
rsum += i*rs # add to the random value
ctx.save()
2019-06-25 16:02:00 +02:00
ctx.translate(s*i + deltaX(i), 0)
for j in range(0,h):
2019-06-03 17:43:30 +02:00
#
2019-06-25 16:02:00 +02:00
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()
2019-06-03 18:06:26 +02:00
ctx.restore()
2019-06-03 17:43:30 +02:00
2019-06-25 16:02:00 +02:00
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)
2019-06-03 17:43:30 +02:00
2019-06-06 18:10:32 +02:00
if len(sys.argv) < 2:
print("Plz specify output file as argument")
sys.exit(1)
config = configparser.ConfigParser()
config.read('cfg.ini')
2019-06-03 17:43:30 +02:00
#float RGB touple
2019-06-25 16:02:00 +02:00
FG_RGB_COLOR=(float(config['DEFAULT']['FG_R_COLOR']),float(config['DEFAULT']['FG_G_COLOR']),float(config['DEFAULT']['FG_B_COLOR']))
2019-06-03 17:43:30 +02:00
#A4 in 300 DPI
2019-06-25 16:02:00 +02:00
width, height = int(config['DEFAULT']['PAGE_W']),int(config['DEFAULT']['PAGE_H'])
offsetX, offsetY = int(config['DEFAULT']['OFFSET_X']),int(config['DEFAULT']['OFFSET_Y'])
2019-06-03 18:06:26 +02:00
2019-06-25 16:02:00 +02:00
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)
2019-06-03 17:43:30 +02:00
2019-06-25 16:02:00 +02:00
rs = float(config['DEFAULT']['RANDOM_STEP']) # random step (rotation increment in degrees)
dp = float(config['DEFAULT']['DAMPEN']) # dampen (soften random effect for position)
2019-06-03 17:43:30 +02:00
rsum = 0 # dummy initial value for rsum
2019-06-25 16:02:00 +02:00
line_width = int(config['DEFAULT']['LINE_WIDTH'])
2019-06-03 17:43:30 +02:00
2019-06-06 18:10:32 +02:00
surface = cairo.PDFSurface (sys.argv[1],width,height)
2019-06-03 17:43:30 +02:00
ctx = cairo.Context (surface)
2019-06-25 16:02:00 +02:00
ctx.set_source_rgb(FG_RGB_COLOR[0],FG_RGB_COLOR[1],FG_RGB_COLOR[2],)
2019-06-06 18:10:32 +02:00
ctx.set_line_width(line_width)
2019-06-03 18:06:26 +02:00
ctx.translate(offsetX, offsetY)
2019-06-03 17:43:30 +02:00
plotSquares(ctx)
ctx.show_page()