Wednesday 1 November 2017

Fofoo


Fofoo means "yellow flowered plant". It is the symbol of jealousy and envy. When the fofo's petals drop, they turn into black spiky-like seeds. The Akan liken the nature of this plant to a jealous person.

We will use the 5 pixel grid to trace out this image. The image of this is shown below:


This symbol consists of lines and circles. The inner circle is of a radius of 3 squares. The outer rim is of a width of 3 squares. The line from the rim to the outer circle is of 4 squares in width. Its length starts from around the point where the distance from the centre is 5 squares. It stretches up to the point which is 13 squares from the centre of the circle. The line is closed up by a filled circle. Its radius is 3 squares.

The plan to draw this symbol is as follows:

  1. Lift the turtle
  2. Move it to the position that is 5 squares from the centre of the symbol
  3. Place the turtle down
  4. Set its pensize to 4 squares
  5. Draw a circle of a radius of 5 squares
  6. Lift up the pen
  7. Move it back to the centre of the symbol which is at the origin
  8. Set the pensize to 3 squares
  9. Set the heading of the turtle to 90 degrees
  10. Move to the position that is 5 squares from the centre of the circle in the direction of the heading of the turtle
  11. Place the turtle down
  12. Draw a line by moving forward by 8 squares
  13. Set the orientation of the turtle based on the formula (heading - 90)
  14. Set the pensize to 1
  15. Draw a filled circle from the point the line stops
  16. Go back to step 6 but each time you get to step 9, increase the heading by 40 until you get to 410

Using Turtle Graphics

We will use the template.py file and rename it to fofoo.py. The size of each square on our grid is 10 pixels. We shall use this as our multiplication factor.

From our first step, we need to lift up the pen. The code to do this is shown below:

turtle.penup()

To move the turtle to the point that is 5 squares from the center of the figure, we want to move it to the location that is (0, -5). Due to the multiplication factor of 10, this will now become (0, -50). The code to do this is given below:

turtle.setposition(0, -50)

To place the turtle down. The code to place the turtle down is shown below:

turtle.pendown()

To set the pensize to 4 squares, we will multiply this by 10 to get 40. The code to do this is shown below:

turtle.pensize(40)

We need to draw a circle of radius 5 squares. We use our multiplication factor and the value becomes 50. The code to do this is shown below:

turtle.circle(50)

The image that is generated is shown below:


Steps 6 to 12 are summarized by the steps shown below:

turtle.penup()
turtle.home()
turtle.pensize(30)
turtle.setheading(90)
turtle.forward(50)
turtle.pendown()
turtle.forward(80)

The generated image is shown below:


The code for steps 13, 14 and 15 are given below:

turtle.setheading(0)
turtle.pensize(1)
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()

The generated image is shown below:


Step 16 indicates that this is a loop. So we go back to step 6.

Now it would be easier to just use a simple while loop. So delete all the code for step 6 to step 15 and just enter this:
heading = 90

while (heading <= 410):
    turtle.penup()
    turtle.home()
    turtle.pensize(30)
    turtle.setheading(heading)
    turtle.forward(50)
    turtle.pendown()
    turtle.forward(80)
    turtle.setheading(heading - 90)
    turtle.pensize(1)
    turtle.begin_fill()
    turtle.circle(30)
    turtle.end_fill()
    heading = heading + 40

If you look carefully, you will see all the steps from steps 6 to 16 in this code. The only thing different about this code is the introduction of a variable called heading.

The generated image is shown below:


Conclusion

At the end of this section, we have successfully used Python turtle to draw the Fofoo symbol.

The use of a loop made the drawing of this symbol easier than if we had drawn each part individually.



No comments:

Post a Comment