Monday, 19 February 2018

Nyansapo


Nyansapo means "wisdom knot". It is the symbol of wisdom, ingenuity, intelligence and patience.

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


This symbol is easy to draw. The plan to draw this shape is shown below:

  1. Lift up the pen
  2. Move the turtle to the position (0, -35)
  3. Set the pen size to 10 pixels
  4. Draw a circle of radius 80 pixels
  5. Lift up the pen
  6. Move the turtle to the position (0, -125)
  7. Place the pen down
  8. Draw a circle of radius 80 pixels
  9. Lift up the pen
  10. Move the turtle to the position (-25, -185)
  11. Set the heading to 90 degrees
  12. Place the pen down
  13. Move forward by 150 pixels
  14. Repeat steps 9 to 13 but change the position of step 10 to (25, -185)
  15. Lift up the pen
  16. Move the turtle to the position (-25, 185)
  17. Set the heading to 270 degrees
  18. Place the pen down
  19. Move forward by 150
  20. Repeat steps 15 to 19 but change the position of step 16 to (25, 185)
  21. Lift up the pen
  22. Move the turtle back to its home position
  23. Change its colour to white
  24. Set its heading to 270 degrees
  25. Change its pen size to 40
  26. Place the pen down
  27. Move backward by 40 pixels
  28. Move forward by 80 pixels

Using Turtle Graphics

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

The code for the first four steps is given below:

turtle.penup()
turtle.setposition(0, -35)
turtle.pensize(10)
turtle.pendown()
turtle.circle(80)

The generated image is shown below:


The code for steps 5 to 8 is given below:

turtle.penup()
turtle.setposition(0, -125)
turtle.pendown()
turtle.circle(80)

The generated image is given below:


The code for steps, 9 to 13 is given below:

turtle.penup()
turtle.setposition(-25, -185)
turtle.setheading(90)
turtle.pendown()
turtle.forward(150)

The code for step 14 is given below:

turtle.penup()
turtle.setposition(25, -185)
turtle.setheading(90)
turtle.pendown()
turtle.forward(150)

The generated image is shown below:


The code for steps 15 to 19 is given below:

turtle.penup()
turtle.setposition(25, 185)
turtle.setheading(270)
turtle.pendown()
turtle.forward(150)

The code for step 20 is given below:

turtle.penup()
turtle.setposition(-25, 185)
turtle.setheading(270)
turtle.pendown()
turtle.forward(150)

The generated image is shown below:


The code for steps 21 to 28 is given below:

turtle.penup()
turtle.home()
turtle.color(“white”, “white”)
turtle.setheading(270)
turtle.pensize(40)
turtle.pendown()
turtle.backward(40)
turtle.forward(80)

The generated image is shown below:


Conclusion

We have succeeded in drawing the symbol Nyansapo. It wasn't so difficult to draw.

Friday, 16 February 2018

Nyame Nnwu Na Me Wu



Nyame Nnwu Na Me Wu means "God never dies, therefore I cannot die". It is the symbol of God's omnipresence and the perpetual existence of man's spirit. This signifies the immortality of man's soul, believed to be a part of God. Because the soul rests with God after death, it cannot die.

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


This function is a composite made up of circles and line. We need to know where the circles are in order to draw this shape.

The plan to draw this symbol is given below:

  1. Lift up the pen
  2. Change the pen size to 10 pixels
  3. Draw the upper left circle
  4. Draw the lower left circle
  5. Draw the upper right circle
  6. Draw the lower right circle
  7. Change the pen size to 30 pixels
  8. Draw a line from the upper left circle to the lower right circle
  9. Draw a line from the upper right circle to the lower left circle
  10. Change the pen size to 10 pixels
  11. Change its colour to white
  12. Draw a line from the upper left circle to the lower right circle
  13. Draw a line from the upper right circle to the lower left circle


Using Turtle Graphics

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

The code for the first two steps is given below:

