Getting Better at Repeating

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

speed 20
pen green
rt 10
fd 200
pen yellow, 10

Now let us figure out how to draw ONE petal of our flower. Insert this one line of code

fd 50

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

fd 50
bk 50
rt 360 / 9
fd 50
bk 50

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]

for petal in [1..9]
  move forward 50
  move backwards 50
  make a rt turn

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?

Now that you know how to draw a flower using angles and repitition, it is time to be creative. You can decide to stick with flowers OR lose the stems and draw stars or fireworks.

Your Program output should have at least the following:

Last updated