我是靠谱客的博主 光亮糖豆,最近开发中收集的这篇文章主要介绍Python turtle模块绘图2021-08-27,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

文章目录


turtle模块绘图:简单的绘图工具,提供一个小海龟,可以将它理解成一个机器人,只能听得懂有限的命令。

绘图窗口的原点(0, 0)在正中间,默认海龟的方向为右

运动命令
forward(d)向前移动d长度
backward(d)向后移动d长度
right(d)向右转向对少度
left(d)向左转d度
goto(x, y)移动到坐标为(x,y)的位置
speed(speed)笔画绘制的速度[0, 10]

笔画控制命令
up() 笔画抬起,在移动的时候不会绘图
down() 笔画落下,移动会绘图
setheading() 改变海龟方向
pensize()画笔的宽度
pencolor()笔画颜色
rest()恢复所有设置,清空窗口,重置turtle状态
clear()清空窗口,不会重置turtle
circle(r, e) 绘制一个圆形,r为半径,e为次数可不写

begin_fill()
fillcolor(colorstr)
end_fill()

其他命令
done()程序继续执行
undo()撤销上一次命令
hideturtle()隐藏海龟
showturtle()显示海龟
screensize()


# 导入turtle库
import turtle
turtle.screensize(800, 400)
turtle.speed(1)
turtle.forward(100)
turtle.right(72)
turtle.forward(100)
turtle.goto(100, -200)
turtle.up()
turtle.goto(-100,100)
turtle.down()
turtle.pencolor("red")
print("ugfh")
turtle.pensize(10)
turtle.forward(100)
turtle.setheading(50)

# turtle.reset()
# turtle.clear()
turtle.goto(100, 50)
turtle.begin_fill()
turtle.fillcolor("blue")

turtle.circle(50, steps = 5)
turtle.end_fill()
turtle.forward(50)
turtle.undo()
turtle.hideturtle()
turtle.done()

最后

以上就是光亮糖豆为你收集整理的Python turtle模块绘图2021-08-27的全部内容,希望文章能够帮你解决Python turtle模块绘图2021-08-27所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部