turtle.penup()
turtle.pensize(10)

To draw the upper left circle, we have to know its position. The position of the upper left circle is at (-125, 70). The circle has a radius of 50 pixels.

The code to draw the circle is as follow:

turtle.penup()
turtle.setposition(-125, 75)
turtle.pendown()
turtle.circle(50)

The position of the lower left circle is at (-125, -180). The code to draw it is given below:

turtle.penup()
turtle.setposition(-125, -175)
turtle.pendown()
turtle.circle(50)

The position of the upper right circle is at (125, 70). The code to draw it is given below:

turtle.penup()
turtle.setposition(125, 75)
turtle.pendown()
turtle.circle(50)

The position of the lower right circle is at (125, -180). The code to draw it is given below:

turtle.penup()
turtle.setposition(125, -175)
turtle.pendown()
turtle.circle(50)

The generated image is shown below:


At step 7 we lift up the pen and increase the pen size to 30 pixels. The code to do this is shown below:

turtle.penup()
turtle.pensize(30)

The coordinate of the point for the joining line between the upper left circle and the lower right circle is (-90, 90) and (90, -90).

We will use the coordinateDistance function to find the distance between the two points since we already know the the orientation between them is a factor of 45 degrees. The code to do this is written below:

pointDistance = coordinateDistance(-90, 90, 90, -90)

Now that we know the distance between the 2 points, we move the pen back to the upper left circle and set its heading to -45 degrees. The code to do this is shown below:

turtle.setposition(-90, 90)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(pointDistance)

The generated image is shown below:


We lift up the pen and move it to the upper left quadrant. We set the orientation of the turtle to 225 degrees and we draw the line. The code to do this is shown below:

turtle.penup()
turtle.setposition(90, 90)
turtle.setheading(225)
turtle.pendown()
turtle.forward(pointDistance)

The generated image is shown below:


Now we are at step 10. The code to change the pen size to 10 pixels is given below:

turtle.penup()
turtle.pensize(10)

To change the colour of the pen to white, the code to do this is shown below:

turtle.color(“white”, “white”)

Now the pen will be moved back to the position we drew from in both cases. Then we will place the pen down, move backward by 10 pixels and move forward by 10 pixels. This will help to clean out the blot lines. The code to do this is shown below:

turtle.setposition(-90, 90)
turtle.setheading(-45)
turtle.pendown()
turtle.backward(10)
turtle.forward(pointDistance + 20)

We repeat this steps again but this time we move the turtle to the upper right circle. The code for this is shown below:

turtle.penup()
turtle.setposition(90, 90)
turtle.setheading(225)
turtle.pendown()
turtle.backward(10)
turtle.forward(pointDistance + 20)

The generated image is shown below:


Conclusion

We have finished drawing the basic shape. A technique to make it perfect would be to initially draw the circles as filled shapes.

This symbol is truly deep.

Wednesday, 14 February 2018

Ntesie Mate Masie


Ntesie Mate Masie means "What I hear, I keep". It is the symbol of symbol of wisdom, knowledge and prudence.

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


This symbol is simple to draw. We only need to know the position of the circles. We will use a function to prevent duplication.

The plan to draw this symbol is given below:
  1. Lift up the pen
  2. Move the position of the turtle to the position of the upper left quadrant
  3. Place the pen down
  4. Set the pen size to 20 pixels
  5. Draw the outer circle
  6. Set the pen size to 1 pixel
  7. Draw the inner circle
  8. Move the position of the turtle to the position of the lower left quadrant
  9. Repeat steps 3 to 7
  10. Move the position of the turtle to the position of the upper right quadrant
  11. Repeat steps 3 to 7
  12. Move the position of the turtle to the lower right quadrant
  13. Repeat steps 3 to 7
Using Turtle Graphics

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

The code for the first step is given below:

turtle.penup()

The position for the circle on the upper right quadrant is at (-90, 10). The code to move the turtle to this position is given below:

