Building the GPUG logo. In Python Logo.


Logo - Man this brings back memories. I remember my first interaction with a computer when I was about 12 years old. I did math lessons on what I think was a Commodore Amiga . I looked around and found Logo installed somewhere on it. I figured it out and convinced our school in George to buy 2 computers. I then became the Outeniqua Pre-Primary Schools first computer teacher. I coded a clock using Logo and it was running on one of the computers for about three months. People from all over came to have a look. Schools then started buying computers. They couldn't be seen to fall behind our small school you know! This was 1987/1988 - about 25 years ago!

Logo Programming Language

The Logo programming language was as graphical environment to teach and learn programming. You were the master of a Turtle and told it what to do. Move forward, turn left. The turtle has a pen on its belly and it draws a line wherever it goes. The picture below shows some of the steps you can do to make a rectangle

Gauteng Python Users Group

We recently started the Gautent Python Users Group and we joked about creating a Pythonic logo. I remembered that the Python standard distribution comes installed with a Turtle graphics / Logo module. Here is the code and the result.

The GPUG generated Logo

Here is a small movie of the output of the script. See the poor turtle moving.

logo

Code

Here is the code, but you can also Download it here.

In [1]:
# -*- coding: utf-8 -*-
"""
Created on Fri May 16 09:04:31 2014
@author: tobie nortje @tooblippe
GPUG LOGO - just for fun
www.insightstack.co.za  link to blog at bottom of this page

"""

from turtle import Turtle

t = Turtle()

#shorter functions names
l = t.left
r = t.right
f = t.fd
b = t.back
pu = t.pu
pd = t. pd
pf = t.pd
goto = t.goto

#scaling
scale = 3.0 # scaling factor - smaller makes GPUG bigger
line_color = 'black'
line_weight = '2'

t.pensize(line_weight)


g = [
    (l, 90),
    (f, 100),
    (l, 90),
    (f, 50),
    (l, 90),
    (f, 50),
    (pu, None),
    (f, 50),
    (l, 90),
    (f, 50),
    (r, 180),
    (pd, None),
    (f, 100),
    (r, 90),
    (f, 200),
    (r, 90),
    (f, 100)
   ]

p = [ (pu, None),
     (f, 10),
     (pd, None),
     (f, 100),
     (r, 90),
     (f, 100),
     (r, 90),
     (f, 100),
     (r, 90),
     (f, 100),
     (b, 200)
     ]

u = [ (r, 90),
      (pu, None),
      (f, 120),
      (pd, None),
      (l, 90),
      (f, 200),
      (b, 200),
      (r, 90),
      (f, 100),
      (l, 90),
      (f, 200),
      (b, 200),
      (r,90),
      (pu, None),
      (f, 120),
      (pd, None)
      ]

#lets draw GPUG

gpug_logo = [ g, p, u, g]

def do( (command, parameter)):
    if command == f or command == b:
        parameter = parameter / scale
        
    if command == goto:
        pu()
        command( parameter)
        pd()
    elif command == pu: pu()
    elif command == pd: pd()
    else:
        command(parameter)
        
for letter in gpug_logo : 
    for command in letter:
        do(command)

t.hideturtle()


print "press CTR-C to exit"
press CTR-C to exit

In []:

Run the code

You can download the code above, or just run the command below te get it working. If this doens't work, just download the file at Here. Save it and run it using Python.

wget -O logo.py http://bit.ly/gpug_logo  && python logo.py

comments powered by Disqus