Advertisement
Guest User

Untitled

a guest
Dec 24th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %!
  2. % Sierpinski gasket
  3. % By John Fouhy.
  4. /maxdepth 10 def
  5. /length 500 def
  6. /xoff 60 def
  7. /yoff 300 def
  8. /root3 1.7320508 def
  9.  
  10. % draw a (roughly) equilateral triangle
  11. /triangle {
  12. newpath x y moveto a 0 rlineto 120 rotate a 0 rlineto 240 rotate closepath
  13. %%%depth 20 div 0 0 setrgbcolor
  14. stroke } def
  15.  
  16. % usage: a x y depth rec
  17. % where a is the side length, (x,y) are the coords of the lower left corner, and depth is the recursion depth
  18. /rec {
  19. /depth exch def
  20. /y exch def /x exch def /a exch def
  21. triangle
  22. depth maxdepth lt
  23. {
  24. /newa a 2 div def
  25. /newdepth depth 1 add def
  26. newa x y newdepth
  27. newa x a 4 div add y root3 a mul 4 div add newdepth
  28. newa x newa add y newdepth rec rec rec
  29. }
  30. if
  31. } def
  32.  
  33. 0 setlinewidth
  34. length xoff yoff 1 rec
  35.  
  36. showpage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement