Rush! Turtle of Logo! 中文版
I am so excited that Python involved module turtle since version 2.5. Once seen it I am grabbed back to the golden time of my childhood. In this blog, I will try to demo how to use the turtle to play tangram.
What is the turtle?
So what does turtle mean here? Exactly the turtle is the figure of cursor in Logo, which is a classic education programming language as an initiation of computer programming for children. Using simple directives we can lead the turtle to draw kinds of graphics. Because this WYSIWYG way the turtle may be a best-case of teaching through lively activities.
Competition of Computer Application
It was great luck for me to attend the 3rd National Children Competition of Computer Application stands for Wuxi in 1999. There were two events for me, the first was making papers using Microsoft Paint shipped in Windows 95, the second was using Logo to play tangram in finite time, the more the better.
At the time of 486, these computer competitions were held to answer the call of
Xiaoping Deng to initiate the education of computers from kids. What the most impressed me is that except the events I participated in, event as operating robots to go out of mazes were also included. It is amazon even now!
After the game, we visited the computer museum in Shanghai which exhibited 8086 series chips. I only knew these chips are brains of computers at that age, but how it works? Whatever that trip and question opened the main theme of my life in the future.
Review the Classic Turtle
To pay honor to Logo, I will mock the environment of Logo programming when coding in turtle of Python3. This means the following choices:
- Use procedure programming pattern instead of OOP
- Following logo mode to code degrees:
- 0 means north
- 90 means east
- 180 means south
- 270 means west
Follow my Order
To move the turtle, the first step is learning basic motion and redirect directives:
- Forward
turtle.forward(distance)
orturtle.fd(distance)
- Backword
turtle.backward(distance)
orturtle.back(distance)
- Turn left
turtle.left(degree)
- Turn right
turtle.right(degree)
- Of cause you can set direction of turtle in directly
turtle.setheading(degree)
We can draw a basic square using these basic directives:
1 | import turtle |
Make it Colorful
It is boring without color. Turtle offers two directives to control color.
- Set pen color
turtle.pencolor(color_string)
- Set filling color
turtle.fillcolor(color_string)
- Also you can set them at once
turtle.color(pencolor, fillcolor)
If want to fill a shape with one specified color, we should wrap our code with function calls begin_fill and end_fill. The following code demos how to draw a red triangle:
1 | import turtle |
Procedural Programming
Procedural programming is a pattern to organize codes into procedures for reuse. When we play tangrams in Logo, we can define a specific procedure for each shape like the following codes:
1 | ''' |
We get the following classic tangram after running the codes above:
Let’s Play Tangram Together
After import the module trangrams.py above, you can draw any tangram patterns yourself. For example, the following code uses it to draw the digit 1:
1 | import turtle |
Then please draw the other digits if interested.
At the Bottom
I figure that Logo successfully catches children’s eyes for drawing is attractive in nature. It makes children familiar with concepts of the coordinate system, degree, direction and so on.
Although time flies, Today I still appreciate the farseeing educators who held the competitions. The events at that time imply how we use computational ability in modern life.
- Expand our sense
All modern info carriers (web pages, digital music/video, even game e.g.) expands our sense system to improve our efficiency of getting information. - Model our life
The general computer run codes in memory to model human activities. Information processing speed up for more and more processes are implemented online.
More and more info we get, faster and faster we processed. The singularity is near.