divergenza/divergenza.py

79 lines
1.7 KiB
Python
Raw 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
'''
import math,cairo,random
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()
ctx.translate(s*i+1.1**i
*dp, 0)
for j in range(0,h-1):
2019-06-03 17:43:30 +02:00
2019-06-03 23:49:40 +02:00
rv = random.uniform(-rsum, rsum)
2019-06-03 17:43:30 +02:00
# 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])
#
# # 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)
2019-06-03 23:49:40 +02:00
ctx.translate(rs*dp*i, s)
2019-06-03 18:06:26 +02:00
ctx.save()
2019-06-03 17:43:30 +02:00
ctx.rotate(rv)
ctx.rectangle(0,0, s, s)
2019-06-03 18:06:26 +02:00
ctx.restore()
2019-06-03 17:43:30 +02:00
ctx.stroke()
2019-06-03 18:06:26 +02:00
ctx.restore()
2019-06-03 17:43:30 +02:00
#float RGB touple
FG_RGB_COLOR=(0,0,0)
#A4 in 300 DPI
width, height = 3508,2480
2019-06-03 18:06:26 +02:00
offsetX, offsetY = 100,500
2019-06-03 23:49:40 +02:00
w = 22 # width (how many squares - es. 22)
2019-06-03 17:43:30 +02:00
h = 12 # height (how many squares - es. 12)
s = 100 # square size (es. 15)
2019-06-03 23:49:40 +02:00
rs = 0.01 # random step (rotation increment in degrees)
2019-06-03 17:43:30 +02:00
dp = 2.25 # dampen (soften random effect for position)
rsum = 0 # dummy initial value for rsum
surface = cairo.PDFSurface ("/tmp/circle.pdf",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(1)
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()