Ring Toss
#creativecoding #dailyart #artcoding
#codeart #stemeducation #cs #CodeNewbies
Inspired by
@art_ogi (thank you!)
x.com/art_ogi/status/1854056…
TO ringtoss
reset : hideturtle : penup
sethatchlimit 121
;maximum number of hatchlings
randombackgroundcolor
setbackgroundshade 8
;shade range -15 (light) to 15 (dark)
repeat 11 [
;position turtle in Y axis (vertical)
sety 120 - 20 * repcount
;repcount = REPeat loop COUNTer
repeat 11 [
;position turtle in X axis (horizontal)
setx -120 20 * repcount
hatch [ ;create new hatchling:
setmodel [ ;create hatchling model:
setfillcolor repcount
;fill color used by shapes (range 0 - 15)
setfillshade -14 2 * repabove 1
;repabove X = REPeat counter ABOVE 1 (parent)
twosided ;light both sides of shape
ring 2, repcount / 1.5, 8
;ring width, inner-radius, sides
]
penup : wrap : showturtle
setbounds [-110 -110 110 110]
;set bounds used by wrap (square)
sync ;wait for other hatchlings to settle
forever [
make "d random [10]
;pick number from 1 to 10 and put in in :d container
setheading 90 * random 4
;set heading (direction) to 0, 90, 180 or 270 degrees
setanchor extrapolate position, forwarddir, 20
;extrapolate anchor point 20 turtle-units in front
;of hatchling (next grid position in front of it)
repeat 15 [
;based on contents of :d, orbit around anchor
;(or do nothing if :d > 4):
switch "d
case 1 [orbitright 6]
case 2 [orbitleft 6]
case 3 [orbitup 12]
case 4 [orbitdown 12]
sync ;wait for other hatchlings / parent
;turtle to sync
] ;do the above 14 more times
] ;do the above forever
] ;end of hatch
;parent turtle code resumes:
] ;do the above 10 more times
] ;do the above 10 more times
wait 180 ;wait 3 seconds for hatchlings to settle
forever [sync : wait 5]
;forever sync and wait 5/60ths of a second
END