教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!

一、哆啦A梦

教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!

 

 由于代码过长,这里仅显示部分代码:

from turtle import *
import turtle as t
from random import *


#五轨迹跳跃
def my_goto(x,y):
    penup()
    goto(x,y)
    pendown()

def eyes():
    fillcolor('#ffffff')
    begin_fill()

    tracer(False)
    a = 2.5
    for i in range(120):
        if 0<= i<30 or 60 <= i <90:
            a -= 0.05
            lt(3)
            fd(a)
        else:
            a += 0.05
            lt(3)
            fd(a)
    tracer(True)
    end_fill()


#胡须
def beard():
    my_goto(-32,135)
    seth(165)
    fd(60)

    my_goto(-32,125)
    seth(180)
    fd(60)

    my_goto(-32,115)
    seth(193)
    fd(60)

    my_goto(37,135)
    seth(15)
    fd(60)

    my_goto(37,125)
    seth(0)
    fd(60)

    my_goto(37,115)
    seth(-13)
    fd(60)


#嘴巴
def mouth():
    my_goto(5,148)
    seth(270)
    fd(100)
    seth(0)
    circle(120,50)
    seth(230)
    circle(-120,100)

 


 

二、海绵宝宝

教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!

 

 部分代码如下:

from turtle import *

def go_to(x, y):
    penup()
    goto(x, y)
    pendown()

def help_do():
    go_to(-400, 0)
    forward(800)
    go_to(-400, 100)
    forward(800)
    go_to(-400,200)
    forward(800)
    go_to(-400, -100)
    forward(800)
    go_to(-400, -200)
    forward(800)
    left(90)
    go_to(0,-300)
    forward(600)
    go_to(100, -300)
    forward(600)
    go_to(-100, -300)
    forward(600)
    go_to(-200, -300)
    forward(600)
    go_to(200, -300)
    forward(600)

def head():
    go_to(-200, 180)
    fillcolor('yellow')
    begin_fill()
    seth(-30)
    for _ in range(6):
        circle(36, 60)
        circle(-36, 60)
    seth(-125)
    for _ in range(5):
        circle(40,60)
        circle(-40,60)
    seth(-210)
    for _ in range(4):
        circle(45,60)
        circle(-45,60)
    seth(65)
    for _ in range(5):
        circle(40,60)
        circle(-40,60)
    end_fill()

 


 

三、皮卡丘

教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!

 

部分代码如下:

import turtle


def getPosition(x, y):
    turtle.setx(x)
    turtle.sety(y)
    print(x, y)


