Categories
Drawing Adinkra Symbols using Python

Adinkrahene

Adinkrahene is the symbol for leadership and charisma. This symbol is reportedly the inspiration for the design of the other symbols. Its simple yet abstract design, consisting of three concentric circles emphasizes the importance of ideas and abstract concepts.

In the last section, I introduced the grid. The grid will allow us create any symbol we want to because we can analyse and replicate the symbol of our choice.

We will draw a grid of 5 pixel squares on the image of the Adinkra symbol of our choice and replicate that on our grid. The squares on our grid are 10 pixels each. The goal of our program would be to create a grid that is two times the size of the original grid.

Drawing the 5 pixel squares on the Adinkrahene symbol will look as shown below:

Adinkrahene on a Grid
Adinkrahene on a Grid

Analysing the Symbol

The first circle is 8 squares away from the centre of the circle. So multiplying by 5 would give us 40 pixels.

The second circle is 13 pixels away from the centre of the circle. So multiplying by 5 would give us 65 pixels.

The third circle is 18 pixels away from the centre of the circle. So multiplying by 5 would give us 90 pixels.

The outer circle doesn’t touch the edge of the grid. It leaves a space of 1 square. The thickness of the circles are all 10 pixels.

The Plan to Draw the Symbol

To draw the Adinkahene symbol, we have to compensate for scaling up the shape to twice its size.

As a result of this, we shall increase the size of our pen to 20 pixels.

The first circle will have a radius of 80 pixels. We will move the pen to the location (0, -80) and draw a circle of 80 pixels.

The second circle will have a radius of 130 pixels. We will move the pen to the location (0, -130) and draw a circle of 130 pixels.

The third circle will have a radius of 180 pixels. We will move the pen to the location (0, -180) and draw a circle of radius 180 pixels.

Algorithm to Draw the Symbol

The algorithm to draw the Adinkrahene symbol is shown below:

  1. Lift up the pen
  2. Increase the pensize to 20 pixels
  3. Move the turtle to the position (0, -80)
  4. Place the pen down
  5. Draw a circle that is 80 pixels in radius
  6. Lift up the pen
  7. Move the turtle to the position (0, -130)
  8. Place the pen down
  9. Draw a circle that is 130 pixels in radius
  10. Lift up the pen
  11. Move the turtle to the position (0, -180)
  12. Place the pen down
  13. Draw a circle that is 180 pixels in radius

Using Turtle Graphics

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

The first step in drawing the Adinkrahene symbol is to draw the innermost circle and work our way out.

The first task is to lift up the pen. The code to do this is shown below:

turtle.penup()

Next we will increase our pensize to 20. The code to do this is shown below:

turtle.pensize(20)

The origin of the turtle is at (0, 0). To move the turtle to the position (0, -80), we use the command shown below:

turtle.setposition(0, -80)

At this point, place the pen down and draw a circle of radius 80 pixels. The code to do this is shown below:

turtle.pendown()
turtle.circle(80)

Our Python Turtle window will look like shown below:

Inner concentric circle of Adinkrahene
Inner Concentric Circle

Steps 6 to 9 are the steps for drawing the second circle. The code is similar to what you have already seen before and is shown below:

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

When we run the code, our second circle now appears as shown below:

Middle Circle of Adikrahene
Middle Concentric Circle

Steps 10 to 13 will draw the third circle. The code to do this is similar to what you have already seen before and is shown below:

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

When you run the code, the image is as shown below:

Adinkrahene
Final Image

Complete Code

The code for drawing the symbol is shown below:

"""
Project Name: Drawing Adinkra Symbols using Python
Symbol Name: Adinkrahene
Developer Name: Truston Ailende
Email Address: trustonailende@gmail.com
"""
import turtle
import math

# Square
def drawSquare(length):
    turtle.penup()
    turtle.setposition(-length/2.0, length/2.0)
    turtle.pendown()
    for i in range(0, 4):
        turtle.forward(length)
        turtle.right(90)
    turtle.penup()
    turtle.home()

