Python Turtle 小项目 9 小黄人

闲来没事儿,继续用turtle绘制图案,这次我们要绘制的是小黄人:

好了,现在开始代码教学:

1.导入模块

from turtle import *

2.设置属性

pensize(4)

3.绘制头部外轮廓和头发

left(90)
fd(50)
circle(-120,90)
seth(90)
circle(45,80)
circle(45,-80)
left(20)
circle(45,95)
circle(45,-95)
seth(90)
circle(-45,80)
circle(-45,-80)
right(20)
circle(-45,95)
circle(-45,-95)
seth(0)
circle(-120,90)
fd(50)

4.绘制眼镜和眼睛

bk(15)
seth(180)
begin_fill()
fd(35)
right(90)
fd(20)
right(90)
fd(35)
end_fill()

bk(35)
seth(90)
pensize(8)
circle(42.5,540)
p11=pos()
circle(-42.5,540)
pensize(4)
p12=pos()
h=heading()

pu()
goto(p11)
seth(180)
fd(40)
dot(20)
right(180)
fd(80)
dot(20)
left(180)
goto(p12)
seth(h)
pd()

seth(180)
begin_fill()
for i in range(2):
    fd(35)
    left(90)
    fd(20)
    left(90)
end_fill()

5.移到裤带的位置

fd(35)
left(90)
fd(50)
fd(25)
p=pos()
bk(25)

6.绘制裤带

p6=pos()
left(60)
fd(80) # length
p8=pos()
right(90)
fd(12.5)
right(90)

pu()
fd(15)
dot(8)
bk(15)
pd()

left(90)
fd(12.5)
p2=pos()
goto(p)

7.绘制裤兜

seth(-90)
fd(50)
left(90)
p3=pos()
goto(p2[0],ycor())
goto(p2)

8.绘制鞋子和下半身轮廓

pu()
goto(p3)
pd()
seth(-90)
circle(120,30)
left(90)
circle(300,10)
circle(300,-10)
right(90)
circle(120,60)
p13=pos()
right(90)
fd(35)
right(90)
fd(80)
right(90)
circle(-15,90)
left(90)
fd(20)
goto(p13)
seth(-90)
fd(35)
left(90)
fd(80)
left(90)
circle(15,90)
right(90)
fd(20)
goto(p13)
seth(0)
circle(120,60)
left(90)
circle(-300,10)
circle(-300,-10)
right(90)
circle(120,30)

9.绘制另一个裤兜

goto(xcor(),p6[1])
seth(90)
fd(20)
bk(20)
seth(-90)
fd(25)
p4=pos()
bk(25)

10.绘制另一个裤带

right(60)
fd(80) # length
p9=pos()
left(90)
fd(12.5)
left(90)

pu()
fd(15)
dot(8)
bk(15)
pd()

right(90)
fd(12.5)
p5=pos()
goto(p4)

seth(-90)
fd(50)
right(90)
p7=pos()
goto(p5[0],ycor())
goto(p5)

11.绘制两边裤带的连接线,使下半部分形成裤子

pu()
goto(p8)
seth(0)
pd()
goto(p9)

12.绘制裤子中间的半圆形

dis=p9[0]-p8[0]
seth(180)
fd(dis/2)
left(90)
pu()
fd(25)
seth(0)
pd()
fd(25)
bk(50)
right(90)
fd(30)
circle(25,180)
fd(30)

13.绘制嘴巴

pu()
seth(-180)
fd(25)
right(90)
fd(25)
fd(25)
p10=pos()
seth(-45)
pd()
circle(30,110)
goto(p10)

14.隐藏画笔并保持窗口显示

ht()
done()

最终代码:

from turtle import *

pensize(4)

left(90)
fd(50)
circle(-120,90)
seth(90)
circle(45,80)
circle(45,-80)
left(20)
circle(45,95)
circle(45,-95)
seth(90)
circle(-45,80)
circle(-45,-80)
right(20)
circle(-45,95)
circle(-45,-95)
seth(0)
circle(-120,90)
fd(50)

bk(15)
seth(180)
begin_fill()
fd(35)
right(90)
fd(20)
right(90)
fd(35)
end_fill()

bk(35)
seth(90)
pensize(8)
circle(42.5,540)
p11=pos()
circle(-42.5,540)
pensize(4)
p12=pos()
h=heading()

pu()
goto(p11)
seth(180)
fd(40)
dot(20)
right(180)
fd(80)
dot(20)
left(180)
goto(p12)
seth(h)
pd()

seth(180)
begin_fill()
for i in range(2):
    fd(35)
    left(90)
    fd(20)
    left(90)
end_fill()

fd(35)
left(90)
fd(50)
fd(25)
p=pos()
bk(25)

p6=pos()
left(60)
fd(80) # length
p8=pos()
right(90)
fd(12.5)
right(90)

pu()
fd(15)
dot(8)
bk(15)
pd()

left(90)
fd(12.5)
p2=pos()
goto(p)

seth(-90)
fd(50)
left(90)
p3=pos()
goto(p2[0],ycor())
goto(p2)

pu()
goto(p3)
pd()
seth(-90)
circle(120,30)
left(90)
circle(300,10)
circle(300,-10)
right(90)
circle(120,60)
p13=pos()
right(90)
fd(35)
right(90)
fd(80)
right(90)
circle(-15,90)
left(90)
fd(20)
goto(p13)
seth(-90)
fd(35)
left(90)
fd(80)
left(90)
circle(15,90)
right(90)
fd(20)
goto(p13)
seth(0)
circle(120,60)
left(90)
circle(-300,10)
circle(-300,-10)
right(90)
circle(120,30)

goto(xcor(),p6[1])
seth(90)
fd(20)
bk(20)
seth(-90)
fd(25)
p4=pos()
bk(25)

right(60)
fd(80) # length
p9=pos()
left(90)
fd(12.5)
left(90)

pu()
fd(15)
dot(8)
bk(15)
pd()

right(90)
fd(12.5)
p5=pos()
goto(p4)

seth(-90)
fd(50)
right(90)
p7=pos()
goto(p5[0],ycor())
goto(p5)

pu()
goto(p8)
seth(0)
pd()
goto(p9)

dis=p9[0]-p8[0]
seth(180)
fd(dis/2)
left(90)
pu()
fd(25)
seth(0)
pd()
fd(25)
bk(50)
right(90)
fd(30)
circle(25,180)
fd(30)

pu()
seth(-180)
fd(25)
right(90)
fd(25)
fd(25)
p10=pos()
seth(-45)
pd()
circle(30,110)
goto(p10)

ht()
done()

喜欢的话就点赞关注吧!在Turtle画图专栏中可以查看往期的Turtle小项目文章哦!

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值