Wednesday 21 June 2017

Drawing Adinkra Symbols using Python - Introduction


I was privileged to live in Ghana for 15 months of my life. All over the place, I would see this symbols that 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 for the African culture in general.

The reason I believe is because of the lack of relevance to modern day life. What if we could merge culture and technology and create Afritech.

Afritech would be a way of living that embraces our culture as its past and technology as the future.

This series is my own contribution. In my own small way, I aim to teach technology with a focus on African culture and history.

This series "Drawing Adinkra Symbols using Python" will look at the Adinkra symbols and attempt to draw them using the Python programming language.

The version of Python used here will be Python 2.7. I agree that the world has moved on to Python 3 however, a lot of Python packages haven't kept up with this pace so Python 2.7 is a safe place to start.

I will be using turtle graphics in Python to achieve this. Turtle graphics earned their usage in computer science from the Logo programming language and are a great way to teach programming concepts.

With all things in life, it is best to start from the beginning. The documentation for Python turtle contains all that we will need. I shall not go into it.

Rather, my approach will be to explain commands as I need them. I will assume that I am teaching an absolute beginner to the Python programming language who has installed the Python interpreter on his computer and is ready to start coding.

I don't intend to optimize the code for this projects. I will leave that for you the reader. My job will be to go through the symbols and draw them using code.

Let's get started.

Grid Drawing
Drawing to scale involves using a grid. In order to draw the Adinkra symbols, I will use a grid of 500 X 500 pixels in my Python environment.

The images are 200 X 200 pixels and I will attempt to use code to draw them. The aim will be to replicate the images using the grid.

To draw a grid, the commands we will need are:
  1. import turtle
  2. turtle.penup()
  3. turtle.setposition(x coordinate, y coordinate)
  4. turtle.pendown()
  5. turtle.forward(distance)
  6. turtle.right(degree)
  7. turtle.left(degree)
So with this 7 commands we can create a grid. Go through the Python turtle graphics documentation for version Python 2.7 and try out the commands in your Python.

The code to do this is shown below:

import turtle

# Horizontal lines
turtle.penup()
turtle.setposition(-250, 250)
turtle.pendown()
turtle.forward(500)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.penup()
turtle.setposition(-250, 200)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, 150)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, 100)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, 50)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, 0)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, -50)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, -100)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, -150)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-250, -200)
turtle.pendown()
turtle.forward(500)

# Vertical lines
turtle.penup()
turtle.setposition(-200, 250)
turtle.right(90)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-150, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-100, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(-50, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(0, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(50, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(100, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(150, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(200, 250)
turtle.pendown()
turtle.forward(500)
turtle.penup()
turtle.setposition(0, 0)
turtle.left(90)

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

The image of the grid is shown below:


This grid will be the basis of how we draw all our Adinkra symbols.

No comments:

Post a Comment