import turtle #导入turtle库
turtle.speed(5) #画笔移动的速度
turtle.penup() #提起画笔,移动画笔但并不会绘制图形
turtle.pendown() #放下画笔,移动画笔即开始绘制
turtle.left(90) #逆时针转动画笔90度
turtle.right(90) #顺时针时针转动画笔90度
turtle.fd(25) #向前移动指定距离 fd=forward
#turtle.bd(30) #向后移动指定距离 bd=backward
turtle.fillcolor("red") #填充颜色
turtle.begin_fill() #开始填充
turtle.circle(200,50) #画一个圆 200 是半径,50 是弧度
turtle.end_fill() #结束填充
#在程序的最后一行加一行
#不然画画结束后会自动退出
turtle.done()
例子:
import turtle
#画个正方形,填充颜色为:红色
turtle.fillcolor("red")
turtle.begin_fill()
turtle.speed(5)
turtle.fd(25)
turtle.left(90)
turtle.fd(25)
turtle.left(90)
turtle.fd(25)
turtle.left(90)
turtle.fd(25)
turtle.end_fill()
#画个弧度,填充颜色为:绿色
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(200,180)
turtle.end_fill()
turtle.done() #可以使画布不出现(未响应)
turtle库 用途:
可以绘制自己想要的任何图形。