Introduction to turtle library

 
 
#pythonDraw.py  
import turtle  
turtle.setup(650,350,200,200)  
turtle.penup()  
turtle.fd(-250)  
turtle.pendown()  
turtle.pensize(25)  
turtle.pencolor("purple")  
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()

function Function
turtle.color(mode)

mode = 1.0 decimal mode

= 255 integer mode

turtle.setup(width=0.5, height=0.75, startx=None, starty=None) Parameters: width, height: When the input width and height are integers, it represents pixels; when they are decimals, it represents the proportion of the computer screen, (startx, starty): This coordinate represents the position of the upper left corner of the rectangular window, if it is empty, The window is centered on the screen.


 
   
   
   
   
   
   


turtle.penup  或者  turtle.pu                                   提起画笔
turtle.pendown  或者 turtle.pd                                 放下画笔
turtle.pensize(width)  或者 turtle.width()            设置画笔宽度

turtle.pencolor(color)                    设置画笔颜色

turtle.done()  运行完不会自动退出

画笔控制方式
颜色字符串 turtle.pencolor("purple")
rgb 的小数值  turtle.pencolor(0.45,0.23.0.33)

rgb的元祖值 turtle.pencolor( (,,) )

运动控制函数

turtle.forward() 或者turtle.fd() (可以负数)

turtle.backward()   或者turtle.bk()

turtle.circle(r,extent) 意思是根据半径r绘制extent角度的弧形 (半径可以为负数,圆心位置不一样)

方向控制函数
turtle.setheading(angle)    turtle.seth(angle)    绝对角度

turtle.left(angle) turtle.right(angle)                        相对角度


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325871710&siteId=291194637