kusakari retweeted
Fence #creativecoding #stemeducation
#codenewbies #codeart #dailyart #dailycoding
Inspired by a piece by @kusakarism (Thank you!)
xitter.cf/kusakarism/status/1854…
TO fence
reset : hideturtle
;position camera:
cam:run [rollright 33 : orbitdown 60] ;degrees
;define colors:
setbackgroundcolor lightblue
setpencolor lightgrey
;define pen:
setpenstyle "mark
setpendepth 20 ;turtle-units
setpenopacity 70 ;70% opacity
make "f array [80 0] ;initialize array (list)
;of 80 zeros in container :f
forever [
;turn:
right loopcount / 2
;ground:
setfillcolor lightgreen : spot 400
setfillcolor yellow
;position:
penup : back 40 : slideleft 40
raise 20 : pendown
;draw fence:
repeat 80 [ ;do 80 times:
forward 5 ;move forward 5 turtle-units
slideleft item repcount :f
;slide to the left the number of turtle-units
;listed at the index of the current repeat
;loop counter (repcount) in container :f
;if stored value is negative, this has
;the effect of sliding to the right
if zerop remainder repcount 5 [icosphere 2]
;every 5 loops, draw an icosphere
if zerop remainder repcount 20 [right 90]
;every 20 loops turn right 90 degrees
]
;show frame to user and then clear space:
render : norender : clearscreen
;move fence by modifying list items:
make "s 20 * random 4
;select side of fence to modify
repeat 2 [ ;change two values on selected side:
make "p random [18] ;select panel of side
;and place that value in container :p
(setitem ;change value of container list item:
:s + :p ;index of item to set
"f ;container in which item resides
;value to set:
(item ;retrieve existing item value:
:s + :p ;item index
:f ;container contents (list)
)
+ ;add to that value the following:
;iff is a functional version of if.
;it takes a boolean, a value to return
;if the boolean is true, and a value
;to return if the boolean is false:
(iff oddp repcount
;is repeat loop odd?
-5 ;yes (subtract 5)
5 ;no (add 5)
;this has the effect of subtracting
;from the first panel item and
;adding to the second panel item
;making sure the turtle gets back to
;the same starting position
) ;end of iff
) ;end of setitem
] ;end of repeat 2
] ;end of forever
END















