最近初学python,完成老师布置的期中作业时回忆起了童年,所以花了一天画这只喵喵,期待洛克王国的手游
目录
【参考链接】:
【最终成果】:
【代码思想】:
【代码】:
【参考链接】:
1.Python绘图Turtle库详解
2.用Python turtle库 绘制皮卡丘
3.用python-turtle优雅的画椭圆
4.使用Python画小猪佩奇(turtle库)
5.几种提升turtle绘图速度的方法
思路参考皮卡丘,画椭圆参考3和4,4中循环的一段可以直接复制粘贴过来用,参数的调节(椭圆大小)可以参考3
【最终成果】:
【代码思想】:
把喵喵分解为,头,身子,尾巴,五官(耳朵,眼睛,胡须,嘴巴,面部浅绿色)
用到的元素主要有:弧线,椭圆,弧线由不同半径的圆形(circle命令)画出,
椭圆使用循环递归划出,链接为:
点的确定可以用,返回鼠标点击位置的函数
【代码】:
import turtle as t
t.hideturtle()
#提笔去向(x,y)处
def mygoto(x,y):
t.penup()
t.goto(x,y)
t.pendown()
#返回鼠标左键点击的位置
def click(x,y):
print(x,y)
t.listen()
t.onscreenclick(click,1)
#画椭圆,定义t.seth改变倾斜度,a改变椭圆大小
def tuoyuan(a=0.01):
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.01
t.lt(3) # 向左转3度
t.fd(a) # 向前走a的步长
else:
a = a - 0.01
t.lt(3)
t.fd(a)
#在x,y处画半径为r的圆
def mycircle(x,y,r,yanse):
t.color(yanse,yanse)
t.begin_fill()
mygoto(x,y)
t.seth(0)
t.circle(r)
t.end_fill()
#定义画布
t.screensize(500,600,'white')
t.setup(550,650,0,0)
t.speed(0)
t.delay(0)
#t.tracer(False)
#猫猫耳朵(避免遮盖先画耳朵)
#左耳
t.pensize(7)
t.colormode(255)
t.color((4,60,4),(147,189,65))
t.begin_fill()
mygoto(-157,138)
t.goto(-114,231)
t.goto(-90,178)
t.goto(-157,138)
t.end_fill()
t.color(181,83,64)
t.begin_fill()
mygoto(-127.0 ,206.0)
t.goto(-114,231)
t.goto(-103.0 ,211.0)
t.goto(-127.0 ,206.0)
t.end_fill()
#右耳
t.color((4,60,4),(147,189,65))
t.begin_fill()
mygoto(-40 ,168)
t.goto(34.0 ,232.0)
t.goto(39.0, 219.0)
t.goto(16.0 ,93.0)
t.goto(-40.0 ,168.0)
t.end_fill()
t.color(181,83,64)
t.begin_fill()
mygoto(11.0 ,211.0)
t.goto(34.0 ,232.0)
t.goto(34.0 ,191.0)
t.goto(11.0 ,211.0)
t.end_fill()
#喵喵身体
t.pensize(7)
t.color((4,60,4),(147,189,65))
t.begin_fill()
mygoto(-140.0, 39.0)
t.goto(-189.0, -22.0)
t.circle(30,30)
t.goto(-139.0 ,-15.0)
t.goto(-133,12)
t.seth(-110)
t.circle(300,20)
t.seth(-80)
t.circle(300,5)
t.seth(10)
t.circle(300,5)
t.goto(-109,-99)
t.goto(-118.0 ,-89.0)
t.goto(-109,-99)
t.goto(-59.0 ,-115.0)
t.goto(-31.0 ,-138.0)
t.seth(80)
t.circle(260,20)
t.circle(50,60)
t.goto(0,-51)
t.seth(110)
t.circle(300,20)
#t.goto(-29,37)
t.goto(-140.0, 39.0)
t.end_fill()
mycircle(-135.0 ,-57.0,5,(220,251,122))
#喵喵大脸
t.pensize(7)
mygoto(-180,100)#起笔位置
t.begin_fill()
t.color((4,60,4),(147,189,65))
##上脸
t.seth(60)
t.fd(30)
print(t.position())
t.circle(-100,120)
print(t.position())
##下脸
mygoto(-180,100)
import turtle as t
t.seth(-80)
t.fd(20)
for i in range(20):
t.lt(3)
t.fd(3)
t.circle(150,60)
for i in range(20):
t.lt(3)
t.fd(1)
print(t.position())
t.fd(20)
t.color(147,189,65)
t.goto((8.21,125.98))
t.color((4,60,4),(147,189,65))
t.end_fill()
#喵喵五官(眼睛,嘴巴,胡须,耳朵)
#面部
#笔
t.color((220,251,122),(220,251,122))
t.pensize(2)
#面部浅绿填充
t.begin_fill()
mygoto(-180,100)
t.goto(-144,146)
t.seth(0)
t.circle(-120,15)
t.seth(-60)
t.fd(15)
t.circle(20,90)
t.goto(-50,136)
t.circle(-20,90)
t.circle(-80,45)
t.circle(-20,120)
t.seth(-140)
t.circle(-30,100)
t.seth(-140)
t.circle(-40,100)
t.seth(-140)
t.circle(-10,140)
t.seth(160)
t.goto(-178,84)
t.seth(110)
t.goto(-180,100)
t.end_fill()
#胡须
#右胡须
t.color((87,132,26),(220,251,122))
t.begin_fill()
mygoto(-31,86)
t.seth(0)
t.circle(300,10)
t.seth(175)
t.circle(300,10)
t.end_fill()
t.color((87,132,26),(220,251,122))
t.begin_fill()
mygoto(-30,74)
t.seth(-13)
t.circle(300,10)
t.seth(175)
t.circle(300,10)
t.end_fill()
#左胡须
t.color((87,132,26),(220,251,122))
t.begin_fill()
mygoto(-166,110)
t.seth(170)
t.circle(200,10)
t.seth(-20)
t.circle(200,10)
t.end_fill()
t.color((87,132,26),(220,251,122))
t.begin_fill()
mygoto(-170,98)
t.seth(170)
t.circle(200,10)
t.seth(-20)
t.circle(200,10)
t.end_fill()
#嘴
def zui(x0,y0,x,y):
mycircle(x0,y0,2.5,(172,205,82))
mygoto(x0,y0)
t.color(4,60,4)
t.seth(-45)
t.fd(x)
a=45
for i in range(4):
t.seth(a)
t.fd(y)
a=-a
t.seth(45)
t.fd(x)
zui(-131,87,7,15)
print(t.position())
mycircle(-79,83,2.5,(172,205,82))
#眼睛
#笔
#左眼
t.color((4,75,5),(4,75,5))
t.begin_fill()
mygoto(-141,105)
t.seth(-15)
tuoyuan(0.4)
t.end_fill()
#左眼仁
mycircle(-141,123,1,'white')
mycircle(-137,110,4,(2,118,10))
#右眼
t.color((4,75,5),(4,75,5))
t.begin_fill()
mygoto(-50,90)
t.seth(0)
tuoyuan(0.45)
t.end_fill()
#右眼仁
mycircle(-53,110,1.3,'white')
mycircle(-49,97,5,(2,118,10))
#耳朵(避免遮盖移至最前方)
#喵喵尾巴
#上尾巴
t.pensize(7)
t.color((4,60,4),(220,250,126))
t.begin_fill()
mygoto(-26.0, -89.0)
t.seth(-10)
t.fd(25)
t.seth(10)
t.circle(70,80)
t.goto(78,-16)
t.goto(64,-6)
t.seth(85)
t.fd(30)
t.circle(-40,100)#尾巴尖
print(t.position())
#中缝
t.pensize(3)
t.seth(-150)
t.circle(50,80)
t.rt(30)
t.circle(-150,45)
t.seth(190)
t.circle(-190,12)
t.goto(-26.0, -89.0)
t.end_fill()
#下尾巴
t.begin_fill()
t.pensize(7)
#逆中缝
t.pensize(3)
t.lt(180)
t.goto(-6.47,-100.96)
t.circle(190,12)
t.seth(215)
t.lt(180)
t.circle(150,45)
t.lt(30)
t.seth(215)
t.lt(255)
t.circle(-50,80)
mygoto(116.82,59.04)
t.pensize(7)
t.color((4,60,4),(152,194,70))
t.seth(-150)
t.circle(20,100)
t.seth(-80)
t.circle(80,20)
t.seth(-85)
t.fd(30)
t.goto(101,-21)
t.goto(121,-40)
t.seth(-125)
t.fd(60)
t.goto(72,-90)
t.goto(74,-102)
t.seth(-150)
t.circle(-240,15)
t.seth(185)
t.circle(-30,50)
t.goto(-26.0, -89.0)
t.end_fill()
t.mainloop()