turtle.setposition(-90, 10)

The function to draw a portion of the symbol is given below:

def drawQuarterSymbol():
    turtle.pendown()
    turtle.pensize(20)
    turtle.circle(80)
turtle.setposition(turtle.xcor(), turtle.ycor() + 10)
    turtle.pensize(1)
    turtle.begin_fill()
    turtle.circle(40)
    turtle.end_fill()

The above function covers steps 3 to 7. We need to call the function. The code to call a function is given below:

drawQuarterSymbol()

The generated image is shown below:


From this point on, the rest is easy. All we need to do is to move the turtle to the point were we want to draw the quarter of the symbol.

The code for steps 8 and 9 is given below:

turtle.penup()
turtle.setposition(-90, -170)
drawQuarterSymbol()

The generated image is shown below:


To draw the quarter of the symbol, the turtle must be moved to the point that is (90, 10). The code to do this is shown below:

turtle.penup()
turtle.setposition(90, 10)
drawQuarterSymbol()

The generated image is shown below:


To draw the lower right symbol, we simply move the turtle to the position (90, -170) and draw the quarter of the symbol. The code to do this is shown below:

turtle.penup()
turtle.setposition(90, -170)
drawQuarterSymbol()

The generated image is shown below:


Conclusion

At the end, we have succeeded in drawing the Ntesie Mate Masie. Rather run the code 4 times, we could also have used a loop to draw the symbol.

Good programmers learn to watch out for this kind of things in their everyday work. However, this is a first draft so I will focus on drawing the symbols.

Monday, 12 February 2018

Nssa

Nssa means "a type of hand woven fabric". It is the symbol of symbol of excellence, genuineness, authenticity.

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


This symbol is simple to draw. It consists of lines.

The plan to draw this symbol is given below:

  1. Lift up the pen
  2. Set the pen size to 20 pixels
  3. Set the heading of the pen to 0 degrees
  4. Move the pen back by 70 pixels
  5. Place the pen down
  6. Move forward by 140 pixels
  7. Move the pen back to the home position
  8. Set the heading of the pen to 90 degrees
  9. Move the pen back by 60 pixels
  10. Move forward by 120 pixels
  11. Set the heading of the pen to 180 degrees
  12. Move forward by 60 pixels
  13. Set the heading to 90 degrees
  14. Move forward by 90 pixels
  15. Set the heading of the pen to 180 degrees
  16. Move forward by 120 pixels
  17. Set the heading of the pen to 270 degrees
  18. Move forward by 120 pixels
  19. Set the heading of the pen to 0 degrees
  20. Move forward by 100 pixels
  21. Set the heading of the pen to 270 degrees
  22. Move forward by 60 pixels
  23. Set the heading of the pen to 180 degrees
  24. Move forward by 100 pixels
  25. Set the heading of the pen to 270 degrees
  26. Move forward by 120 pixels
  27. Set the heading of the pen to 0 degrees
  28. Move forward by 120 pixels
  29. Set the heading of the pen to 90 degrees
  30. Move forward by 90 pixels
  31. Set the heading of the pen to 0 degrees
  32. Move forward by 120 pixels
  33. Set the heading of the pen to 270 degrees
  34. Move forward by 90 pixels
  35. Set the heading of the pen to 0 degrees
  36. Move forward by 120 pixels
  37. Set the heading of the pen to 90 degrees
  38. Move forward by 120 pixels
  39. Set the heading of the pen to 180 degrees
  40. Move forward by 100 pixels
  41. Set the heading of the pen to 90 degrees
  42. Move forward by 60 pixels
  43. Set the heading of the pen to 0 degrees
  44. Move forward by 100 pixels
  45. Set the heading of the pen to 90 degrees
  46. Move forward by 120 pixels
  47. Set the heading of the pen to 180 degrees
  48. Move forward by 120 pixels
  49. Set the heading of the pen to 270 degrees
  50. Move forward by 90 pixels
  51. Set the heading of the pen to 180 degrees
  52. Move forward by 60 pixels
