欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

turtle画了一个皮卡丘

程序员文章站 2022-05-09 13:47:30
...
from turtle import *
import numpy as np

reset()
setup(500,500)
screensize(bg='white')
pensize(1.5)

# 尾巴尾巴尾巴
pu()
goto(0,-100)
left(185)
color('black','gold')
begin_fill()
pd()

# 上尾巴
a = np.random.RandomState(10)
angle = a.rand(6)
angle = angle * 20+85
edge = [20, 30, 30, 25, 50, 70]

for i in range(6):
    fd(edge[i])
    if i%2 == 0: right(angle[i])
    else: left(angle[i])

#左上角点
goto(-180,50)

# 下尾巴
pu()
goto(-8,-110)
seth(190)
pd()

edge2 = [20, 30, 30, 25, 60, 40]

for i in range(6):
    fd(edge2[i])
    if i%2 == 0: right(angle[i]+np.random.randn(1))
    else: left(angle[i])

# 左上相连闭合
left(15)
fd(70)
goto(-180,50)

# 右下相连闭合
pu()
goto(-8,-110)
seth(10)
pd()
fd(10)
goto(0,-100)
end_fill()

# 身体外轮廓填充

fillcolor('gold')
begin_fill()
goto(0,-100)
# 左身体
seth(105)
circle(-180,30)
# 左脸颊
seth(110)
circle(-100,50)
# 左耳朵
seth(150)
circle(-190,15)
goto(-32,108)
circle(-190,15)
goto(-40,145)
seth(-20)
circle(-180,27)
# 额头
seth(20)
circle(-100,40)
# 右耳朵
seth(95)
circle(-190,17)

goto(103,158)
circle(-190,13)
goto(125,175)
seth(-80)
circle(-190,27)



# 右脸颊和下巴
seth(295)
circle(-65,25)
seth(260)
circle(50,30)
seth(285)
circle(-40,60)
goto(117,-5)


# 手
goto(110,-9)
seth(-45)
circle(-45,58)
goto(121,-52)

# 双脚
goto(122,-50)
seth(-30)
circle(-35,55)
# 右脚
seth(75)
circle(-50,30)
circle(-4,140)
seth(-95)
circle(-80,40)
circle(-4,180)

#左脚
goto(125,-110)
seth(-90)
circle(-80,30)
circle(-6,140)
seth(200)
circle(-90,65)

# 与尾巴闭合
goto(0,-100)
end_fill()

# fillcolor('yellow')
# begin_fill()
# goto(0,-100)
# # 左身体
# seth(105)
# circle(-180,30)
# # 左脸颊
# seth(110)
# circle(-100,50)
# # 左耳朵
# seth(150)
# circle(-190,15)
pu()
goto(-32,108)
pd()
fillcolor('black')
begin_fill()
circle(-190,15)
goto(-40,145)
goto(-32,108)
end_fill()

pu()
goto(-40,145)
pd()
seth(-20)
circle(-180,27)


# 额头
seth(20)
circle(-100,40)

# 右耳朵
seth(95)
circle(-190,17)
goto(103,158)

fillcolor('black')
begin_fill()
circle(-190,13)
goto(125,175)
goto(103,158)
end_fill()

# pu()
# goto(125,175)
# pd()

# seth(-80)
# circle(-190,27)

# 右脸颊和下巴
# seth(295)
# circle(-65,25)
# seth(260)
# circle(50,30)
# seth(285)
# circle(-40,60)
pu()
goto(117,-5)
pd()
seth(205)
circle(-150,20)
circle(-50,20)
circle(-180,5)

# 手
pu()
goto(117,-5)
pd()
goto(110,-9)
seth(-45)
circle(-45,58)
goto(121,-52)
circle(-45,22)
goto(110,-70)
x=110
y=-70
for i in range(5):
    x = x-2
    if i%2 == 0: y = y+4
    else: y = y-4
    goto(x,y)

x=100
y=-66
for i in range(3):
    y = y-2
    if i%2 != 0: x = x+3
    else: x = x-4
    goto(x,y)

seth(205)
circle(-50,60)

x=100
y=-66

pu()
goto(x,y)
pd()

for i in range(3):
    y = y+2
    if i%2 != 0: x = x+4
    else: x = x-3
    goto(x,y)

seth(130)
circle(75,45)

pu()
goto(92,-53)
pd()

seth(95)
circle(-75,25)

# # 双脚
# pu()
# goto(121,-52)
# pd()
# goto(122,-50)
# seth(-30)
# circle(-35,55)
# # 右脚
# seth(75)
# circle(-50,30)
# circle(-4,140)
# seth(-95)
# circle(-80,40)
# circle(-4,180)

# #左脚
# goto(125,-110)
# seth(-90)
# circle(-80,30)
# circle(-6,140)
# seth(200)
# circle(-90,65)

# # 与尾巴闭合
# goto(0,-100)

# 左脚上半部分
pu()
goto(125,-110)
pd()

seth(85)
circle(4,180)
seth(230)
circle(65,30)
seth(60)
circle(50,70)

# end_fill()

# 眼睛
pu()
goto(45,52)
pd()
fillcolor('black')
begin_fill()
circle(14,360)
end_fill()

pu()
goto(40,50)
pd()
fillcolor('white')
begin_fill()
circle(5,360)
end_fill()

pu()
goto(105,50)
pd()
fillcolor('black')
begin_fill()
circle(14,360)
end_fill()

pu()
goto(97,48)
pd()
fillcolor('white')
begin_fill()
circle(5,360)
end_fill()

# 腮红
pu()
goto(33,20)
pd()
fillcolor('tomato')
begin_fill()
circle(15,360)
end_fill()
pu()
goto(115,17)
pd()
fillcolor('tomato')
begin_fill()
circle(13,360)
end_fill()

# 鼻子
pu()
fillcolor('black')
begin_fill()
goto(61,22)
pd()
goto(65,22)
goto(64,20)
goto(61,22)
end_fill()

# 微笑
a=np.sqrt(3)

pu()
goto(62,13)
pd()
seth(240)
circle(-12,120)

pu()
goto(62,13)
pd()
seth(-60)
circle(12,120)

# 嘴巴填充
pu()
goto(62,13)
pd()

fillcolor('lightcoral')
begin_fill()
seth(240)
circle(-12,60)
goto(62-6*a,7)
seth(-90)
circle(20,55)
goto(62,-10)

pu()
goto(62,13)
pd()
seth(-60)
circle(12,60)
goto(62+6*a,7)
seth(-90)
circle(-20,55)
goto(62,-10)

end_fill()
hideturtle()
相关标签: python小记录