I am so excited that Python involved module turtle since version 2.5. Once seen it I am grabbed back to golden time of my childhood. In this blog I will try to demo how to use turtle to play tangram.
So what does turtle really mean here? Exactly the turtle is the figure of cursor in Logo), which is a classic education programming language as initiation of computer programming for children. Using simple directives we can lead the turtle to draw kinds of graphic. Because this WYSIWYG way the turtle may be a best case of teaching through lively activities.
It was great lucky 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 education of computer from kids. What the most impressed me is that except the events I participated, event as operating robots to go out of mazes was 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.
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
To move the turtle, the first step is learning basic motion and redirect directives:
- Turn left
- Turn right
- Of cause you can set direction of turtle in directly
We can draw a basic square using these basic directives:
It is boring without color. Turtle offers two directives to control color.
- Set pen color
- Set filling color
- Also you can set them at once
If want to fill a shape with 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:
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:
We get the following classic tangram after running the codes above:
After import the module trangrams.py above, you can draw any tangram patterns yourself. For example the following code use it to draw the digit 1:
Then please draw the other digits if interested.
I figure that Logo successfully catches children’s eyes for drawing is attractive in natural. It makes children familiar with concepts of 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 implies how we use computational ability in modern life.
- Expand our sense
All modern info carrier(web pages, digital music/video, even game e.g.) expands our sense system to improve our efficiency of getting informations.
- Model our life
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 infos we get, faster and faster we processed. The singularity is really near.