Using Turtle Graphics

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

The code for steps 1 to 10 is given below:

turtle.penup()
turtle.pensize(20)
turtle.setheading(0)
turtle.backward(70)
turtle.pendown()
turtle.forward(140)
turtle.home()
turtle.setheading(90)
turtle.backward(60)
turtle.forward(120)

The image generated is given below:



The code for steps 11 to 22 draws the outline of the shape for the upper left quadrant and extends to the lower left quadrant. The code for the steps is:

turtle.setheading(180)
turtle.forward(60)
turtle.setheading(90)
turtle.forward(90)
turtle.setheading(180)
turtle.forward(120)
turtle.setheading(270)
turtle.forward(120)
turtle.setheading(0)
turtle.forward(100)
turtle.setheading(270)
turtle.forward(60)

The generated image is shown below:


The remaining steps are just a repetition of the steps we have executed so far. The code for steps 23 to 32 gives us the image shown below:


Steps 33 to 42. draw the 3rd square. The code for this steps is given below:

turtle.setheading(270)
turtle.forward(90)
turtle.setheading(0)
turtle.forward(120)
turtle.setheading(90)
turtle.forward(120)
turtle.setheading(180)
turtle.forward(100)
turtle.setheading(90)
turtle.forward(60)

The generated image is shown below:


The code to complete the symbol is given below:

turtle.setheading(0)
turtle.forward(100)
turtle.setheading(90)
turtle.forward(120)
turtle.setheading(180)
turtle.forward(120)
turtle.setheading(270)
turtle.forward(90)
turtle.setheading(180)
turtle.forward(60)

The final symbol is given below:


Conclusion

Nssa is one of the easier symbols to draw although the steps are involved. Its kind of fun to see the turtle go about drawing this shape.

Friday, 9 February 2018

Nkyinkyim


Nkyinkyim means "twisting". It is the symbol of that depicts the twists and turns of life.

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


This symbol is simple to draw. It consists of lines. What will make it tricky will be the way the lines change in width.

The plan to draw this symbol is given below:

  1. Lift up the turtle
  2. Move the turtle to the position (150, 170)
  3. Set the pensize to 40 pixels
  4. Set the heading of the turtle to 180 degrees
  5. Place the pen down
  6. Move forward by 300 pixels
  7. Move backward by 10 pixels
  8. Set the heading to 270 degrees
  9. Move forward by 10 pixels
  10. Change the pen size to 60 pixels
  11. Move the pen forward by 50 pixels
  12. Lift up the pen
  13. Move forward by 10 pixels
  14. Change the pen size to 40 pixels
  15. Set the heading to 0 degrees
  16. Place the pen down
  17. Move forward by 290 pixels
  18. Repeat steps 7 to 11
  19. Repeat steps 12 to 16 but change the heading to 180
  20. Repeat steps 7 to 11
  21. Repeat steps 12 to 16
  22. Repeat steps 7 to 11 however change the number of steps from 50 to 110
  23. Lift up the pen
  24. Move backward by 60 steps
  25. Repeat steps 12 to 16
  26. Repeat steps 7 to 11 however change the number of steps from 50 to 40
  27. Lift up the pen
  28. Change the pen size to 40 pixels
  29. Move the turtle to the position (-40, -110)
  30. Change the heading to 270 degrees
  31. Move forward by 60 pixels
  32. Lift up the pen
  33. Change the pen size to 40 pixels
  34. Move the turtle to the position (40, -110)
  35. Change the heading to 270 degrees
  36. Move forward by 60 pixels

Using Turtle Graphics

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

The code for steps 1 to 6 is given below:

turtle.penup()
turtle.setposition(150, 170)
turtle.pensize(40)
turtle.setheading(180)
turtle.pendown()
turtle.forward(300)

The code for steps 7 to 11 is given below:

