大家好,欢迎来到IT知识分享网。
先看最终成果
有点怪怪的
首先当然是导入turtle模块啦:
import turtle as tl
接下来就是各种的预设值了
# 设置窗口 screen = tl.Screen() screen.setup(width=500,height=500) # 设置窗口大小 screen.title('多拉A梦') # 设置窗口标题 # 设置画笔、颜色 tl.pensize(4) # 画笔大小 tl.color('black','#598ef9') # 画笔画线颜色与填充色
预设完成后,那就开始画吧
下面就简单粗暴的直接上完整代码
# -*- encoding: utf-8 -*- __Autor__ = 'Ocpt' import turtle as tl screen = tl.Screen() screen.setup(width=500,height=500) screen.title('多拉A梦') tl.pensize(4) tl.speed(0) tl.color('black','#598ef9') def setPen(size,x,y,color,angle): tl.begin_fill() tl.pencolor(color) tl.pensize(size) tl.penup() tl.goto(x,y) tl.setheading(angle) tl.pendown() def arc(sa,ea,x,y,r): tl.penup() # 抬起画笔 tl.goto(x,y) # 指定画笔的位置 tl.setheading(0) # 设置当前朝向为 0 度 tl.begin_fill() # 填充颜色块的开始位置 tl.left(sa) # 逆时针移动 sa 个度数 tl.fd(r) # 向当前朝向前进 r 个像素 tl.pendown() # 落下画笔,准备开始绘制 tl.left(90) # 逆时针移动 90度 tl.circle(r,ea-sa) # 画圆,半径为 r , 角度为 ea - sa # tl.end_fill() # 填充颜色块的结束位置 return tl.position() # 返回当前画笔的坐标 arc(-45,225,0,0,150) tl.end_fill() def ellipse(ea,r1,r2,sa,x,y,pc,bc): tl.penup() tl.goto(x,y) tl.color(pc, bc) tl.setheading(ea) tl.begin_fill() tl.pendown() for i in range(2): tl.circle(r1,sa) tl.circle(r2,sa) tl.end_fill() return tl.position ellipse(54,130,130,63,106,-106,'black','white') ellipse(-10,610,610,5,-106,-106,'black','white') # 左手 tl.begin_fill() tl.color('black','#598ef9') setPen(4,-106.00,-116.00,'black',225) tl.circle(150,45) tl.setheading(0) tl.fd(50) tl.setheading(90) tl.circle(-150,45) tl.end_fill() # 右手 tl.begin_fill() tl.color('black','#598ef9') setPen(4,106.00,-116.00,'black',-45) tl.circle(-150,45) tl.setheading(180) tl.fd(50) tl.setheading(90) tl.circle(150,45) tl.end_fill() # tl.begin_fill() tl.color('black','red') tl.goto(106,-106) tl.setheading(180) tl.circle(5,-180) tl.penup() tl.goto(-106,-106) tl.pendown() tl.circle(-5,-180) tl.end_fill() ellipse(-10,610,610,5,-106,-116,'black','red') ellipse(-10,610,610,5,-106,-106,'black','white') # 眼睛,鼻子 ellipse(45,40,20,90,-15,60,'black','white') ellipse(45,40,20,90,39,60,'black','white') ellipse(54,12,12,90,6,48,'black','#ae353e') ellipse(54,2,2,90,-5,55,'white','white') setPen(5,-30,80,'black',10) # 调用画笔设置函数 tl.circle(20,60) setPen(5,30,80,'black',-350) # 调用画笔设置函数 tl.circle(25,-60) # 嘴巴 setPen(4,-2,45,'black',-90) # 调用画笔设置函数 tl.fd(120) tl.setheading(-180) tl.right(180) def mouth(r1,a1,s1,r2,a2,s2,r3,a3,r4,a4,r5,a5,r6,a6): tl.circle(r1, a1) # tl.circle(180,10) tl.pensize(s1) # tl.pensize(3) tl.circle(r2, a2) # tl.circle(115,20) tl.pensize(s2) # tl.pensize(2) tl.circle(r3, a3) # tl.circle(90,20) tl.circle(r4, a4) # tl.circle(80,30) tl.pensize(s1) # tl.pensize(3) tl.circle(r5, a5) # tl.circle(30,40) tl.circle(r6, a6) # tl.circle(20,50) mouth(180,10,3,115,20,2,90,20,80,30,30,40,20,50) setPen(4,-2,-75,'black',180) # 调用画笔设置函数 tl.right(360) mouth(-180,10,3,-115,20,2,-90,20,-80,30,-30,40,-20,50) # 胡须 def fdline(x,y,angle,distance): tl.pensize(6) tl.penup() tl.goto(x,y) tl.setheading(angle) tl.pendown() tl.fd(distance) fdline(-40,20,160,65) fdline(-40,5,170,75) fdline(-35,-8,190,85) fdline(40,20,30,60) fdline(40,5,10,70) fdline(35,-8,-10,90) # 铃铛 tl.color('black','#f0db82') setPen(3,0,-120,'black',-180) # 调用画笔设置函数 tl.circle(20,360) tl.end_fill() ellipse(-220,30,30,20,20,-135,'black','#f0db82') ellipse(-220,30,30,20,20,-140,'black','#f0db82') setPen(2,-2.5,-140,'black',180) # 调用画笔设置函数 tl.circle(5,360) setPen(3,-2,-150,'black',-90) # 调用画笔设置函数 tl.fd(10) tl.end_fill() setPen(6,-200,-222,'black',0) # 调用画笔设置函数 tl.fd(400) tl.hideturtle() # 隐藏画笔的tl形状 tl.mainloop()
最后记得要加上主循环
tl.mainloop()
如果没有这个循环语句,程序将在画完的时候退出!
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/96706.html