divergenza.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/python
  2. '''
  3. Schotter pdf reproduction
  4. It design SchotterR
  5. Author: Luca COnte ''
  6. Website: polybius.fyi
  7. Last edited: June 2019
  8. '''
  9. import math,cairo,random
  10. def plotSquares(ctx):
  11. global rsum
  12. for i in range(0,w-1):
  13. rsum += i*rs # add to the random value
  14. ctx.save()
  15. ctx.translate(s*i+1.1**i
  16. *dp, 0)
  17. for j in range(0,h-1):
  18. rv = random.uniform(-rsum, rsum)
  19. # here comes the box :-)
  20. #box = shapes.square(s)
  21. # box position
  22. #curr_cx = - w*s/2 + i*s + rv*dp ; curr_cy = - h*s/2 + j*s + rv*dp
  23. # transforms.center_at(box, [curr_cx, curr_cy])
  24. #
  25. # # rotate the box of rv degrees around its center
  26. # transforms.rotate(box, rv, pivot=(curr_cx, curr_cy))
  27. # draw the damn box
  28. # plotter.write(box)
  29. #
  30. #ctx.rotate(math.pi * 1 / 4)
  31. ctx.translate(rs*dp*i, s)
  32. ctx.save()
  33. ctx.rotate(rv)
  34. ctx.rectangle(0,0, s, s)
  35. ctx.restore()
  36. ctx.stroke()
  37. ctx.restore()
  38. #float RGB touple
  39. FG_RGB_COLOR=(0,0,0)
  40. #A4 in 300 DPI
  41. width, height = 3508,2480
  42. offsetX, offsetY = 100,500
  43. w = 22 # width (how many squares - es. 22)
  44. h = 12 # height (how many squares - es. 12)
  45. s = 100 # square size (es. 15)
  46. rs = 0.01 # random step (rotation increment in degrees)
  47. dp = 2.25 # dampen (soften random effect for position)
  48. rsum = 0 # dummy initial value for rsum
  49. surface = cairo.PDFSurface ("/tmp/circle.pdf",width,height)
  50. ctx = cairo.Context (surface)
  51. ctx.set_source_rgb(FG_RGB_COLOR[0],FG_RGB_COLOR[1],FG_RGB_COLOR[2])
  52. ctx.set_line_width(1)
  53. ctx.translate(offsetX, offsetY)
  54. plotSquares(ctx)
  55. ctx.show_page()