Home
> MicroWorlds Logo Links & Examples >
MicroWorlds Code Pages > spirals3 Code
spirals3.txt 6 KB
; Purpose: To play with recursion
; Copyright © 2004 by Rupert Russell
; e-mail: rupert.russell1@gmail.com
; URL: http://www.rupert.id.au/microworlds/index.html
; Created: October 14, 2004
;
; Based code from Jeff Fox
; http://el.media.mit.edu/logo-foundation/logo/turtle.html
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; --------------------------------------------------------------
;
to startup
make "last_n 1
end
to go
setc "black
st
cg
curve 0 0
end
to ++
; add 1 to the current setting of the deg slider
; if the slider is already at its minimum do nothing
carefully [set "deg
"value deg + 1] [ ]
cg
go
end
to --
; subtract 1 from the current setting of the deg slider
; if the slider is already at its minimum do nothing
carefully [set "deg
"value deg - 1][ ]
cg
go
end
to favourites
; set the value of the deg slider to a random one of my favourites
make "n (random 29) + 1
; make sure not to repeat
the same shape twice in a row
if :n = :last_n [ifelse :n = 29 [make "n 1][make "n
:n + 1]]
if :n = 1 [set "deg
"value 30]
if :n = 2 [set "deg "value 33]
if :n = 3 [set "deg "value 36]
if :n = 4 [set "deg "value 40]
if :n = 5 [set "deg "value 44]
if :n = 6 [set "deg "value 45]
if :n = 7 [set "deg "value 47]
if :n = 8 [set "deg "value 51]
if :n = 9 [set "deg "value 55]
if :n = 10 [set "deg "value 59]
if :n = 11 [set "deg "value 71]
if :n = 12 [set "deg "value 75]
if :n = 13 [set "deg "value 77]
if :n = 14 [set "deg "value 83]
if :n = 15 [set "deg "value 89]
if :n = 16 [set "deg "value 94]
if :n = 17 [set "deg "value 97]
if :n = 18 [set "deg "value 98]
if :n = 19 [set "deg "value 99]
if :n = 20 [set "deg "value 103]
if :n = 21 [set "deg "value 117]
if :n = 22 [set "deg "value 126]
if :n = 23 [set "deg "value 127]
if :n = 24 [set "deg "value 136]
if :n = 25 [set "deg "value 144]
if :n = 26 [set "deg "value 149]
if :n = 27 [set "deg "value 162]
if :n = 28 [set "deg "value 166]
if :n = 29 [set "deg "value 171]
if :n = 30 [set "deg "value 179]
make "last_n :n
go
end
to curve :size deg
; this is the heart of the program
pd
ifelse (and ((first pos) < 200 ) ((last pos) < 200)
) [
fd :size
rt :deg
make "size :size + 0.3
curve :size deg ; recursive call
] [pu fd 2 setc "yellow fill ht stop] ; recursive
stop
end
APA citation:
Russell, R. (2016, July 04, 04:17 pm). spirals3 code.
Retrieved November 25, 2024, from http://www.rupert.id.au/microworlds/code/spirals3.php