The Call Form¶
Everything a shape can be told to do has two ways to write it. The English way is the one you have been using:
draw circle sun at 100, 100 having radius 20, fill "gold"
turn sun by 90 in 3 seconds
The other way is how most programming languages, like Python and JavaScript, say it: the shape, a dot, what to do, and the details in brackets with their names.
draw circle sun at 100, 100 having radius 20, fill "gold"
sun.turn(by=90, seconds=3)
Both do exactly the same thing. Use whichever you like, or mix them.
How to write a call¶
- The shape comes first, then a dot, then the action:
sun.turn(...). - Each detail has a name, then
=, then its value:by=90,seconds=3. - A place is two numbers in brackets:
by=(50, 0). - Details are separated by commas, in any order.
- The time is
seconds=, becauseinis a word Python keeps for something else.
Every action¶
| English | Call form |
|---|---|
move sun by 50, 0 in 2 seconds |
sun.move(by=(50, 0), seconds=2) |
move sun to 10, 10 |
sun.move(to=(10, 10)) |
turn sun by 90 in 3 seconds |
sun.turn(by=90, seconds=3) |
turn door by 90 around 0, 0 |
door.turn(by=90, around=(0, 0)) |
grow sun to 2 in 1 second |
sun.grow(to=2, seconds=1) |
shrink sun by 0.5 |
sun.shrink(by=0.5) |
show sun in 1 second |
sun.show(seconds=1) |
hide sun |
sun.hide() |
beat sun 3 times by 1.5 in 2 seconds |
sun.beat(times=3, by=1.5, seconds=2) |
beat lamp.glow |
lamp.glow.beat() |
wait 1 second |
wait(seconds=1) |
stop spin |
spin.stop() |
move, turn, grow and shrink need by or to, one of them. wait needs seconds. The rest need nothing, so the brackets can be empty.
Your own animations¶
An animation you made can be played as a call too. Its settings are written with their names, and each has its value:
draw circle ball at 150, 150 having radius 20, fill "orange"
animation hop(height=60, time=1) {
move ball by 0, -height in time / 2 seconds
move ball by 0, height in time / 2 seconds
}
hop()
wait(seconds=2)
hop(height=100, time=2)
| English | Call form |
|---|---|
animation hop having height 60, time 1 { } |
animation hop(height=60, time=1) { } |
play hop |
hop() |
play hop having height 100 |
hop(height=100) |
if hop is playing { } |
if hop.is_playing() { } |
stop hop |
hop.stop() |
- Each setting needs its value in the brackets, and each value in a call needs its setting's name:
hop(100)is a mistake,hop(height=100)works. hop.is_playing()is the one call that gives something back: it is true while the animation is running, so it goes in anif.play hop(height=100)is a mistake. Write one or the other:play hop having height 100, orhop(height=100).- A recipe's instances take the same calls for the animations inside the recipe:
kim.blink(),kim.blink.stop(). See Telling an instance what to do.
Where a call can go¶
Anywhere the English can: on its own line, inside repeat, forever, together and when, and on a part (face.eye.turn(by=90)). On a bunch it happens to every shape in it, just as the English does:
draw circle a at 40, 60 having radius 10, fill "tomato"
draw circle b at 100, 60 having radius 10, fill "gold"
bunch row = a, b
row.move(by=(0, 50), seconds=2)
row.hide(seconds=1)
The editor helps¶
Type the shape's name and a dot, and the editor lists what it can do and what it has: turn, move, grow and the rest, and its properties like radius. Pick an action and it writes a call that works, with the numbers ready to change. Inside the brackets it lists the names that action takes, like by, seconds and around, leaving out the ones you have written. After the name of one of your animations and a dot, it offers stop and is_playing.
When something is wrong¶
A call is checked the same way. Each detail needs its name, and only the names an action takes are allowed:
draw circle sun at 100, 100 having radius 20, fill "gold"
sun.turn(90)
The message says what turn takes, and shows a call that works: sun.turn(by=90, seconds=3).