turtle.backward(10)
turtle.setheading(270)
turtle.forward(10)
turtle.pensize(60)
turtle.forward(50)

The code for steps 12 to 16 is given below:

turtle.penup()
turtle.forward(10)
turtle.pensize(40)
turtle.setheading(0)
turtle.pendown()
turtle.forward(290)

Step 18 involves us repeating steps 7 to 11 so we copy and paste the code.

We do the same for steps 19, 20 and 21.

The image we have generated so far is shown below:


Executing steps 21 generates the image shown below:


The code for steps 23 and 24 is given below:

turtle.penup()
turtle.backward(60)

Then copy the code for steps 7 to 11 but remember to change the number of steps from 50 to 40.

The generated image is shown below:


The code for steps 27 to 31 is given below:

turtle.penup()
turtle.pensize(40)
turtle.setposition(-40, -110)
turtle.setheading(270)
turtle.pendown()
turtle.forward(60)

The code for steps 32 to 36 is given below:

turtle.penup()
turtle.pensize(40)
turtle.setposition(40, -110)
turtle.setheading(270)
turtle.pendown()
turtle.forward(60)

The generated image is shown below:


Conclusion

At the end of this section, we have succeeded in drawing the Nkyinkyim.

Wednesday, 7 February 2018

Nkyimu


Nkyimu mean "the crossed divisions made on adinkra cloth before stamping". It is the symbol of symbol of skillfulness, precision.

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


This symbol is simple. It consists of lines. Note that angles between the lines are based on 45 degrees. The plan to draw this symbol is shown below:

  1. Set the pen size to 40 pixels
  2. Draw the outer square
  3. Draw all the lines working from the upper left quadrant

Using Turtle Graphics

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

The code for the first step of the algorithm is shown below:

turtle.pensize(40)

To draw the outer square, we can use the drawSquare function. The size of our square is 340 pixels. The code for this is given below:

drawSquare(340)

The generated image is shown below:


Step 3 of our algorithm is to draw all the lines working from the upper left quadrant. The lines are 20 in total.

Thankfully, 2 of each lines repeat in the shape so just have to identify which lines repeat and use the lengths of the lines.
To draw a line, we need to get its coordinates. Then we find the length of the line. We know that the angle between the lines is a multiple of 45 degrees so knowing its coordinates help us to know the distance between the lines.

The first line extends from (-120, 150) to (150, -120). To get the distance between the two points, we use the coordinateDistance function and assign the value it returns to a variable called firstLineLength. The code to do this is shown below:

firstLineLength = coordinateDistance(-120, 150, 150, -120)

To draw the line, we need to lift up the pen and move it to the point (-120, 150). Then we set the heading of the turtle to -45 degrees. We must reduce the pensize to 5 pixels and then we draw the first line. The code to do this is shown below:

turtle.penup()
turtle.setposition(-120, 150)
turtle.setheading(-45)
turtle.pensize(5)
turtle.pendown()
turtle.forward(firstLineLength)

The generated image is shown below:


Lines 2 to 4 are drawn in pretty much the same way. Since these lines are unique, I shall go through them together and show the code at the end.

Line 2 extends from (-140, 150) to (150, -140). The code to draw the line is given below:

turtle.penup()
secondLineLength = coordinateDistance(-140, 150, 150, -140)
turtle.setposition(-140, 150)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(secondLineLength)

Line 3 starts at (-150, 140). Its length is the same as that of the second line so we don’t need to calculate the length of this line. Our code will now be as shown below:

turtle.penup()
turtle.setposition(-150, 140)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(secondLineLength)

Line 4 starts at (-150, 120). Its lenght is the same as that of the first line so we don’t need to calculate its length. Our code will now be as shown below:

turtle.penup()
turtle.setposition(-150, 120)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(firstLineLength)

The generated image is shown below:


The next 4 lines will follow a similar pattern to be drawn. However, I will state that there is the need to get the values of the distance between the lines because these lines are unique.

