Python学习——哆啦A梦的脑袋

本文分享了一个使用Python的Turtle库绘制卡通猫的过程。从自定义goto_函数避免画图痕迹开始,逐步介绍了如何画出猫的头部、眼睛、鼻子、嘴巴、胡子和铃铛。通过精确的角度和坐标计算,展现了Turtle库在图形绘制上的灵活性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

turtle画图

刚开始画这个是学校里学python一开始就学的turtle画图,正好作业里也有要画一个卡通图,就画了这个,我一开始是在草稿本子上一点一点的去想他要转多少度角,然后goto_到哪个位置去画鼻子眼睛,要正转还是反转,还挺麻烦的。

首先的准备工作

定义一个goto_()函数,让goto的时候不会留下痕迹,比较方便

def goto_(x, y):
pu()
goto(x, y)
pd(

##画头

def head():
goto_(100, 0)
fillcolor(“blue”)
begin_fill()
lt(45)
circle(150, 270)
lt(45)
fd(15)
lt(135)
circle(-128.78, 270)
lt(135)
fd(15)
end_fill()
fillcolor(“red”)
begin_fill()
circle(-9, 180)
fd(212)
circle(-9, 180)
fd(212)
end_fill()

##画眼睛

def eye():
fillcolor(“white”)
begin_fill()
goto_(0, 219.82746)
lt(90)
circle(25,180)
fd(25)
circle(25, 180)
fd(25)
goto_(0, 219.82746)
circle(-25, 180)
fd(25)
circle(-25, 180)
fd(25)
end_fill()
pensize(10)
goto_(-10, 194.82746)
circle(10, 180)
goto_(10, 194.82746)
rt(180)
circle(-10,180)
pensize(2)

##画鼻子和嘴巴

def nose_mouth():
fillcolor(“red”)
begin_fill()
goto_(0, 149.82746)
lt(90)
circle(15)
end_fill()
rt(90)
fd(130)
lt(90)
circle(100, 70)
goto_(0, 19.82746)
rt(250)
circle(-100, 70)

##画胡子

def beard():
lt(70)
goto_(-30, 83.79672)
lt(10)
fd(100)
goto_(-30, 83.79672+15.333)
rt(10)
fd(110)
goto_(-30, 83.79672+15.333+15.333)
rt(15)
fd(110)
rt(165)
goto_(30, 83.79672)
rt(10)
fd(100)
goto_(30, 83.79672+15.333)
lt(10)
fd(110)
goto_(30, 83.79672+15.333+15.333)
lt(15)
fd(110)
rt(15)

##画铃铛

def bell():
fillcolor(“gold”)
begin_fill()
goto_(0, -39)
circle(15)
end_fill()

##源码

from turtle import*
pensize(2)


def goto_(x, y):
    pu()
    goto(x, y)
    pd()


def head():
    goto_(100, 0)
    fillcolor("blue")
    begin_fill()
    lt(45)
    circle(150, 270)
    lt(45)
    fd(15)
    lt(135)
    circle(-128.78, 270)
    lt(135)
    fd(15)
    end_fill()
    fillcolor("red")
    begin_fill()
    circle(-9, 180)
    fd(212)
    circle(-9, 180)
    fd(212)
    end_fill()


def eye():
    fillcolor("white")
    begin_fill()
    goto_(0, 219.82746)
    lt(90)
    circle(25,180)
    fd(25)
    circle(25, 180)
    fd(25)
    goto_(0, 219.82746)
    circle(-25, 180)
    fd(25)
    circle(-25, 180)
    fd(25)
    end_fill()
    pensize(10)
    goto_(-10, 194.82746)
    circle(10, 180)
    goto_(10, 194.82746)
    rt(180)
    circle(-10,180)
    pensize(2)


def nose_mouth():
    fillcolor("red")
    begin_fill()
    goto_(0, 149.82746)
    lt(90)
    circle(15)
    end_fill()
    rt(90)
    fd(130)
    lt(90)
    circle(100, 70)
    goto_(0, 19.82746)
    rt(250)
    circle(-100, 70)


def beard():
    lt(70)
    goto_(-30, 83.79672)
    lt(10)
    fd(100)
    goto_(-30, 83.79672+15.333)
    rt(10)
    fd(110)
    goto_(-30, 83.79672+15.333+15.333)
    rt(15)
    fd(110)
    rt(165)
    goto_(30, 83.79672)
    rt(10)
    fd(100)
    goto_(30, 83.79672+15.333)
    lt(10)
    fd(110)
    goto_(30, 83.79672+15.333+15.333)
    lt(15)
    fd(110)
    rt(15)


def bell():
    fillcolor("gold")
    begin_fill()
    goto_(0, -39)
    circle(15)
    end_fill()


def main():
    head()
    eye()
    nose_mouth()
    beard()
    bell()
    hideturtle()


if __name__ == '__main__':
    main()
    done()

作者:Don 任

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值