ludus-scripts/walk.ld

35 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-06-11 21:37:04 +00:00
& Lesson 8: A random walk
& Besides colors, what can we get?
doc! (random) & Check the console to see the documentation
pc! (random (colors))
& * random distances
fd! (random (10, 50)) & walks forward a random amount between 10 and 50
& * random angles
rt! (random (-0.25, 0.25)) & turns a random amount between -0.25 and 0.25
& you can give turtle commands negative values!
& try giving `fd!` and `bk!` negative values.
& do it a random number of times:
let times = random (10, 30)
& `let` allows us to give names to values; so far we have only named functions
& let times = random (10, 30)
& ^^^ `let` is a special form; after
& ^^^^^ This is the name we're binding
& ^ `=` goes between the lhs and the rhs
& ^^^^^^^^^^^^^^^ The value of this expression is what's bound to the name
& (in this case, it's a random value between 10 and 30)
& here's our random walk:
repeat times { & repeat our random number of times
pc! (random (colors)) & a new random color
fd! (random (10, 50)) & a new random distance
rt! (random (-0.3, 0.3)) & a new random turn
}