To draw the fifth line, we note where it starts and where it ends. Once we know its length, we can then proceed to draw it.
The fifth line goes from (-150, 0) to (0, 150). The code to draw the line is given below:

turtle.penup()
fifthLineLength = coordinateDistance(-150, 0, 0, 150)
turtle.setposition(-150, 0)
turtle.setheading(45)
turtle.pendown()
turtle.forward(fifthLineLength)

The sixth line goes from (-150, -20) to (20, 150). The code to draw the line is given below:

turtle.penup()
sixthLineLength = coordinateDistance(-150, -20, 20, 150)
turtle.setposition(-150, -20)
turtle.setheading(45)
turtle.pendown()
turtle.forward(sixthLineLength)

The seventh line goes from (-150, -40) to (40, 150). The code to draw the line is given below:

turtle.penup()
seventhLineLength = coordinateDistance(-150, -40, 40, 150)
turtle.setposition(-150, -40)
turtle.setheading(45)
turtle.pendown()
turtle.forward(seventhLineLength)

The eight line goes from (-150, -60) to (60, 150). The code to draw the line is given below:

turtle.penup()
eightLineLength = coordinateDistance(-150, -60, 60, 150)
turtle.setposition(-150, -60)
turtle.setheading(45)
turtle.pendown()
turtle.forward(eightLineLength)

The generated image is shown below:


Drawing lines 9 to 12 will involve the same steps.

Line nine extends from (-150, -20) to (-20, -150). The code to draw the line is shown below:

turtle.penup()
ninthLineLength = coordinateDistance(-150, -20, -20, -150)
turtle.setposition(-150, -20)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(ninthLineLength)

Line ten extends from (-150, -40) to (-40, -150). The code to draw the line is shown below:

turtle.penup()
tenthLineLength = coordinateDistance(-150, -40, -40, -150)
turtle.setposition(-150, -40)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(tenthLineLength)

Line eleven extends from (-150, -60) to (-60, -150). The code to draw the line is shown below:

turtle.penup()
eleventhLineLength = coordinateDistance(-150, -60, -60, -150)
turtle.setposition(-150, -60)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(eleventhLineLength)

Line twelve extends from (-150, -80) to (-80, -150). The code to draw the line is shown below:

turtle.penup()
twelvethLineLength = coordinateDistance(-150, -80, -80, -150)
turtle.setposition(-150, -80)
turtle.setheading(-45)
turtle.pendown()
turtle.forward(twelvethLineLength)

The generated image is shown below:


Drawing lines 13 to 16 involves pretty much the same approach. However, I would note that line 13 is not the same length as any other line.

Line thirteen runs from (-80, -150) to (150, 80). The code to draw the line is shown below:

turtle.penup()
thirteenLineLength = coordinateDistance(-80, -150, 150, 80)
turtle.setposition(-80, -150)
turtle.setheading(45)
turtle.pendown()
turtle.forward(thirteenLineLength)

Line fourteen starts at (-60, -150). It has the same length as line eight so we use it. The code to draw this line is shown below:

turtle.penup()
turtle.setposition(-60, -150)
turtle.setheading(45)
turtle.pendown()
turtle.forward(eightLineLength)

Line fifteen starts at (-40, -150). It has the same length as line seven so we use it. The code to draw this line is shown below:

turtle.penup()
turtle.setposition(-40, -150)
turtle.setheading(45)
turtle.pendown()
turtle.forward(seventhLineLength)

Line sixteen starts at (-20, -150). It has the same length as line six so we use the length of line six. The code to draw this line is shown below:

turtle.penup()
turtle.setposition(-20, -150)
turtle.setheading(45)
turtle.pendown()
turtle.forward(sixthLineLength)

The generated image is shown below:


Drawing lines 17 to 20 will involve using a heading of 135 degrees. These lines are unique so we need to calculate their lengths.

