pythagoras-tree.cs 993 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. %!CairoScript
  2. /pi4 0.785398163 def
  3. /sqrt2 1.414213562 def
  4. /R { % cr size *R* cr
  5. dup 1 lt { pop } {
  6. exch /current-point get % size cr x y
  7. 4 2 roll % x y size cr
  8. % draw a rectangle in relative co-ordinates
  9. 1 index 2 div neg dup exch M
  10. 1 index 0 L
  11. 0 2 index L
  12. 1 index neg 0 L
  13. h
  14. save
  15. 1 index dup 2 div neg exch translate
  16. 4 2 roll 3 copy % size cr x y cr x y
  17. m
  18. //pi4 rotate
  19. pop 4 2 roll % x y size cr
  20. 1 index //sqrt2 div
  21. R
  22. restore
  23. save
  24. 1 index dup 2 div exch translate
  25. 4 2 roll 3 copy % size cr x y cr x y
  26. m
  27. //pi4 neg rotate
  28. pop 4 2 roll % x y size cr
  29. 1 index //sqrt2 div
  30. R
  31. restore
  32. 4 1 roll pop pop pop
  33. } ifelse
  34. } bind def
  35. dict
  36. /width 1024 set
  37. /height 512 set
  38. surface context
  39. 1 1 1 set-source-rgb paint
  40. 0 512 translate 1 -1 scale
  41. 512 64 m 128. R 0 0 0 set-source-rgb fill
  42. /target get (out.png) write-to-png pop
  43. pop