# Horizontal lines
def drawHorizontalLine(length, division):
    pixelSpace = int(length / division)
    half = int(length / 2)
    for j in range((-half + pixelSpace), half, pixelSpace):
        turtle.penup()
        turtle.setposition(-half, j)
        turtle.pendown()
        turtle.forward(length)
    turtle.penup()
    turtle.home()

# Vertical lines
def drawVerticalLine(length, division):
    pixelSpace = int(length / division)
    half = int(length / 2)
    turtle.right(90)
    for k in range((-half + pixelSpace), half, pixelSpace):
        turtle.penup()
        turtle.setposition(k, half)
        turtle.pendown()
        turtle.forward(length)
    turtle.penup()
    turtle.home()

# Draw the grid
drawSquare(400)
drawHorizontalLine(400, 40)
drawVerticalLine(400, 40)

# Change the colour mode
turtle.colormode(255)

# Change the pencolor to red
turtle.pencolor(255, 0, 0)

# Draw the horizontal centre line
turtle.setposition(-200, 0)
turtle.pendown()
turtle.forward(400)
turtle.penup()

# Draw the vertical centre line
turtle.setposition(0, 200)
turtle.setheading(270)
turtle.pendown()
turtle.forward(400)

# Reset all the properties
turtle.home()
turtle.pencolor(0, 0, 0)

# Place code here
# Lift up the pen
turtle.penup()

# Set the pensize
turtle.pensize(20)

# Draw the first circle
turtle.setposition(0, -80)
turtle.pendown()
turtle.circle(80)

# Draw the second circle
turtle.penup()
turtle.setposition(0, -130)
turtle.pendown()
turtle.circle(130)

# Draw the third circle
turtle.penup()
turtle.setposition(0, -180)
turtle.pendown()
turtle.circle(180)

# End the program
turtle.done()

Where Can It Be Found?

A brief Google search led me to the following places where you can get branded Adinkrahene products:

  1. TShirts, Mugs and Phone Cases on TeePublic
  2. Pendants on Purple Blessing
  3. Socks on Adinkra Republic

Summary

At the end of this post, we have successfully used the Python Turtle environment to draw the Adinkrahene symbol.

The code for this series is available on GitHub. Please feel free to check it out.

Support this Series

Using the Adinkra symbols, I created the Adinkra Notebooks Collection.

You can support this series by buying one of them.

Categories
Python Programming

Why We Program

A computer is a machine that processes information under the control of a program.

By seeing the computer as a machine, you can then come to appreciate it like any device around you.

What however makes the computer special is the fact that you can program it.

What is Programming?

Computer programming is a way of giving computers instructions about what they should do in order to complete a set task.

A computer program will have the ability to take input data from a device such as a keyboard, process calculations, and make decisions based on certain conditions.

The practice of programming is one of teaching the computer to do something.

You must know how to do it yourself before you can teach a computer to do it for you.

Programming Languages

The instructions to execute the task that you want the computer to do for your are given to it in a programming language.

A programming language is a language that the computer understands.

Using a programming language, you are then able to transfer the logic of how you solved a problem to the computer.

To learn a programming language, you should be able to do the following with it:

  1. Take inputs
  2. Produce outputs
  3. Declare variables
  4. Use mathematical expressions
  5. Use conditional statements such as IF/ELSE
  6. Using looping statements such as WHILE
  7. Write functions

The Purpose of Programming

The purpose of programming is to automate processes.

When we have a problem that we want to solve, we list out the steps to solve that problem.

The sequence of steps we create is the algorithm.

The algorithm embodies all the logic we need to solve a problem.

With a well designed algorithm, we are confident that if we follow the steps of the algorithm, the result will always be correct.

We then take this algorithm and express it in a programming language as a program.

Once we have the program, the computer will handle the task for us.

We can then free up the time for our task until something goes wrong or we need to update the program’s logic.

This is the essence of programming.

Conclusion

Programming is a task that deals with the automation of the solution to a problem.

It is difficult hence the need to understand why it is needed before you do it.

Learn Python in One Week

If you want a quick and easy introduction to the Python programming language, you should check out my fifth book: Learn Python in One Week on the Amazon store.

Categories
Python for Financial Mathematics

Simple Interest

The concept of Simple Interest is one of the first things anyone learns in Financial Mathematics.

It isn’t really hard to program.

