45 lines
967 B
Plaintext
45 lines
967 B
Plaintext
|
& Lesson 8: A random lesson.
|
||
|
|
||
|
& So far, everything we've done is deterministic.
|
||
|
& Let's let the computer make some decisions.
|
||
|
|
||
|
& We're going to introduce a few things here:
|
||
|
& * colors
|
||
|
& * random
|
||
|
& * dicts
|
||
|
|
||
|
& our friend box!
|
||
|
fn box! (size) -> repeat 4 { fd! (size); rt! (0.25) }
|
||
|
|
||
|
doc! (pencolor!)
|
||
|
print! ("These are Ludus's built-in colors: ", colors)
|
||
|
|
||
|
pencolor! (colors :maroon)
|
||
|
& ^^^^^^ This is a dict.
|
||
|
& ^^^^^^^ This is a keyword.
|
||
|
& We use <dict> <keyword> to get values out of dicts.
|
||
|
& Dict is short for "dictionary."
|
||
|
& pencolor! is also pc!
|
||
|
|
||
|
& Drawing some colourful boxes:
|
||
|
box! (100)
|
||
|
rt! (0.25)
|
||
|
pc! (colors :purple)
|
||
|
box! (100)
|
||
|
rt! (0.25)
|
||
|
pc! (colors :olive)
|
||
|
box! (100)
|
||
|
rt! (0.25)
|
||
|
pc! (colors :teal)
|
||
|
box! (100)
|
||
|
|
||
|
& We can also get a random colour using a handy-dandy function: random
|
||
|
repeat 4 {
|
||
|
pc! (random (color))
|
||
|
box! (75)
|
||
|
rt! (0.25)
|
||
|
}
|
||
|
|
||
|
& And we can also set the background to a random colour:
|
||
|
background! (random (color))
|