class Pikachu:

    def __init__(self):
        self.t = turtle.Turtle()
        t = self.t
        t.pensize(3)
        t.speed(9)
        t.ondrag(getPosition)

    def noTrace_goto(self, x, y):
        self.t.penup()
        self.t.goto(x, y)
        self.t.pendown()

    def leftEye(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t
        t.seth(0)
        t.fillcolor('#333333')
        t.begin_fill()
        t.circle(22)
        t.end_fill()

        self.noTrace_goto(x, y + 10)
        t.fillcolor('#000000')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

        self.noTrace_goto(x + 6, y + 22)
        t.fillcolor('#ffffff')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

    def rightEye(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t
        t.seth(0)
        t.fillcolor('#333333')
        t.begin_fill()
        t.circle(22)
        t.end_fill()

        self.noTrace_goto(x, y + 10)
        t.fillcolor('#000000')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

        self.noTrace_goto(x - 6, y + 22)
        t.fillcolor('#ffffff')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

 


 

四、史迪仔

教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!

 

部分代码如下:

from turtle import *

setup(650,650)
penup()
pensize(5)
speed(1000)
pencolor("#065693")
seth(180)
fd(140)
seth(-90)
fd(50)
pendown()      #起点
fillcolor("#0079C6")
begin_fill()
seth(170)
circle(-40,100)
seth(180)
fd(50)
seth(180)
circle(-10,46)
seth(130)
circle(-300,40)#耳朵外廓大圆
circle(-100,45)
right(10)
circle(-50,30)
right(10)
circle(-30,30)
left(1)
fd(2)
right(1)
fd(3)
right(4)
fd(3)
right(3)
fd(5)
right(4)
fd(6)
right(4)
fd(10)
right(4)
fd(10)
right(3)
fd(15)
right(2)
fd(20)
right(2)
fd(20)
right(4)
fd(20)
right(3)
fd(30)
right(1)
fd(40)
right(1)
fd(60)
seth(-115)
fd(5)    #脸左侧开始逆时针
circle(200,30)
end_fill()
begin_fill()
left(8)
fd(20)
left(10)
fd(20)
left(14)
circle(100,30)
left(10)
circle(150,20)
right(2)
fd(55)
left(5)
fd(40)
left(3)
fd(25)
right(3)
circle(150,20)
left(7)
circle(100,30)

 


 

五、完整源码下载

关注我的原创公众号【小鸿爱摸鱼】,回复【可爱皮卡丘】、【哆啦A梦】、【史迪仔】、【海绵宝宝】关键词获取对应的源码

 


 

六、作者Info

Author:南柯树下,Goal:让编程更有趣!

原创微信公众号:『小鸿爱摸鱼』,专注于算法、爬虫,网站,游戏开发,数据分析、自然语言处理,AI等,期待你的关注,让我们一起成长、一起Coding!

版权声明:本文禁止抄袭、转载 ,侵权必究!

 

——  ——  ——  ——  —  END  ——  ——  ——  ——  ———— 

         欢迎扫码关注我的公众号

          小鸿爱摸鱼

       教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!

原文链接:https://www.cnblogs.com/makerchen/p/17331094.html

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔! - Python技术站

(0)
上一篇 2023年4月19日
下一篇 2023年4月19日

相关文章

  • 利用Python中的内置open函数读取二进制文件

    读取二进制文件可以使用Python内置的open函数,通过指定读取模式’rb’,来读取文件的二进制数据。 下面是利用Python中的内置open函数读取二进制文件的完整攻略: 1. 打开二进制文件 使用open函数打开二进制文件,可以指定打开模式为’rb’,代码示例: with open(‘test.bin’, ‘rb’) as f: # f为文件对象,可以…

    python 2023年6月2日
    00
  • python实现网站的模拟登录

    Python实现网站的模拟登录是一种常见的自动化测试方法,可以帮助我们更好地测试网站的功能和稳定性。本文将介绍如何使用Python实现网站的模拟登录,并提供两个示例。 1. 使用requests库实现模拟登录 我们可以使用requests库实现模拟登录。以下是一个示例,演示如何使用requests库实现模拟登录: import requests login_…

    python 2023年5月15日
    00
  • python处理excel文件之xlsxwriter 模块

    Python 处理 Excel 文件之 XlsxWriter 模块 简介 XlsxWriter 是一个使用纯 Python 编写的强大的 Excel 写入库。通过它,我们可以创建和修改 Excel 文档,支持多种自定义样式,如单元格格式、字体、颜色、边框等等。XlsxWriter 还支持创建图表、图表系列、数据有效性等。 安装 通过 pip 可以很容易地安装…

    python 2023年6月3日
    00
  • Python使用openpyxl读写excel文件的方法

    以下是关于“Python使用openpyxl读写excel文件的方法”的完整实例教程。 1. 安装openpyxl库 在使用openpyxl读写excel文件前,需要先安装openpyxl库。可以通过在命令行中输入以下命令安装: pip install openpyxl 2. 编写代码 2.1 读取excel文件 以下代码是读取excel文件的示例: imp…

    python 2023年5月13日
    00
  • 详解Python函数中的几种参数

    我会用 markdown 格式撰写完整攻略,内容如下: 详解 Python 函数中的几种参数 在 Python 函数中,参数是用于传递值给函数的占位符。在这篇文章中,我们将详细阐述 Python 函数中的几种参数,并举例说明。 位置参数 位置参数是指那些按照其顺序被输入到函数中的参数。也就是说,位置参数的位置是很重要的。比如,下面这个例子中的函数 add 接…

    python 2023年5月13日
    00
  • python 实现两个字符串乘法小练习

    这里我们就来详细讲解一下Python实现两个字符串乘法的小练习,包含以下内容: 题目介绍 思路分析 详细代码实现 示例说明 1.题目介绍 这是一道比较基础的字符串乘法小练习,给定两个只包含数字的字符串num1和num2,求它们的乘积,返回一个字符串表示。 例如: 输入: num1 = “2”, num2 = “3”,输出: “6” 输入: num1 = “1…

    python 2023年6月5日
    00
  • 在Python中操作时间之tzset()方法的使用教程

    下面我将详细讲解在Python中操作时间之tzset()方法的使用教程。 1. 什么是tzset()方法? tzset()方法是Python中time模块提供的一个函数,用于设置时区信息。该方法可以加载系统配置文件中的时区信息,或者手动指定时区信息。通过使用该方法,可以让Python程序正确地处理不同时区的时间,进行时区转换等操作。 2. 如何使用tzset…

    python 2023年6月2日
    00
  • Python实现图像和办公文档处理的方法和技巧

    Python实现图像和办公文档处理的方法和技巧 本文将介绍Python实现图像和办公文档处理的方法和技巧,包括常用的库、基本操作和示例说明。 常用的库 在Python中,实现图像和办公文档处理的重要库有Pillow、OpenCV、PyPDF2和python-docx等。其中,Pillow和OpenCV用于图像处理,而PyPDF2和python-docx用于办…

    python 2023年5月18日
    00
合作推广
合作推广
分享本页
返回顶部