The formula I am using is given below:

Simple Interest Formula

The code to program this is shown below:

# Print out the purpose of the program
print("This program computes the compound amount using simple interest")
print("Reference: An Undergraduate Introduction to Financial Mathematics (Page 2)\n")

# Ask the user for the initial deposit
principal = float(input("Please enter the initial deposit: "))

# Ask the user for the rate as a percentage
rate = float(input("Please enter the rate: "))

# Ask the user for the number of years
years = float(input("Please enter the number of years: "))

# Compute the compounded amount
rate = rate / 100
compounded_amount = principal * ((1 + rate)**years)
print("\nThe compounded amount is:", round(compounded_amount, 2))

You can also find the code on GitHub.

Categories
Drawing Adinkra Symbols using Python

Drawing Adinkra Symbols using Python – Introduction

I was privileged to live in Ghana for 15 months of my life. All around me I would see these symbols which I didn’t know what they meant and one day I would ask my Ghanaian friends their meaning.

What would follow would be an exposition into the heart of Ghanaian culture. Sadly, that culture is dying. This isn’t just true for Ghanaian culture but African culture in general.

The reason I believe is that at present, our culture contributes nothing meaningful to our lives. What’s the use of culture if you can’t feed yourself. Sadly, everywhere you look, Africans are at the bottom of the totem pole.

Yet, that culture is relevant to today’s realities. I am a graduate of Systems Engineering from the University of Lagos and I would say that my understanding of my culture was made more meaningful to me from my studies.

There are many forms of power in this world. The strongest of which is identity. When you know who you are, you will reject anything else and the world will either conform to you or eliminate you but while you live, you will dictate your terms.

I am an Esan man from Edo state in Nigeria. A descendant of the last men to surrender to the British in the Southern Protectorate that would later become Nigeria.

Knowing this, I expect myself to lead and on the hard days, I remind myself of who I am.

That is the strength an identity gives you. Why African culture doesn’t do the same is simply because we have never sought to truly understand it.

Most of what we call culture in Africa is dogma. Whenever you ask the practitioners the reasons for some cultural belief, there is no explanation other than: “It’s our culture”.

Such an approach repels most people who only see the rites but cannot connect to their meaning. Rather than acceptance, such an attitude breads contempt.

I only got to learn about the Adinkra symbols because the Ghanaians were open about it. If my friends had kept quiet, I would never have discovered the beauty, minimalism and symmetry of the Adinkra symbols.

This series “Drawing Adinkra Symbols using Python” will look at 40 Adinkra symbols and my attempt to draw them using the Python programming language. It is a rewrite of a series on my old blog.

I will be using Python 3. In the old blog, I created the code using Python 2. I intend to optimize the code as much as I can.

For a quick introduction to the Python programming language, please check out my fifth book: “Learn Python In One Week“.

I will be drawing 40 symbols in all. This symbols are the easiest to draw because they are made up of lines and circular curves.

Using Turtle Graphics

Before we can draw the symbols satisfactorily, we need to use a grid to analyse the symbols.

A grid will be drawn over the images of the symbols and we will be attempt to reproduce the image on our own grid.

The base images are 200 X 200 pixels. I will be drawing on a grid of 400 X 400 pixels.

The commands we will be using are:
1. import turtle
2. turtle.penup()
3. turtle.setposition(x coordinate, y coordinate)
4. turtle.pendown()
5. turtle.forward()
6. turtle.right(degree)
7. turtle.left(degree)

Please check out the Python documentation if you need to know the meaning of the commands.

The source file should be saved as template.py because we will use this file to draw the other symbols.

The code is shown below:

"""
Project Name: Drawing Adinkra Symbols using Python
Developer Name: Truston Ailende
Email Address: trustonailende@gmail.com
"""
import turtle
import math

# Square
def drawSquare(length):
    turtle.penup()
    turtle.setposition(-length/2.0, length/2.0)
    turtle.pendown()
    for i in range(0, 4):
        turtle.forward(length)
        turtle.right(90)
    turtle.penup()
    turtle.home()