To draw line seventeen, we must establish where it starts from and where it ends in order to get its distance. The line starts at (150, 20) and ends at (20, 150).

turtle.penup()
seventeenthLineLength = coordinateDistance(150, 20, 20, 150)
turtle.setposition(150, 20)
turtle.setheading(135)
turtle.pendown()
turtle.forward(seventeenthLineLength)

Line eighteen starts at (150, 40) and ends at (40, 150). The code to draw the line is shown below:

turtle.penup()
eighteenthLineLength = coordinateDistance(150, 40, 40, 150)
turtle.setposition(150, 40)
turtle.setheading(135)
turtle.pendown()
turtle.forward(eighteenthLineLength)

Line nineteen starts at (150, 60) and ends at (60, 150). The code to draw the line is shown below:

turtle.penup()
nineteenLineLength = coordinateDistance(150, 60, 60, 150)
turtle.setposition(150, 60)
turtle.setheading(135)
turtle.pendown()
turtle.forward(nineteenLineLength)

Line twenty starts at (150, 80) and ends at (80, 150). The code to draw the line is shown below:

turtle.penup()
twentiethLineLength = coordinateDistance(150, 80, 80, 150)
turtle.setposition(150, 80)
turtle.setheading(135)
turtle.pendown()
turtle.forward(twentiethLineLength)

The generated image is shown below:


Conclusion

At the end of this program, we have drawn the Nkyimu shape.

Monday, 5 February 2018

Nea Ope Se Obedi Hene


Nea Ope Se Obedi Hene means “He who wants to be king”. It is the symbol of symbol of service and leadership.

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


The symbol is complex. To draw it, we will need to use some of the techniques that we used to draw the Fawohudie symbol.

The plan to draw the shape is given below:

  1. Lift the pen up
  2. Set the pen size to 10 pixels
  3. Draw the outer 4 bounds
  4. Draw the outer square
  5. Draw the inner circles
  6. Draw the inner V shape
  7. Draw the parallel center vertical line
Using Turtle Graphics


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

The code for steps 1 and 2 are given below:

turtle.penup()
turtle.pensize(10)

The 4 bounds are in the 4 quadrants. We shall draw the 4 bounds starting with the one in the upper left quadrant.

To draw it, we need to move the mouse to its position (-185, 60), set its heading to 90 degrees and move 120 pixels forward. Next we change its heading to 0 degrees and move 120 pixels forward. The code to do this is shown below:

