• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python使用turtle库绘制小猪佩奇(实例代码)

python 搞代码 4年前 (2022-01-08) 81次浏览 已收录 0个评论

这篇文章主要介绍了Python使用turtle库绘制小猪佩奇,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

turtle(海龟)是Python重要的标准库之一,它能够进行基本的图形绘制。turtle图形绘制的概念诞生于1969年,成功应用于LOGO编程语言。

turtle来源gaodai#ma#com搞@@代~&码*网库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形。刚开始绘制时,小海龟位于画布正中央,此处坐标为(0,0),前进方向为水平右方。
在Python3系列版本安装目录的Lib文件夹下可以找到turtle.py文件。

下面通过代码给大家介绍Python使用turtle库绘制小猪佩奇,

具体代码如下所示:

 # -*- coding:utf-8 -*- import turtle as t import time def main(): t.pensize(4) t.hideturtle() t.colormode(255) t.color((255, 155, 192), "pink") t.setup(840, 500) t.speed(10) # 鼻子 t.pu() t.goto(-100, 100) t.pd() t.seth(-30) t.begin_fill() a = 0.4 for i in range(120): if 0 <= i <30 or 60 < 90: a + 0.08 t.lt(3) # 向左转3度 t.fd(a) 向前走a的步长 else: - t.end_fill() t.pu() t.seth(90) t.fd(25) t.seth(0) t.fd(10) t.pd() t.pencolor(255, 155, 192) t.seth(10) t.begin_fill() t.circle(5) t.color(160, 82, 45) t.fd(20) 头 t.color((255, 192), "pink") t.fd(41) t.fd(0) t.seth(180) t.circle(300, -30) t.circle(100, -60) t.circle(80, -100) t.circle(150, -20) t.circle(60, -95) t.seth(161) t.circle(-300, 15) t.goto(-100, 100) t.seth(-30) 0.4 for i in range(60): if 0 30 耳朵 t.fd(-7) t.fd(70) t.seth(100) t.circle(-50, 50) t.circle(-10, 120) 54) t.fd(-12) t.fd(30) 56) 眼睛 "white") t.fd(-20) t.fd(-95) t.circle(15) t.color("black") t.fd(12) t.fd(-3) t.circle(3) t.fd(-25) t.fd(40) 腮 192)) t.fd(65) t.circle(30) 嘴 t.color(239, 69, 19) t.fd(15) t.fd(-100) t.seth(-80) t.circle(30, 40) t.circle(40, 80) 身体 t.color("red", (255, 99, 71)) t.fd(-78) t.seth(-130) 10) 30) t.fd(230) 3) 100, 100)) t.seth(-135) t.circle(-80, 63) t.circle(-150, 24) 手 t.fd(-40) t.fd(-27) t.seth(-160) t.seth(-10) t.circle(-20, 90) t.fd(237) t.seth(-20) t.seth(-170) t.circle(20, 脚 t.pensize(10) t.color((240, 128, 128)) t.fd(-75) t.fd(-180) t.seth(-90) t.seth(-180) t.pensize(15) t.fd(90) 尾巴 t.pensize(4) t.fd(95) t.circle(70, 20) t.circle(10, 330) __name__== '__main__': 画小猪佩奇 main() time.sleep(10)

执行结果:

总结

如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

以上就是Python使用turtle库绘制小猪佩奇(实例代码)的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python使用turtle库绘制小猪佩奇(实例代码)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址