A. Conceptual design length color python
First of all, we conceived a simple python. It's color is yellow, the shape of a snake is crawling.
Second, Prepare graphics library
Python has a graphics library called turtle we first introduced it.
import turtle (python corresponding module to import or import from ... import, which is similar to the specific usage include header file import refer to C of https://blog.csdn.net/Greenovia/article/details/79399475 )
The turtle is a graphics library here I just introduce a few common functions
1. Set the canvas
turtle.setup (a, b, c, d) a, b are two parameters controlling the width and height of the canvas, c, d property controls the position of the canvas;
turtle.screesize (a, b, c) a, b control the width and height of the canvas, C to control the color canvas;
E.g:
turtle.setup (800,400,200,200) // Create a width of 800 pixels high by 400 pixels, the coordinates (200, 200) canvas
turtle.screensize (800,400, 'green') // Create a width of 800 pixels, 400 pixels high, color is green canvas
2. brush set
turtle.penup () lift the pen movement, not drawn graphics, from one place to another draw
turtle.pendown () falls brush, start drawing graphics
turtle.pensize () to set the width of the brush;
turtle.pencolor () passed in parameter setting pen color, none is passed, compared with the current pen color
turtle.seth (a) to change the direction of travel of a sea turtle to an absolute degree of the statement, but not only change the direction of travel
3. Brush Motion Control
turtle.fd (X) (turtle.forward (X)) the mobile X-direction length of the pixel to the current pen, straight line (X may be a negative number)
turtle.circle (r, o) according to r O draw an arc angle (r default center position in the left turtles distance r, o draw angle, default full circle 360 degrees)
4. directional control
turtle.seth (a) to change the direction (turtle.setheading (a)) a as an absolute angle of travel direction
turtle.left(a)
turtle.right (a) to the left / right of a
III Code Example
color python python
import turtle
turtle.setup(1300,400,-250,250)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.color("yellow")
turtle.seth(-40)
for i in range(4):
turtle.circle(40,80)
turtle.circle(-40,80)
turtle.circle(40,80/2)
turtle.fd(40)
turtle.circle(16,180)
turtle.fd(40 * 2/3)
turtle.done()
---------------------