# Horizontal lines
def drawHorizontalLine(length, division):
    pixelSpace = int(length / division)
    half = int(length / 2)
    for j in range((-half + pixelSpace), half, pixelSpace):
        turtle.penup()
        turtle.setposition(-half, j)
        turtle.pendown()
        turtle.forward(length)
    turtle.penup()
    turtle.home()

# Vertical lines
def drawVerticalLine(length, division):
    pixelSpace = int(length / division)
    half = int(length / 2)
    turtle.right(90)
    for k in range((-half + pixelSpace), half, pixelSpace):
        turtle.penup()
        turtle.setposition(k, half)
        turtle.pendown()
        turtle.forward(length)
    turtle.penup()
    turtle.home()

# Draw the grid
turtle.speed(1000000)
drawSquare(400)
drawHorizontalLine(400, 40)
drawVerticalLine(400, 40)

# Change the colour mode
turtle.colormode(255)

# Change the pencolor to red
turtle.pencolor(255, 0, 0)

# Draw the horizontal centre line
turtle.setposition(-200, 0)
turtle.pendown()
turtle.forward(400)
turtle.penup()

# Draw the vertical centre line
turtle.setposition(0, 200)
turtle.setheading(270)
turtle.pendown()
turtle.forward(400)

# Reset all the properties
turtle.home()
turtle.pencolor(0, 0, 0)

# Place code here

# End the program
turtle.done()

Check out the GitHub repository for all the code for this series.

The code shown above creates a grid of 400 X 400 pixels and resets the turtle to be at the origin of the window when the program finishes running.

The generated image is shown below:

Grid to Draw Adinkra Symbols

Where Can They Be Found?

Adinkra Symbols are ubiquitous in Ghana, a beautiful West African country on the Atlantic, situated between Cote d’Ivoire and Togo.

On cloth and walls, in pottery and logos, these Asante tribe symbols can be found everywhere.

I would first notice them in a church.

Summary

This post has introduced the series “Drawing Adinkra Symbols using Python” which has the aim to draw 40 Adinkra symbols using the Python programming language.

There are a large number of Adinkra symbols but 40 were chosen because the are the easiest to analyse and draw.

Each of the motifs that make up the corpus of Adinkra symbolism has a name and meaning derived either from a proverb, an historical event, human attitude, animal behaviour, plant life, forms and shapes of inanimate and man-made objects.

There are evocative messages in them that carry traditional wisdom. The beliefs, history, and philosophy of the Akan people is also represented by them.

They are still relevant because the corpus of symbols covers all aspects of life in terms of values and the collective knowledge of a people that has been handed over from antiquity.

Support this Series

Using the Adinkra symbols, I created the Adinkra Notebooks Collection.

You can support this series by buying one of them.

Categories
Python for Financial Mathematics

Compound Amount using Monthly Compounding

Introduction

I live in Lagos, Nigeria the poverty capital of the world.

This year, I decided to study Financial Mathematics.

I am an Engineer with a BSc in Systems Engineering from the University of Lagos.

My decision to study Financial Mathematics stems from the knowledge that to solve a problem, I must thoroughly understand it.

Programming with Python

Whilst reading the book An Undergraduate Introduction to Financial Mathematics I realized that the formulas where jumping over my head.

Besides, its been a long time since I have done any Mathematics.

So I decided to write the compounding formula as a program. You can find the program below:

# Print out the purpose of the program
print("This program computes the compound amount using monthly compounding")
print("Reference: An Undergraduate Introduction to Financial Mathematics (Page 3)\n")

# Ask the user for the principal amount
principal = float(input("Please enter the principal amount: "))

# Ask the user for the rate as a percentage
rate = float(input("Please enter the rate: "))

# Ask the user for the number of years as a decimal value
years = float(input("Please enter the number of years as a decimal value: "))

# Compute the compound amount (Page 3)
r_n = rate / (12 * 100)
nt = years * 12
factor = (1 + r_n) ** nt
compound_amount = principal * factor
print("\nThe compound amount is:", round(compound_amount, 2))

In doing so, I have a ready made program that I can use to solve the exercises in the book without having to use a calculator.

Conclusion

The essence of code is to replace human rigour and tedium.

In creating this program, I had to study the formula and come up with my own program.

Now I understand the formula.

You can also find it on GitHub.