Python Turtle 小项目 6

本次教大家画一只简易龙猫

代码讲解

首先,导入turtle模块

import turtle as t

初始化画笔属性

t.pensize(2)
t.speed(0)

绘制龙猫的身体(用circle函数绘制弧线)

t.pu()
t.goto(-150,0)
t.pd()
t.left(90)
t.circle(-300,30)

t.seth(180)
t.circle(-40,270)

t.seth(20)
t.circle(-150,40)

t.seth(90)
t.circle(-40,270)

t.seth(-60)
t.circle(-300,30)

t.seth(-80)
t.circle(-(t.pos()[0]--150+4)/2,200)

绘制龙猫的两只眼睛,坐标手动计算

t.pu()
t.goto(-84,50)
t.dot(20)
t.goto(47.5,50)
t.dot(20)

绘制龙猫的鼻子,坐标手动计算

t.goto(-18.25,25)
t.dot(30)
t.goto(-18.25,10)
t.pd()
t.seth(-90)
t.circle(-20,90)
t.pu()
t.goto(-18.25,10)
t.seth(-90)
t.pd()
t.circle(20,90)

绘制龙猫的右手(龙猫的视觉)

t.pu()
h=0
pos=-74,-25
for i in range(3):
    t.pu()
    t.goto(pos[0],pos[1])
    t.seth(h)
    t.pd()
    t.circle(-35,40)
    h=t.heading()
    pos=t.pos()
    t.seth(-135)
    t.fd(20)
t.seth(-135)
t.fd(20)

绘制龙猫的左手(龙猫的视觉)

t.pu()
h=180
pos=47.5,-25
for i in range(3):
    t.pu()
    t.goto(pos[0],pos[1])
    t.seth(h)
    t.pd()
    t.circle(35,40)
    h=t.heading()
    pos=t.pos()
    t.seth(-45)
    t.fd(20)
t.seth(-45)
t.fd(20)

隐藏画笔并保持显示

t.hideturtle()
t.done()

最终代码

import turtle as t

t.pensize(2)
t.speed(0)

t.pu()
t.goto(-150,0)
t.pd()
t.left(90)
t.circle(-300,30)

t.seth(180)
t.circle(-40,270)

t.seth(20)
t.circle(-150,40)

t.seth(90)
t.circle(-40,270)

t.seth(-60)
t.circle(-300,30)

t.seth(-80)
t.circle(-(t.pos()[0]--150+4)/2,200)

t.pu()
t.goto(-84,50)
t.dot(20)
t.goto(47.5,50)
t.dot(20)

t.goto(-18.25,25)
t.dot(30)
t.goto(-18.25,10)
t.pd()
t.seth(-90)
t.circle(-20,90)
t.pu()
t.goto(-18.25,10)
t.seth(-90)
t.pd()
t.circle(20,90)

t.pu()
h=0
pos=-74,-25
for i in range(3):
    t.pu()
    t.goto(pos[0],pos[1])
    t.seth(h)
    t.pd()
    t.circle(-35,40)
    h=t.heading()
    pos=t.pos()
    t.seth(-135)
    t.fd(20)
t.seth(-135)
t.fd(20)

t.pu()
h=180
pos=47.5,-25
for i in range(3):
    t.pu()
    t.goto(pos[0],pos[1])
    t.seth(h)
    t.pd()
    t.circle(35,40)
    h=t.heading()
    pos=t.pos()
    t.seth(-45)
    t.fd(20)
t.seth(-45)
t.fd(20)

t.hideturtle()
t.done()

喜欢的话记得点赞关注哦!

关注我,订阅免费的Turtle画图专栏,查看更多的turtle绘图教学吧!(持续更新ing...)

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值