divergenza.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/python
  2. '''
  3. Schotter pdf reproduction
  4. It design SchotterR
  5. Author: Jan Bodnar
  6. Website: zetcode.com
  7. Last edited: April 2016
  8. '''
  9. import math,cairo,random
  10. def plotSquares(ctx):
  11. global rsum
  12. for i in xrange(0,w-1):
  13. rsum += i*rs # add to the random value
  14. ctx.save()
  15. ctx.translate(s*i, 0)
  16. for j in xrange(0,h-1):
  17. rv = random.uniform(-rsum, rsum)
  18. # here comes the box :-)
  19. #box = shapes.square(s)
  20. # box position
  21. #curr_cx = - w*s/2 + i*s + rv*dp ; curr_cy = - h*s/2 + j*s + rv*dp
  22. # transforms.center_at(box, [curr_cx, curr_cy])
  23. #
  24. # # rotate the box of rv degrees around its center
  25. # transforms.rotate(box, rv, pivot=(curr_cx, curr_cy))
  26. #
  27. # draw the damn box
  28. # plotter.write(box)
  29. #
  30. ctx.translate(rs*dp*i, s)
  31. #ctx.rotate(math.pi * 1 / 4)
  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 = 10 # 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.015 # 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()