home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l076 / 1.ddi / HILBERT.TRU < prev    next >
Encoding:
Text File  |  1988-08-27  |  1018 b   |  46 lines

  1. ! Space filling curve, by David Hilbert
  2. !
  3. SET COLOR MIX(0) .3,.3,.3
  4.  
  5. SET MODE "graphics"
  6. ASK PIXELS px,py
  7. SET WINDOW 0,px-1,0,py-1             ! make pixels work nicely
  8. LET xc = 2^(Int(Log2(px)))
  9. LET yc = 2^(Int(Log2(py)))
  10. LET step  = Min(xc,yc)/2
  11. LET xbase = (px/2)-step
  12. LET ybase = (py/2)-step              ! center the picture
  13.  
  14. DO while step > 2
  15.    LET x = xbase + step/2
  16.    LET y = ybase + step/2
  17.    LET level = level + 1
  18.    IF end data then RESTORE
  19.    READ color$
  20.    SET COLOR color$
  21.    CALL hilbert (0,step,step,0,level)
  22.    PLOT x,y
  23.    LET step = step / 2
  24. LOOP
  25.  
  26. DATA magenta,white,cyan
  27.  
  28. SUB draw (xs, ys)
  29.     PLOT x,y;
  30.     LET x = x + xs
  31.     LET y = y + ys
  32. END SUB
  33.  
  34. SUB hilbert (xs, ys, x2, y2, lev)
  35.     IF lev = 0 then EXIT SUB
  36.     CALL hilbert (x2, y2, xs, ys, lev-1)
  37.     CALL draw (xs, ys)
  38.     CALL hilbert (xs,ys,x2,y2,lev-1)
  39.     CALL draw (x2,y2)
  40.     CALL hilbert (xs,ys,x2,y2,lev-1)
  41.     CALL draw (-xs,-ys)
  42.     CALL hilbert (-x2,-y2,-xs,-ys,lev-1)
  43. END SUB
  44.  
  45. END
  46.