Make Your Own Block
The turtle knows square and triangle. It does not know petal. So teach it. Write to petal, then the drawing, then end. From that moment on, the word petal is a command, exactly like forward.
π‘ The idea
You can teach the turtle a brand new command and give it any name you like.
- to petal starts your new block, and end finishes it.
- Nothing is drawn while you are teaching. It draws when you call the name.
- After that, writing petal once draws the whole thing.
- A good block finishes where it started, so you can use it again and again.
- Give your block a name that says what it draws.
π Words to know
- block
- a command you make and name yourself
- to
- the word that starts a new block
- call
- use a block by writing its name
π Watch this
Six petals around one point, all from a single block that you named yourself.
to petal repeat 2 [ forward 80 right 60 forward 80 right 120 ] end colour pink repeat 6 [ petal right 60 ]
βοΈ Your turn
- Run it and find the word petal being used.
- Delete the last line and run it again. Nothing is drawn, because nothing called petal.
- Change repeat 6 and right 60 to repeat 12 and right 30.
- Change the 80s inside petal to 50 and watch every petal shrink.
- Rename petal to leaf, in both places.
π― Challenge: Make a block called leaf and use it four times to draw a four-leaf pattern.
Show me one answer
to leaf repeat 2 [ forward 60 right 45 forward 60 right 135 ] end colour green repeat 4 [ leaf right 90 ]
Your program