Getting Better at Repeating
Last updated
Last updated
Consider this drawing in pencil code. To program this flower we need to produce 9 "petals" that are the same color, width and general shape, but are pointing outward at different angles from the center. And this time the differences are not random!
Open a new penicl code (be sure to sign in and save) and use this code to create the stem. The last line of code sets the pen color to yellow, but because there is no movement AFTER this, nothing is acually yellow
Now let us figure out how to draw ONE petal of our flower. Insert this one line of code
Now - using the turtles ability to move backwards in the same direction it moved forwards, let us get this turtle back to the "center" of our flower. Hint
bk 50
Now - he needs to TURN and get ready to draw the next flower. Each petal of the flower is an equal distance from all the other petals. This means that each petal is drawn after we have turned the turtle, the same degree, for each one.
We are turning in a circle - (which is 360 degrees) and we have 9 petals. So after we draw each petal, we want the turtle to make a right turn that is 360 divided by 9 - so rt 360 / 9.
In programing the division sybmol is the forward slash on the bottom row of your keyoard
Here is the code to draw TWO petals
So you could just keep typing that over and over again - OR we can use the ability to REPEAT lines of code and make it easier
for petal in [1..9]
Now change your flower to have 12 petals - you will need to change how many times you repeat from 9 to 12 AND change the number of degrees we turn from 360 / 9 to 360 divided by 12. Can you add a center to your flower? Can you add a second, shorter set of petals in a different color?
Your Program output should have at least the following:
At least one other "thing"
leaves on the stems of a flower?
a vine?
a shooting star?