home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilsm / mkdrawf / Examples / src / Koch < prev    next >
Encoding:
Text File  |  1994-12-16  |  1.1 KB  |  39 lines

  1. # Snowflake curve
  2.  
  3. Set $r3/2 Over Sqrt 3 2
  4.  
  5. # Side { %x0 .. %y0 .. %x1 .. %y1 .. %n .. }
  6. # this should be inserted into a Path
  7. # The assumption is that we’re
  8. # already "at" (x0,y0).
  9. Define Side {
  10.   IfLess %n 1
  11.     Line %x1 %y1
  12.   Else
  13.     Set %dx Over Minus %x1 %x0 3
  14.     Set %dy Over Minus %y1 %y0 3
  15.     Set %xa Plus %x0 %dx         Set %ya Plus %y0 %dy
  16.     Set %xb Minus %x1 %dx        Set %yb Minus %y1 %dy
  17.     Set %xh Over Plus %x0 %x1 2  Set %yh Over Plus %y0 %y1 2
  18.     Set %xt Plus %xh Times %dy $r3/2
  19.     Set %yt Minus %yh Times %dx $r3/2
  20.     Set %m Minus %n 1
  21.     Side { %x0 %x0 %y0 %y0  %x1 %xa %y1 %ya  %n %m }
  22.     Side { %x0 %xa %y0 %ya  %x1 %xt %y1 %yt  %n %m }
  23.     Side { %x0 %xt %y0 %yt  %x1 %xb %y1 %yb  %n %m }
  24.     Side { %x0 %xb %y0 %yb  %x1 %x1 %y1 %y1  %n %m }
  25.   EndIf
  26. }
  27.  
  28. Set $x0 100  Set $y0 100
  29. Set $x1 400  Set $y1 100
  30. Set $x2 250  Set $y2 Plus 100 Times 300 $r3/2
  31.  
  32. Path {
  33.   Move $x0 $y0
  34.   Side { %x0 $x0 %y0 $y0  %x1 $x1 %y1 $y1  %n 5 }
  35.   Side { %x0 $x1 %y0 $y1  %x1 $x2 %y1 $y2  %n 5 }
  36.   Side { %x0 $x2 %y0 $y2  %x1 $x0 %y1 $y0  %n 5 }
  37.   Close      # not really needed unless you want to fill it
  38. }
  39.