首页 > 技术文章 > python中turtle绘图的简单指令

zlong123 2019-02-23 19:53 原文

'''turtle
绘图原点为中心点,默认朝向前(右)
#导入turtle 库(绘图工具)
import turtle


笔画控住命令
up() 笔画抬起,笔头移动,不划线
down() 笔画落下,划线移动
setheading() 改变笔头朝向
pensize(大小) 改变笔画宽度
pencolor(colorstr)笔画颜色
reset() 回复所有设置,清空窗口,重置turtle
clear() 清空窗口,停留最后位置和属性
circle(r,e) 绘制半径为r的图形,e=steps=5为5边行

begin_fill() 开始填充
fillcolor(颜色) 填充颜色
end_fill() 结束填充

运动命令
forward(d) 向前移动d长度
backward(d)向后移动d长度
right(d) 向右转动多少度
left(d) 向左转动多少度
goto(x,y) 移动到(x,y)位置
speed(speed) 笔画绘制的速度
其他命令
done() 停留在结束界面
undo() 撤销上一次动作
hideturtle() 隐藏图标
showturtle() 显示图标
screensize(x,y) 屏幕大小
#画一个正方形边框(1)turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.done()
(2)
turtle.begin_fill()
turtle.fillcolor("red")
turtle.right(45)
turtle.circle(100,steps=4)
turtle.end_fill()
turtle.done()

奥运5环的绘制
turtle.up()
turtle.forward(200)
turtle.down()
turtle.circle(100)
turtle.up()
turtle.backward(200)
turtle.down()
turtle.right(90)
turtle.circle(100)
turtle.up()
turtle.left(90)
turtle.down()
turtle.circle(100)
turtle.up()
turtle.backward(200)
turtle.down()
turtle.right(90)
turtle.circle(100)
turtle.left(90)
turtle.circle(100)
turtle.done()



推荐阅读