Python利用Turtle绘制哆啦A梦和小猪佩奇


Posted in Python onApril 04, 2022

1.哆啦A梦

“只要把愿望系在竹竿上请求月亮女神,心愿便能达成”。我超喜欢这句话。

哆啦A梦的创造要追溯到1969年的某个截稿日,作者藤子·F·不二雄的家里突然闯进了一只小猫,虽然很快就要截稿了,但作者还是和小猫玩了起来,还替小猫挠虱子,而这一挠就是几个小时。等作者发现时间不够用的时候,已经来不及完成稿子。这时作者像热锅上的蚂蚁走来走去,突然踢到了女儿的不倒翁玩具,于是作者灵光一现,把猫的形象和不倒翁结合起来,就创造了哆啦A梦。

2.小猪佩奇

对比于国内的《喜羊羊与灰太狼》和《熊出没》,我希望有一天喜羊羊被灰太狼炖了、熊大被光头强一枪打中,然后直接卖到动物园。(哈哈哈......)可是这个想法一直没实现,有些失落。还是看小猪佩奇吧:

由英国E1 Kids于2004年5月31日发行首播后,其动画片已于全球180个地区播放,现已播出6季;

中国中央电视台少儿频道也在热播之中,极简的动画风格,幽默的对话语调,深具教育意义的故事情节,不仅能让学龄前儿童学习知识,更能让小朋友们从小养成良好的生活习惯体验生活,深受全球各地小朋友们以及其家长们的喜爱。

3.Python代码实现(哆啦A梦)

Python利用Turtle绘制哆啦A梦和小猪佩奇

import turtle as t
t.title('哆啦A梦')
# t.speed(5)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')
 
"""猫脸"""
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()
t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()
t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
a = 0.4
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
t.pu()
t.goto(-38, 190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)
t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()
t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)
"""左边的胡子"""
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)
t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80, 40)
t.circle(80, 80)
t.end_fill()
t.pu()
t.home()
t.goto(-80, 70)
t.pd()
t.forward(160)
t.pu()
t.home()
t.goto(-50, 50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()
# 领带
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)
"""铃铛"""
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()
t.pu()
t.goto(-5, -40)
t.pd()
t.pensize(2)
t.color("black", '#79675d')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pensize(3)
t.right(115)
t.forward(7)
t.mainloop()

4.Python代码实现(小猪佩奇 )

Python利用Turtle绘制哆啦A梦和小猪佩奇

import turtle
from turtle import *
turtle.title('小猪佩奇')
 
def nose(x,y):
    """画鼻子"""
    pensize(5)
    pencolor((255, 155, 192))
    penup()
    # 将海龟移动到指定的坐标
    goto(x,y)
    pendown()
    # 设置海龟的方向(0-东、90-北、180-西、270-南)
    setheading(-30)
    begin_fill()
    fillcolor(255, 192, 203)
    a = 0.4
    for i in range(120):
        if 0 <= i < 30 or 60 <= i <90:
            a = a + 0.08
            # 向左转3度
            left(3)
            # 向前走
            forward(a)
        else:
            a = a - 0.08
            left(3)
            forward(a)
    end_fill()
    penup()
    setheading(90)
    forward(25)
    setheading(0)
    forward(10)
    pendown()
    """设置画笔的颜色(红, 绿, 蓝)"""
    pencolor(255, 155, 192)
    setheading(10)
    begin_fill()
    circle(5)
    color(160, 82, 45)
    end_fill()
    penup()
    setheading(0)
    forward(20)
    pendown()
    pencolor(255, 155, 192)
    setheading(10)
    begin_fill()
    circle(5)
    color(160, 82, 45)
    end_fill()
 
 
def head(x, y):
    """画头"""
    color((255, 155, 192), "pink")
    penup()
    goto(x,y)
    setheading(0)
    pendown()
    begin_fill()
    setheading(180)
    circle(300, -30)
    circle(100, -60)
    circle(80, -100)
    circle(150, -20)
    circle(60, -95)
    setheading(161)
    circle(-300, 15)
    penup()
    goto(-100, 100)
    pendown()
    setheading(-30)
    a = 0.4
    for i in range(60):
        if 0<= i < 30 or 60 <= i < 90:
            a = a + 0.08
            lt(3) #向左转3度
            fd(a) #向前走a的步长
        else:
            a = a - 0.08
            lt(3)
            fd(a)
    end_fill()
 
 
def ears(x,y):
    """画耳朵"""
    color((255, 155, 192), "pink")
    penup()
    goto(x, y)
    pendown()
    begin_fill()
    setheading(100)
    circle(-50, 50)
    circle(-10, 120)
    circle(-50, 54)
    end_fill()
    penup()
    setheading(90)
    forward(-12)
    setheading(0)
    forward(30)
    pendown()
    begin_fill()
    setheading(90)
    circle(-50, 50)
    circle(-10, 120)
    circle(-50, 56)
    end_fill()
 
 
