Tuesday 12 December 2017

Me-Ware-Wo


Me-Ware-Wo means "I shall marry you". It is the symbol of commitment and perseverance.

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


The plan to draw this shape is shown below:
  1. Lift the turtle
  2. Set the pen size to 20 pixels
  3. Move the turtle to the position (-90, 10)
  4. Place the pen down
  5. Draw a circle of radius 80 pixels
  6. Set the heading of the turtle to 90 degrees
  7. Move forward by 50 pixels
  8. Change the heading of the turtle to 0 degrees
  9. Change the pen size to 1 pixel
  10. Draw a filled circle of radius 30 pixels
  11. Lift the pen
  12. Move the turtle to the position (90, 10)
  13. Set the pen size to 20 pixels
  14. Repeat steps 4 to 10
  15. Lift the pen
  16. Move the turtle to the position (90, -170)
  17. Set the pen size to 20 pixels
  18. Repeat steps 4 to 10
  19. Lift the pen
  20. Move the turtle to the position (-90, -170)
  21. Set the pen size to 20 pixels
  22. Repeat steps 4 to 10
Using Turtle Graphics

We will use the template.py file and rename it to mewarewo.py.

The code for steps 1 - 5 is given below:

turtle.penup()
turtle.pensize(20)
turtle.setposition(-90, 10)
turtle.pendown()
turtle.circle(80)

The generated image is shown below:


The code for steps 6 to 10 is given below:

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

The generated image is shown below:


Steps 14, 18 and 22 are repeated. This would be a good candidate for a function. So we create a function called draw_quarter_symbol and place it just after drawVertical function.

The code for the draw_quarter_symbol is shown below:

def draw_quarter_symbol():
    turtle.pendown()
    turtle.circle(80)
    turtle.setheading(90)
    turtle.forward(50)
    turtle.setheading(0)
    turtle.pensize(1)
    turtle.begin_fill()
    turtle.circle(30)
    turtle.end_fill()

This step we have carried out is called refactoring. The code that draws our symbol now becomes:

turtle.penup()
turtle.pensize(20)
turtle.setposition(-90, 10)
draw_quarter_symbol()

Run the above code and test it. The program runs as expected. To draw the rest of the symbol, you only need to copy and paste the code above 3 more times. Then you change the position you move your turtle to.

The code for our program now becomes:

turtle.penup()
turtle.pensize(20)
turtle.setposition(-90, 10)
draw_quarter_symbol()
turtle.penup()
turtle.pensize(20)
turtle.setposition(90, 10)
draw_quarter_symbol()
turtle.penup()
turtle.pensize(20)
turtle.setposition(90, -170)
draw_quarter_symbol()
turtle.penup()
turtle.pensize(20)
turtle.setposition(-90, -170)
draw_quarter_symbol()

The generated image is shown below:


Conclusion

At the end of this section, we have used the Python language to draw the Adinkra symbol Me Ware Wo.





No comments:

Post a Comment