1 turtle library Introduction
turtle library is a library in the Python language very popular rendering of the image, imagine a small turtle in a horizontal axis is x, and the vertical axis is the y coordinate origin, (0,0) position to start.
It moves in the plane coordinate system based on the control function of a set of instructions so as to draw a pattern on its path crawling.
2 brush
On the canvas, there is a default origin for the coordinate axes of the center of the canvas, there is an x-axis positive direction facing the coordinate origin small turtles. Here we describe the use of a small turtle two words: the origin of coordinates (position), facing the positive x-axis direction (direction), Turtle drawing, is the use of the position and direction described small turtles ( pen state).
Brushes (brush attributes, color, width, line drawing, etc.)
turtle.pensize (): Set the width of the pen;
turtle.pencolor (): none is passed, returns the current pen color, incoming pen color parameters, can be a string, such as "green", "red", it may be RGB 3-tuple.
urtle.speed (speed): setting the moving speed of the brush, brushed speed range [0,10] integer, the larger the number, the faster.
3 drawing commands
Actuating turtle drawing has many commands that can be divided into three types: one for the motion commands , one for the brush control command, there is a global control command .
Several commonly used to explain the movement command:
forward (100): 100 pixels to the current moving direction of the brush
right (90): 90 degrees clockwise movement
left (90): 90 degrees counterclockwise movement
goto (x, y): move to x, y at
circle (), dot (): draw a circle and draw points, respectively
Brush and global command:
fillcolor (colorstring): draw a fill color pattern
clear (): Empty turtle window
4 Example
1 Draw quadrilateral
2 Draw a cross
3 sunflowers
4 Rose
Page 5 pig
These are a few typical examples turtle library, we can use their imagination to use turtle to draw a more imaginative graphics.
This article reference URL:
https://www.cnblogs.com/chen0307/articles/9645138.html
https://www.cnblogs.com/widows/p/10100041.html
https://www.cnblogs.com/xiaoyh/p/9670748.html
Python and algorithms Community