def eyes(x,y):
    """画眼睛"""
    color((255, 155, 192), "white")
    penup()
    setheading(90)
    forward(-20)
    setheading(0)
    forward(-95)
    pendown()
    begin_fill()
    circle(15)
    end_fill()
    color("black")
    penup()
    setheading(90)
    forward(12)
    setheading(0)
    forward(-3)
    pendown()
    begin_fill()
    circle(3)
    end_fill()
    color((255, 155, 192), "white")
    penup()
    seth(90)
    forward(-25)
    seth(0)
    forward(40)
    pendown()
    begin_fill()
    circle(15)
    end_fill()
    color("black")
    penup()
    setheading(90)
    forward(12)
    setheading(0)
    forward(-3)
    pendown()
    begin_fill()
    circle(3)
    end_fill()
 
 
def cheek(x,y):
    """画脸颊"""
    color((255, 155, 192))
    penup()
    goto(x,y)
    pendown()
    setheading(0)
    begin_fill()
    circle(30)
    end_fill()
 
 
def mouth(x,y):
    """画嘴巴"""
    color(239, 69, 19)
    penup()
    goto(x, y)
    pendown()
    setheading(-80)
    circle(30, 40)
    circle(40, 80)
 
def body(x,y):
    '''画身体'''
    penup()
    goto(x,y)
    pencolor('red')
    fillcolor(250,106,106)
    pendown()
    begin_fill()
    setheading(-66)
    circle(-450,17)
    setheading(180)
    forward(185)
    setheading(85)
    circle(-450,17)
    end_fill()
    '''右手'''
    penup()
    goto(110,-45)
    pendown()
    pensize(8)
    pencolor(255, 192, 203)
    setheading(30)
    circle(-400,10)
    penup()
    goto(167,-5)
    pendown()
    setheading(-120)
    forward(20)
    left(100)
    forward(20)
    '''左手'''
    penup()
    goto(-25,-45)
    pendown()
    pencolor(255, 192, 203)
    setheading(150)
    circle(400,10)
    penup()
    goto(-78,-6)
    pendown()
    setheading(-60)
    forward(20)
    right(100)
    forward(20)
 
def feet1(x,y):
    pensize(7)
    pencolor(255, 192, 203)
    penup()
    goto(x,y)
    setheading(-90)
    pendown()
    forward(10)
    penup()
    goto(x-12,y-10)
    pendown()
    pencolor(238,201,0)
    fillcolor(238,230,132)
    begin_fill()
    setheading(0)
    forward(24)
    right(90)
    forward(36)
    right(90)
    forward(40)
    circle(-10,180)
    forward(16)
    left(90)
    forward(12)
    end_fill()
 
def feet2(x,y):
    pensize(7)
    pencolor(255, 192, 203)
    penup()
    goto(x,y)
    setheading(-90)
    pendown()
    forward(10)
    penup()
    goto(x-12,y-10)
    pendown()
    pencolor(238,201,0)
    fillcolor(238,230,132)
    begin_fill()
    setheading(0)
    forward(24)
    right(90)
    forward(36)
    right(90)
    forward(40)
    circle(-10,180)
    forward(16)
    left(90)
    forward(12)
    end_fill()
 
def tail(x,y):
    pensize(8)
    penup()
    goto(x,y)
    pendown()
    pencolor(255, 192, 203)
    setheading(-5)
    circle(30,100)
    circle(10,180)
    circle(20,150)
 
def backg(x):
    penup()
    goto(-420,x)
    setheading(0)
    fillcolor(50,205,50)
    begin_fill()
    forward(840)
    right(90)
    forward(300)
    right(90)
    forward(840)
    right(90)
    forward(300)
    end_fill()
    setheading(0)
    fillcolor(0,191,255)
    begin_fill()
    forward(840)
    left(90)
    forward(600)
    left(90)
    forward(840)
    left(90)
    forward(600)
    end_fill()
 
def cloude1(x, y):
    """画云"""
    penup()
    goto(x,y)
    setheading(90)
    fillcolor(255,255,255)
    begin_fill()
    a = 0.4
    for i in range(120):
        if 0 <= i < 30 or 60 <= i <90:
            a = a + 0.14
            # 向左转3度
            left(3)
            # 向前走
            forward(a)
        else:
            a = a - 0.15
            left(3)
            forward(a)
    end_fill()
 
def cloude2(x, y):
    """画云"""
    penup()
    goto(x,y)
    setheading(90)
    fillcolor(255,255,255)
    begin_fill()
    a = 0.4
    for i in range(120):
        if 0 <= i < 30 or 60 <= i <90:
            a = a + 0.15
            # 向左转3度
            left(3)
            # 向前走
            forward(a)
        else:
            a = a - 0.13
            left(3)
            forward(a)
    end_fill()
 
