The message below is being cross-posted from the LogoForum. Please
reply here at comp.lang.logo and it will be crossposted back to the
LogoForum. The original author of this message is
"robbiejames_inc" <robbiejames@[EMAIL PROTECTED]
>.
Hi.
I took a look at the output for the program, (below), that I posted a
few weeks ago on palindromic numbers, and saw a mirror of nature.
I may have just been crazy, so to prove it to myself I modified
the "Reversal" program to get a forest.
"Forest" uses the same baseline as "Reversal" with a bit of
randomness thrown in here and there to give the output a natural look
(I lifted the recursive tree program from the net and changed it a
bit).
I was going for the appearance of a typical dry sclerophyll forest in
Australia (becoming more like a rainforest the bigger the numbers).
It has a eucalypt canopy with a couple of smaller understorey species
(still much less complex than the real thing).
To run the program type "forest" (into the command line) followed by
the first positive integer "x" in the range from "x" to "x + 300"
Or type "land" (into the command line) followed by
the first positive integer "x" in the range from "x" to "x + 300" and
the number of times you want to run "forest" in sequance.
Or. To do the next patch of forest it is just two clicks. This
program also sends a bitmap to the resident folder (same as the
other).
This is the code:
Forrest
to forest :x
print "########################################################
setlabelfont [[Arial] -12 0 0 400 0 0 0 0 3 2 1 34]
cs pu setpos [-490 -480] rt 90 pd label (list :x "to :x+300)
pu ht home window setactivearea [-500 -500 500 500]
make "outray (array 301)
make "n 1 make "k :x
repeat 301 [checkloop :x 0 make "x :x+1 make "n :n+1]
make "outlist arraytolist :outray
print "########################################################
show :num
make "j 0 pu make "itt 0 setpos [-299 -495] pd
repeat 301 [xaxis make "j :j+1]
print (list "land :k+300 "1)
gifsave (list "f2 :k ".gif)
end
to land :x :m
make "num 1
repeat :m [forest :x make "x :x + 300 make "num :num+1]
end
to checkloop :x :i
if :i > 99 [setitem :n :outray 100 print (list (:n+(:k-
1)) "... :i "... :x) stop]
if (:x = (reverse :x)) [setitem :n :outray :i print (list (:n+(:k-
1)) "... :i "... :x) stop]
checkloop (lsum :x (reverse :x)) :i+1
end
to lsum :n1 :n2 [:rest 0] [:resp "||] [:parcial :rest + (last :n1) +
last :n2]
if (and (not emptyp :resp) (:rest = 0) (:n1 = 0) (:n2 = 0))
[output :resp]
output (lsum ifelse 1 < count :n1 [butlast :n1] [0]
ifelse 1 < count :n2 [butlast :n2] [0]
(count :parcial) - 1
word (last :parcial) :resp)
end
to leaf
make "mark pos
make "hd heading
make "f (first :outlist)
if :f > 30 [make "q 10 make "w 2 make "f 0]
if :f > 20 [make "q 5 make "w 2 make "f 0]
if :f > 5 [make "q 5 make "w 4 make "f 0]
lt :q*:w fd 1
repeat :q*:w [rt :w fd 1]
pu setpos :mark pd fd 1
repeat :q*:w [lt :w fd 1]
pu setpos :mark seth :hd pd
end
to rtree :size
if (:size < 5) [if (first :outlist) > 10 [leaf] stop]
fd :size
lt :ang rtree :size*(((random 7)+7)/14)
rt :ang*2 rtree :size*(((random 7)+7)/14)
lt :ang bk :size
end
to xaxis
bk 2 fd 2
make "tr (random 3)+1
make "ang (random 7)+21
make "tilt (random 6)-3
rt :tilt fd (first :outlist)*:tr
rtree (first :outlist)
bk (first :outlist)*:tr lt :tilt
pu rt 90 fd 2 lt 90 pd
make "outlist butfirst :outlist
make "itt :itt+1
end
This is the initial program.
This program shows how numbers become palindromic
over successive iterations of checking if the number is a
palindrome, and if not, adding the number to its' reverse
and checking the result until a palindromic number is obtained
If the iterations of this process exceed 99 it stops the process and
records the iterations as 100 and outputs the result it stoped on
To run the program type "doit" (into the command line) followed by
the first positive integer "x" in the range from "x" to "x + 300"
Or type "runit" (into the command line) followed by
the first positive integer "x" in the range from "x" to "x + 300" and
the number of times you want to run "doit".
The output will be a print (in the commander output) of: each number
in the range along with the iterations it took to become palindromic
and the final palindromic number arrived at.
It will also draw a graphic output by the turtle (saved as a .gif in
the folder where "Reversal" resides)
For a nice output .gif I suggest choosing (as "x") a multiple of 100
This is the code:
Reversal
to doit :x
print "########################################################
cs pu ht home setactivearea [-300 -100 500 350]
setlabelfont [[Arial Narrow] -10 0 0 400 0 0 0 0 3 2 1 34]
make "outray (array 301)
make "n 1 make "k :x
repeat 301 [checkloop :x 0 make "x :x+1 make "n :n+1]
make "outlist arraytolist :outray
print "########################################################
show :num
yaxis
make "j 0 pu make "itt 0 setpos (list -200 -50) pd
repeat 301 [xaxis make "j :j+1]
print (list "runit :k+300 "1)
gifsave (list "doit :k ".gif)
end
to runit :x :m
make "num 1
repeat :m [doit :x make "x :x + 300 make "num :num+1]
end
to checkloop :x :i
if :i > 99 [setitem :n :outray 100 print (list (:n+(:k-
1)) "... :i "... :x) stop]
if (:x = (reverse :x)) [setitem :n :outray :i print (list (:n+(:k-
1)) "... :i "... :x) stop]
checkloop (lsum :x (reverse :x)) :i+1
end
to lsum :n1 :n2 [:rest 0] [:resp "||] [:parcial :rest + (last :n1) +
last :n2]
if (and (not emptyp :resp) (:rest = 0) (:n1 = 0) (:n2 = 0))
[output :resp]
output (lsum ifelse 1 < count :n1 [butlast :n1] [0]
ifelse 1 < count :n2 [butlast :n2] [0]
(count :parcial) - 1
word (last :parcial) :resp)
end
to jump
pd bk 15
pu fd 3 rt 90 bk 7 pd label (:j+:k) pu fd 7 lt 90 bk 3
fd 15 pu
end
to spike
pu fd ((first :outlist)*3)+1 rt 90 bk 7 lt 90
if (:itt > 2) [pd label (:j+:k)]
pu bk ((first :outlist)*3)+1 rt 90 fd 7 lt 90
make "itt 0
end
to xaxis
bk 1 fd 1
fd (first :outlist)*3 bk (first :outlist)*3
if (modulo :j+:k 10) = 0 [pd bk 5 fd 5 pu]
if (modulo :j+:k 100) = 0 [jump]
if (first :outlist) > 10 [spike make "itt 0]
pu rt 90 fd 2 lt 90 pd
make "outlist butfirst :outlist
make "itt :itt+1
end
to yaxis
make "f 5
pu setpos (list -220 -50)
pd rt 90 bk 3 fd 3
pu fd 2 lt 90 fd 6 rt 90 pd label 0 pu
lt 90 bk 6 rt 90 bk 2 lt 90
repeat 20 [pd fd 15 rt 90 bk 3 fd 3
pu fd 2 lt 90 fd 6 rt 90 pd label (list :f) pu
lt 90 bk 6 rt 90 bk 2 lt 90 make "f :f+5]
pd fd 10
setlabelfont [[Arial Narrow] -10 0 0 400 255 0 0 0 3 2 1 34]
label (list "--> "8) pu bk 10
setlabelfont [[Arial Narrow] -10 0 0 400 0 0 0 0 3 2 1 34]
bk 300 pu
setpos (list -237 85) label "iterations
setpos [75 -70] rt 90 label (list "positive "integers)
seth 0
end
Daniel wondered why I didn't use "lsum" in my original program, but I
wasn't going to use it until I understood it. I do now, so I have
used it in both programs and, yes, it is more efficient. Thanks.
One thing though. I am new to this and am using MSWlogo as a learning
tool / new toy. I just wanted to say thanks for the toy (to the
designers), this is what I made with it!
My question is: Was the output of the program not even just a little
bit interesting? . The code is im****tant but sometimes it is good to
be able to see the wood for the trees
Robbie.


|