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

目录
  • 1.哆啦A梦
  • 2.小猪佩奇
  • 3.Python代码实现(哆啦A梦)
  • 4.Python代码实现(小猪佩奇 )

1.哆啦A梦

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

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

2.小猪佩奇

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

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

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

3.Python代码实现(哆啦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代码实现(小猪佩奇 )

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梦 小猪佩奇的资料请关注我们其它相关文章!

(0)

相关推荐

  • 使用python画个小猪佩奇的示例代码

    基本原理 选好画板大小,设置好画笔颜色.粗细,定位好位置,依次画鼻子.头.耳朵.眼睛.腮.嘴.身体.手脚.尾巴,完事儿. 都知道,Turtle 是 Python 内置的一个比较有趣味的模块,俗称"海龟绘图",它是基于 Tkinter 模块打造,提供一些简单的绘图工具. 在海龟作图中,我们可以编写指令让一个虚拟的(想象中的)海龟在屏幕上来回移动.这个海龟带着一只钢笔,我们可以让海龟无论移动到哪都使用这只钢笔来绘制线条.通过编写代码,以各种很酷的模式移动海龟,我们可以绘制出令人惊奇的图片.

  • Python+Turtle绘制可爱的多啦A梦的示例代码

    目录 1 送她的多啦A梦 2 白驹过隙 3 Python代码实现 1 送她的多啦A梦 一个哆啦A梦让她开心开心好久好久.我也很开心,昨天送了一个实体模型,今天用Python代码再弄一个送给她. 哆啦A梦(日语:ドラえもん,英语:Doraemon),旧译为机器猫,日本漫画<多啦A梦>及其衍生作品中的猫型机器人,本作的主人公.名字的意思是铜锣(ドラ)卫门(えもん). 哆啦A梦肚子上拥有四次元口袋,这个口袋直接通往四次元空间,再多的东西也放得下.害怕老鼠.平时的职责是照顾野比大雄. 2 白驹过隙 虽

  • Python使用turtle库绘制小猪佩奇(实例代码)

    turtle(海龟)是Python重要的标准库之一,它能够进行基本的图形绘制.turtle图形绘制的概念诞生于1969年,成功应用于LOGO编程语言. turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形.刚开始绘制时,小海龟位于画布正中央,此处坐标为(0,0),前进方向为水平右方. 在Python3系列版本安装目录的Lib文件夹下可以找到turtle.py文件. 下面通过代码给大家介绍Python使用turtle库绘制小猪佩奇, 具体代码如下所示: # -*

  • 啥是佩奇?使用Python自动绘画小猪佩奇的代码实例

    最近社会猪可是火遍了大江南北,不蹭下热度可对不起它.见过手画的佩奇,见过用代码画的吗? 没有?那就来看我大显身手. 用python的turtle库来画小猪佩奇. 有人问:turtle难不难? 答曰:不难,就那几个方法,跟入新手村的任务一样简单.难得是要有耐心跟一定的画画功底. 话不多说,直接上我苦苦搜寻(copy)而来的代码+注释版 温馨提示:您苦苦思念的佩奇猪在文末等你哦! # coding:utf-8 import turtle as t t.pensize(4) # 设置画笔的大小 t.c

  • Python画图小案例之多啦A梦叮当猫超详细注释

    一步步教你怎么用Python画多啦A梦叮当猫,进一步熟悉Python的基础画图操作. 分析:叮当猫由头.脸.眼.眼珠.鼻子.嘴.胡子.项带.铃当.身子.围嘴.手臂.手.脚组成. 其中:头.脸.眼.眼珠.鼻子.嘴.胡子组成一个部件:其余元件组成一个部件.废话不多说,上代码. 希望您给个关注给个赞,也算对我们的支持了. import math import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWi

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

    目录 1.哆啦A梦 2.小猪佩奇 3.Python代码实现(哆啦A梦) 4.Python代码实现(小猪佩奇 ) 1.哆啦A梦 “只要把愿望系在竹竿上请求月亮女神,心愿便能达成”.我超喜欢这句话. 哆啦A梦的创造要追溯到1969年的某个截稿日,作者藤子·F·不二雄的家里突然闯进了一只小猫,虽然很快就要截稿了,但作者还是和小猫玩了起来,还替小猫挠虱子,而这一挠就是几个小时.等作者发现时间不够用的时候,已经来不及完成稿子.这时作者像热锅上的蚂蚁走来走去,突然踢到了女儿的不倒翁玩具,于是作者灵光一现,把

  • 使用Python的Turtle绘制哆啦A梦实例

    这是我几年前为了练习python的turtle库而画的,今天翻出了代码,分享给大家. 这是我初学python时画的,当时还没有面向对象的概念,也没有采取类方法之类,纯原始手工,供大家参考. 若有兴趣可以自行优化简洁代码,有时间我也会重新写一遍. 画出来的效果如下图: 代码如下: # * -- utf-8 -- * # Author: Tang import turtle as t t.speed(10) t.pensize(8) t.hideturtle() t.screensize(500,

  • Python利用Turtle绘制虎年图像

    目录 导语 一.代码展示 二.效果展示 导语 2022年是农历壬寅虎年,在自然界中,虎有“百兽之王”之称 它的王者之风与勇猛,被作为威仪和权势的象征,千百年来,人们崇虎.刻虎.画虎.剪虎……形成了极具特色的中国虎文化,而今天给大家用Turtle绘制虎年图像,带给大家虎年的祝福! 虎年送头虎,全家乐悠悠,虎蹄为你开财路,虎尾为你拂忧愁. 虎耳为你撞鸿运,虎背为你驮康寿,让这头虎伴你左右,你不虎也虎 也希望大家在新年里,虎虎生威.虎年大吉 一.代码展示 本文是基于Turtle绘制的小老虎呢!本文的全

  • Python利用Turtle绘制Technoblade的示例代码

    在刚过去不久的6月30日那天,国外一位在YouTube拥有上千万粉丝的我的世界游戏主播Technoblade因癌症与世长辞,年仅23岁,他并没有离开我们,只是用另外一种方式活在了这个世界上. 为了纪念他,特地写了这篇文章,教大家用Turtle绘制出Technoblade,运行效果如下: 代码如下: 首先,用坐标表示每个像素块的颜色,定义一个列表 POS=[ [4,0,(213,164,9)], [6,0,(213,164,9)], [9,0,(213,164,9)], [11,0,(213,16

  • Python利用turtle库绘制彩虹代码示例

    语言:Python IDE:Python.IDE 需求 做出彩虹效果 颜色空间 RGB模型:光的三原色,共同决定色相 HSB/HSV模型:H色彩,S深浅,B饱和度,H决定色相 需要将HSB模型转换为RGB模型 代码示例: #-*- coding:utf-8 –*- from turtle import * def HSB2RGB(hues): hues = hues * 3.59 #100转成359范围 rgb=[0.0,0.0,0.0] i = int(hues/60)%6 f = hues/

  • python 利用turtle库绘制笑脸和哭脸的例子

    我就废话不多说了,直接上代码吧! import turtle turtle.pensize(5) turtle.pencolor("yellow") turtle.fillcolor("red") turtle.penup() turtle.goto(0,-200) turtle.pendown() turtle.circle(200) turtle.penup() turtle.goto(-100,50) turtle.pendown() turtle.begin

  • Python利用Turtle库绘制一个小老虎

    目录 导语 1.定义库以及初始化界面 2.画出左右两只耳朵 3.画出小老虎头部轮廓 4. 画出老虎的两只眼睛 5.画出老虎的鼻子和嘴巴 6.画出小老虎的左右肢体和脚趾 7.在需要的位置写上我们的新年祝福 8. 显示倒数3,2,1 9.显示我们需要的文字 10.设定代码运行入口,调用目标函数 成果展示 导语 哈喽铁汁们好久不见吖~小编已经复工了于是马不停蹄赶来给大家准备新年礼物算开工礼物吧! 海龟来作图 虎年就是要画老虎 2022不用纸和笔~ 今晚画老虎~ 一二三四五 老虎宝宝示意图 虎年怎么能少

  • 详解Python如何利用turtle绘制中国结

    目录 导语 一.中国结 01  平安喜乐 1)效果图 2)附代码 二.中国结 02 心想事成 1)效果图 2)附代码 三.中国结 03 烟火年年 总结 导语 春节是中国特有的传统节日,中国结是中华民族特有的纯粹的文化精髓,富含丰富的文化底蕴,代表着我们对未来,对美好生活的向往和憧憬.新春佳节,小编祝福大家虎年吉祥!万事如意!祝我们的祖国引领世界,勇立潮头!国富民强! 渐渐的,渐渐的,新年很快就要到来.在快过新年时,人们有一个习俗,那就是买“中国结”. 据说,中国结可以让一家人平平安安.幸福,所以

  • Python利用Turtle库绘制一颗樱花树

    后唐李煜曾说道,樱花落尽春将困,秋千架下归时.漏暗斜月迟迟,花在枝.樱花落尽的时候春天也将过去了,秋千架下归去时.天上的斜月姗姗来迟,花还在枝头. 关于python画图相关的,我们一直使用的是turtle来画,用专业的非标准库来做专业的事儿.将需要使用到的内置库或者非标准库全部都导入到当前的代码块中. from time import sleep # 用于控制程序运行时的阻塞停顿 from turtle import * # 绘图相关接口 import random # 生成随机数 设置全局需要

  • Python实战之画哆啦A梦(超详细步骤)

    一.写在前面 本文基于64位windows系统(鼠标右键点击桌面"此电脑"图标--属性可查看电脑系统版本).python3.x(pycharm自动安装的版本, 3.0以上).文中代码内容所使用的工具是pycharm-community-2020.1,实践中如有碰到问题,可留言提问. 前阵子有看到zh上有大神画了这个哆啦A梦的大头贴,自己也来试了一下,很简单,但长篇整段的代码对刚刚学会海龟绘图语法的初学者来说还是有一定难度,所以来做一个拆解版详细步骤讲解实现. 二.效果图 言归正传,先上

随机推荐