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:
- Lift the turtle
- Set the pen size to 20 pixels
- Move the turtle to the position (-90, 10)
- Place the pen down
- Draw a circle of radius 80 pixels
- Set the heading of the turtle to 90 degrees
- Move forward by 50 pixels
- Change the heading of the turtle to 0 degrees
- Change the pen size to 1 pixel
- Draw a filled circle of radius 30 pixels
- Lift the pen
- Move the turtle to the position (90, 10)
- Set the pen size to 20 pixels
- Repeat steps 4 to 10
- Lift the pen
- Move the turtle to the position (90, -170)
- Set the pen size to 20 pixels
- Repeat steps 4 to 10
- Lift the pen
- Move the turtle to the position (-90, -170)
- Set the pen size to 20 pixels
- 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