【python模块】turtle模块

【python模块】turtle模块

'''
turtle模块
是一个简单的绘图工具
提供一个小海龟,可以把它理解为一个机器人,只能听懂有限的命令
绘图窗口原点(0,0)在正中间,默认朝向右
'''
import turtle

'''运动命令
turtle.forward(d)向前移动d长度
backward(d)向后移动d长度
right(d)向右转动d度,下
left(d)向左转动d度,上
goto(x,y) 移动到(x,y)
speed(speed)速度
'''
turtle.speed(5)
turtle.forward(100)
turtle.left(45)
turtle.forward(100)


'''笔画控制命令
up()笔画抬起,不会绘图
down()
setheading()改变海龟的朝向 
pensize(d)笔画宽度
pencolor(color)笔画颜色
reset() 重置,清空窗口
clear() 清空窗口,不会重置
circle(d) 绘制一个圆形,半径
circle(d,step5=5) 绘制五边形,半径
begin_fill()
turtle.fillcolor("red")
end_fill()
'''
turtle.up()
turtle.goto(-100,200)
turtle.down()
turtle.forward(30)

'''其他命令
done() 程序继续执行
undo() 撤销上一次动作
hideturtle() 隐藏海龟
showturtle() 显示海龟
screensize(x,y)
'''
turtle.reset()
turtle.begin_fill()
turtle.circle(100,steps=5)
turtle.fillcolor("red")
turtle.end_fill()

#保持程序不结束
turtle.done()
 

猜你喜欢

转载自blog.csdn.net/acycy/article/details/82697219
今日推荐