[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> fractals



I have two procedures in my MSWLOGO logolib, 'np' (note position) and 
'rp' (restore position) which may be of interest.
'np' stores, in a stack, a turtle's coordinates, heading and the pen state.
They MUST be used together and can be nested to any level: np...np...rp..rp.
The idea came from  their use in the FRACTINT L-SYSTEM (equivalent symbols '[' and ']') 
for fractal design.
They do not significantly slow drawing but do use more memory.
Equivalent procedures can be written for 3d work and I also find a use for
procedures using a queue rather than a stack.

-----------------
Store under file name np (no extension)
----
make "coord.stack []
make "penf 0

to np
localmake "coord.posn (list  xcor ycor heading)
ifelse pendownp [make "coord.posn fput 1 :coord.posn]~
                [make "coord.posn fput 0 :coord.posn]
push "coord.stack :coord.posn
end

bury [[np] [coord.stack penf] []]


----------------------------------
Store under file name rp 
--------

to rp
pu
localmake "coord.posn pop "coord.stack
make "penf first :coord.posn
make "coord.posn butfirst :coord.posn
setpos butlast :coord.posn
setheading last :coord.posn
if :penf=1 [pd]
end

bury "rp

-----------------------------

I illustrate their use in a Penrose tiling
------
to aaa
; try penrose 120 3
; 'large' and 'small' are the penrose rhombs
; 'pent' is the initial design
; but can be any design involving the rhombs (large, small).
; Use  'large :size :level' and then 'small :size :level' 
; with :level=1 then 2
; to see the recursion links.
end

to penrose :size :level
cs 
ht  pu 
localmake "ang 36
localmake "tau (1+sqrt 5)/2
bk :size*:tau
rt 2*:ang
;small :size :level
;large :size :level
pent :size :level
end

to pent :l :n
if :n=0 [pu stop]
;; draw central pattern
repeat 5 [lt :ang large :l :n rt :ang
          fd :l lt :ang fd :l lt :ang]
end

to large :l :n
if :n=0 [pu stop]
if :n=1 [pd]
fd :l lt 2*:ang
 np
   lt :ang small :l/:tau :n-1
 rp
fd :l lt 3*:ang
 np
   lt :ang large :l/:tau :n-1 
   rt 2*:ang large :l/:tau :n-1
 rp
 fd :l
 np
   small :l/:tau :n-1 rt :ang  bk :l/:tau
   lt :ang large :l/:tau :n-1
 rp
lt 2*:ang
fd :l lt 3*:ang
pu
end

to small :l :n
if :n=0 [pu stop]
if :n=1 [pd]
 np
   rt :ang large :l/:tau :n-1
   np 
     lt 3*:ang fd :l/:tau rt 180 
     small :l/:tau :n-1 
     rt 4*:ang small :l/:tau :n-1
   rp
  lt 4*:ang large :l/:tau :n-1
 rp
fd :l lt 4*:ang fd :l lt :ang 
fd :l lt 4*:ang fd :l lt :ang
pu
end


---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home