Click to make things happen! ๐
Your drawings can do something when you click them. Write when, the shape's name and is clicked, and put what should happen inside { }:
Canvas paper having width 400, length 250
draw circle balloon at 200, 125 having radius 40, fill "tomato"
when balloon is clicked {
grow balloon by 1.5 in 0.5 seconds
shrink balloon by 1.5 in 0.5 seconds
}
Click the balloon. Click it again! It happens every time.
Remembering things ๐ง
A variable is a name that holds a value, like a number. Give it a value with =, and change it later. Here pops counts the clicks:
Canvas paper having width 400, length 250
draw circle balloon at 200, 125 having radius 30, fill "tomato"
pops = 0
when balloon is clicked {
pops = pops + 1
grow balloon by 1.2 in 0.3 seconds
}
Making choices ๐
if checks something, and does its lines only when it's true. otherwise says what to do when it isn't:
Canvas paper having width 400, length 250
draw circle lamp at 200, 125 having radius 40, fill "gray"
lit = false
when lamp is clicked {
lit = not lit
if lit {
lamp.fill = "gold"
}
otherwise {
lamp.fill = "gray"
}
}
Click the lamp to switch it on, and again to switch it off. ๐ก
Make a game ๐ฆซ
Put it all together, and you can make a game. Moles take turns popping up. Catch one by clicking it: it smiles, and you get a star. Catch five to win!
Canvas garden having width 400, length 300, fill "lightgreen"
shape mole having mood "hiding" {
circle body having radius 20, fill "sienna"
circle eye1 at -7, -5 having radius 3, fill "black"
circle eye2 at 7, -5 having radius 3, fill "black"
when mood is "hiding" { }
when mood is "caught" {
arc smile from 8, 6 to -8, 6 having radius 10
}
}
caught = 0
draw mole m1 at 100, 150
draw mole m2 at 200, 150
draw mole m3 at 300, 150
draw text message at 200, 40 having content "Catch the moles!"
hide m2
hide m3
forever {
hide m1
show m2
wait 1 second
hide m2
show m3
wait 1 second
hide m3
show m1
wait 1 second
}
when m1 is clicked {
caught = caught + 1
m1.mood = "caught"
draw circle star at 20 * caught, 280 having radius 6, fill "gold"
if caught is at least 5 {
message.content = "You win!"
}
}
Only the first mole can be caught so far. Can you make the other two catchable? ๐
Learn more in Click to Make Things Happen and Remembering Things. Have fun! โจ