turtle.setposition(-185, 60)
turtle.setheading(90)
turtle.pendown()
turtle.forward(120)
turtle.setheading(0)
turtle.forward(120

To draw the upper right bound, we need to lift up our pen and move the mouse to the position (185, 60). Then we can repeat the steps we used to draw the upper left bound but change the heading to 180 degrees. The code to do this is shown below:

turtle.penup()
turtle.setposition(185, 60)
turtle.setheading(90)
turtle.pendown()
turtle.forward(120)
turtle.setheading(180)
turtle.forward(120)

To draw the lower right bound, we need to lift up our pen and move the mouse to the position (185, -60). Then we can repeat the steps we used to draw the upper left bound but change the heading to 270 degrees. The code to do this is shown below:

turtle.penup()
turtle.setposition(185, -60)
turtle.setheading(270)
turtle.pendown()
turtle.forward(120)
turtle.setheading(180)
turtle.forward(120)

To draw the lower left bound, we need to lift up our pen and move the mouse to the position (-185, -60). Then we can repeat the steps we used to draw the upper left bound but change the heading to 270 degrees. The code to do this is shown below:

turtle.penup()
turtle.setposition(-185, -60)
turtle.setheading(270)
turtle.pendown()
turtle.forward(120)
turtle.setheading(0)
turtle.forward(120)

The generated image is shown below:


To draw the square, we simply use the drawSquare function. The size of the square is 330. So we pass it in as a parameter. The code to do this is shown below:

drawSquare(330)

The generated image is shown below:



To draw the first inner circle, we need to lift up the turtle and move it to the position that is 155 pixels from the center of the circle. Then we draw a circle of radius 155 pixels. The code to do this is shown below:

turtle.penup()
turtle.setposition(0, -155)
turtle.pendown()
turtle.circle(155)

The generated image is shown below:


The second circle is 125 pixels from the center of the symbol. We need to lift up the turtle and move it to the position that is 125 pixels from the center of the circle. Then we draw a circle of radius 125 pixels. The code to do this is shown below:

turtle.penup()
turtle.setposition(0, -125)
turtle.pendown()
turtle.circle(125)

The generated image is shown below:


To draw the leftward outer line, we need to draw a line from point (0, -155) to (-120, 10). We will use the coordinateDistance function defined earlier using Epa. The function definition is shown below:

def coordinateDistance(x1, y1, x2, y2):
    dx = x1 - x2
    dy = y1 - y2
    D = math.sqrt((dx * dx) + (dy * dy))
    return D
We pass the distance between the two points into a variable called distanceLength. The code to do this is shown below:

distanceLength = coordinateDistance(0, -155, -120, 10)

We also need to find the angle between the two points. The code to do this is shown below:

myradians = math.atan2(10 - (-155), -120 - (0))
upperAngle = math.degrees(myradians)
turtle.setheading(upperAngle)

Once we have the angle between the two points and the length, we need to move the turtle to the point (0, -155) and draw the line. The code to do this is shown below:

turtle.penup()
turtle.setposition(0, -155)
turtle.pendown()
turtle.forward(distanceLength)

We now do the same for the right line. The code to do this is shown below:

turtle.penup()
turtle.setposition(0, -155)
turtle.setheading(180 -  upperAngle)
turtle.pendown()
turtle.forward(distanceLength)

The generated image is shown below:


To hide the point of intersection between the lines and the inner circle, we need to use a trick. I will move the turtle to the point (0, -140) and draw a triangle to connect points (20, -110) and (-20, -110). The pen colour will be set to white and I shall fill the triangle with a white colour. The code to do this is shown below:

turtle.penup()
turtle.setposition(0, -140)
turtle.color(“white”, “white”)
equalSide = coordinateDistance(0, -140, 20, -110)
myradians = math.atan2(-110 - (-140), 20 - (0))
upperAngle = math.degrees(myradians)
turtle.setheading(upperAngle)
turtle.begin_fill()
turtle.pendown()
turtle.forward(equalSide)
turtle.setheading(180)
turtle.forward(40)
turtle.setheading(-upperAngle)
turtle.forward(equalSide)
turtle.end_fill()

The generated image is shown below:


We shall now draw the left inner line. To draw it, we need to first change the pen colour of the mouse to black. Then move it to the position (0, -90). The value of the point on the left side we are trying to get to is (-110, 60). The code to do this is shown below:

turtle.penup()
turtle.pencolor(0, 0, 0)
turtle.setposition(0, -90)
distance = coordinateDistance(0, -90, -110, 60)
myradians = math.atan2(60 - (-90), -110 - (0))
upperAngle = math.degrees(myradians)
turtle.setheading(upperAngle)
turtle.pendown()
turtle.forward(distance)

We need to lift up the pen and move forward by 35 pixels, place the pen down and move forward by 60 pixels. The code to do this is shown below:

turtle.penup()
turtle.forward(35)
turtle.pendown()
turtle.forward(60)

We lift up the turtle and repeat the same sequence for the right. The code to do this is shown below:

turtle.penup()
turtle.setposition(0, -90)
turtle.setheading(180 - upperAngle)
turtle.pendown()
turtle.forward(distance)
turtle.penup()
turtle.forward(35)
turtle.pendown()
turtle.forward(60)

We will comment out the drawHorizontalLine and drawVerticalLine functions and see our creation in all its glory.

The generated image is shown below:


Conclusion

This was one of the harder symbols to draw. But at the end, we made it.