home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #12 / Amiga Plus CD - 2002 - No. 12.iso / AmigaOS / Vollversion / MetaView / ARexx-Examples / KochKurve.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  2002-11-17  |  1.2 KB  |  52 lines

  1. /* test */
  2. /*TRACE I*/
  3.  
  4. address MetaView.0
  5.  
  6. K=1.732050807568877293 /* sqrt(3) */
  7. LIMIT=100*100              /* Don't split lines shorter than 2 pixels */
  8.  
  9. newpic 100 100 0 "KochKurve"
  10.  
  11. call Koch(5000, 20000, 30000, 20000)
  12. redrawpic
  13. return 0
  14.  
  15. Koch: PROCEDURE
  16. ARG x0,y0,x1,y1
  17.  
  18.   K=0.5 /*1.732050807568877293  sqrt(3) */
  19.   LIMIT=200*200              /* Don't split lines shorter than 2 pixels */
  20.  
  21.   dx = x1 - x0
  22.   dy = y1 - y0
  23.   l = dx*dx + dy*dy;
  24.   if l<limit then
  25.     do
  26.       /* segment too small... just draw it */
  27.       /* say "Line" x0 y0 x1 y1 */
  28.       AMF_DRAWLINE trunc(x0) trunc(y0) trunc(x1) trunc(y1)
  29.     end
  30.   else
  31.     do
  32.       /* Segment big enough... go subdividing */
  33.       xa = x0 + dx/3
  34.       ya = y0 + dy/3
  35.       xb = x1 - dx/3
  36.       yb = y1 - dy/3
  37.       xc = (x0 + x1 + dy*K)/2
  38.       yc = (y0 + y1 - dx*K)/2
  39.  
  40.       call Koch(x0, y0, xa, ya)
  41.       call Koch(xa, ya, xc, yc)
  42.       call Koch(xc, yc, xb, yb)
  43.       call Koch(xb, yb, x1, y1)
  44. /*
  45.       AMF_DRAWLINE trunc(x0) trunc(y0) trunc(xa) trunc(ya)
  46.       AMF_DRAWLINE trunc(xa) trunc(ya) trunc(xc) trunc(yc)
  47.       AMF_DRAWLINE trunc(xc) trunc(yc) trunc(xb) trunc(yb)
  48.       AMF_DRAWLINE trunc(xb) trunc(yb) trunc(x1) trunc(y1)
  49. */
  50.     end
  51. return 0
  52.