Teaching Kids Programming – Turtle Graphics/Canvas Programming in Python


Teaching Kids Programming: Videos on Data Structures and Algorithms

The LOGO (Turtle Graphic) programming was popular in 1980s. And it has been ported to Python as a Library which we can do this:

1
from turtle import *
from turtle import *

Then, we can send commands to the turtle to draw on the canvas. The turtle package requires the GUI to work though.

Instead of using the “REPEAT” command in LOGO, we use the Python for/while loop. For example, the following draws a star:

1
2
3
for _ in range(5):
    fd(100)
    rt(144)
for _ in range(5):
    fd(100)
    rt(144)

The turtle graphs becomes even more powerful with the modern Python compiler. Similar to loops, the procedure definition aka “TO” keyword is no longer in need as we can directly define functions/procedures in Python.

The Turtle library is focusing on the interface between Turtle and the Canvas, and some commands are quite useful for example, the “undo()” command undos the last draw.

See all supported commands of Turtle Graphics in Python:
https://docs.python.org/3/library/turtle.html

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
298 words
Last Post: Teaching Kids Programming - Algorithm to Compute the Smallest Value of the Rearranged Number (Math)
Next Post: Teaching Kids Programming - Introduction to BASH Commands

The Permanent URL is: Teaching Kids Programming – Turtle Graphics/Canvas Programming in Python

Leave a Reply