def setting():
    """设置参数"""
    pensize(5)
    # 隐藏海龟
    hideturtle()
    colormode(255)
    color((255, 155, 192), "pink")
    setup(840, 700)
    speed(10)
 
 
def main():
    """主函数"""
    
    setting() 
    backg(0)
    body(105,-20)
    nose(-100, 100)
    head(-69, 167)
    ears(0, 160)
    eyes(0, 140)
    cheek(80, 10)
    mouth(-20, 30)
    feet1(10,-150)
    feet2(90,-150)
    tail(130,-110)
    cloude1(-200,200)
    cloude2(300,300)
    done()
 
 
if __name__ == '__main__':
    main()

以上就是Python利用Turtle绘制哆啦A梦和小猪佩奇的详细内容,更多关于Python哆啦A梦 小猪佩奇的资料请关注三水点靠木其它相关文章!

Python 相关文章推荐
python基础while循环及if判断的实例讲解
Aug 25 Python
Pandas标记删除重复记录的方法
Apr 08 Python
PyQT实现多窗口切换
Apr 20 Python
python tkinter canvas使用实例
Nov 04 Python
python实现七段数码管和倒计时效果
Nov 23 Python
python接口自动化如何封装获取常量的类
Dec 24 Python
python使用PIL剪切和拼接图片
Mar 23 Python
python对接ihuyi实现短信验证码发送
May 10 Python
python3.8.1+selenium实现登录滑块验证功能
May 22 Python
Python 可视化神器Plotly详解
Dec 26 Python
利于python脚本编写可视化nmap和masscan的方法
Dec 29 Python
python flask开发的简单基金查询工具
Jun 02 Python
Python必备技巧之函数的使用详解
Python批量解压&压缩文件夹的示例代码
Apr 04 #Python
Python调用腾讯API实现人脸身份证比对功能
Python字符串常规操作小结
Anaconda安装pytorch和paddle的方法步骤
python lambda 表达式形式分析
PyTorch device与cuda.device用法
Apr 03 #Python
You might like
PHP查找数值数组中不重复最大和最小的10个数的方法
2015/04/20 PHP
php字符串比较函数用法小结(strcmp,strcasecmp,strnatcmp及strnatcasecmp)
2016/07/18 PHP
利用PHP获取网站访客的所在地位置
2017/01/18 PHP
基于thinkPHP3.2实现微信接入及查询token值的方法
2017/04/18 PHP
Yii2框架实现登录、退出及自动登录功能的方法详解
2017/10/24 PHP
PHP进阶学习之依赖注入与Ioc容器详解
2019/06/19 PHP
5款Javascript颜色选择器
2009/10/25 Javascript
javascript 内存回收机制理解
2011/01/17 Javascript
Jquery 自定义动画概述及示例
2013/03/29 Javascript
javascript分页代码实例分享(js分页)
2013/12/13 Javascript
JsRender for object语法简介
2014/10/31 Javascript
NodeJS整合银联网关支付(DEMO)
2016/11/09 NodeJs
js使用i18n实现页面国际化的方法
2017/05/09 Javascript
利用 spin.js 生成等待效果(js 等待效果)
2017/06/25 Javascript
详解Node.js amqplib 连接 Rabbit MQ最佳实践
2019/01/24 Javascript
p5.js临摹旋转爱心
2019/10/23 Javascript
jQuery实现简单日历效果
2020/07/05 jQuery
[03:54]DOTA2英雄梦之声_第06期_昆卡
2014/06/23 DOTA
[01:17]炒鸡美酒第四天TA暴走
2018/06/05 DOTA
[07:54]DOTA2-DPC中国联赛 正赛 iG vs VG 选手采访
2021/03/11 DOTA
Python最基本的数据类型以及对元组的介绍
2015/04/14 Python
Python中常见的数据类型小结
2015/08/29 Python
python中使用PIL制作并验证图片验证码
2018/03/15 Python
Pytorch入门之mnist分类实例
2018/04/14 Python
使用memory_profiler监测python代码运行时内存消耗方法
2018/12/03 Python
python数据预处理 :数据共线性处理详解
2020/02/24 Python
纯CSS绘制漂亮的圆形图案效果
2014/05/07 HTML / CSS
CSS3改变浏览器滚动条样式
2019/01/04 HTML / CSS
俄罗斯香水和化妆品购物网站:Л’Этуаль
2018/05/10 全球购物
酒店个人求职信范文
2014/01/25 职场文书
小学中秋节活动方案
2014/02/06 职场文书
送温暖献爱心活动总结
2014/07/08 职场文书
2014年流动人口工作总结
2014/11/26 职场文书
2014年财务工作总结与计划
2014/12/08 职场文书
校长个人总结
2015/03/03 职场文书
初中数学课堂教学反思
2016/02/17 职场文书