iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >用python画一只帅气的皮卡丘
  • 796
分享到

用python画一只帅气的皮卡丘

2024-04-02 19:04:59 796人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

没错,全网最帅的比卡丘在我这~~~ 为了访问 python 库,您需要将它导入到您的 Python 环境中,使用以下命令将其导入 turtle到您的 Python 脚本中。 im

惊呆了!python画出全网最帅比卡丘_Python

没错,全网最帅的比卡丘在我这~~~

惊呆了!python画出全网最帅比卡丘_ide_02

为了访问 python 库,您需要将它导入到您的 Python 环境中,使用以下命令将其导入 turtle到您的 Python 脚本中。

import turtle

首先,让我们创建一个 Screen 实例。

wn = turtle.Screen()

现在,创建一个 Turtle 实例。

self.t = turtle.Turtle()

让我们将速度设置为 3 使用 speed 方法,这意味着皮卡丘不会只是出现在屏幕上,绘图也会有一些动画。如果您想更改背景颜色,可以使用该 bGColor 方法,默​​认为白色。您可以使用pensize 方法调整笔的粗细 ,它会稍微加粗。ondrag 拖动 Turtle 将在屏幕上移动它,从而产生手绘(如果笔已放下)。

t.pensize(3)
t.speed(9)
t.ondrag(getPosition)

现在让我们看看这个程序中使用的一些常用方法:

Turtle(): 用于创建并返回一个新的海龟对象。

forward(value): 相对于指定的值,海龟向前移动。

向后(值): 相对于指定的值,海龟向后移动。

right(angle): 乌龟顺时针转动。

left(angle): 海龟逆时针旋转。

penup(): 捡起乌龟笔。

pendown(): 乌龟笔放下。

up(): 与 penup() 相同。

down(): 与 pendown() 相同。

color(颜色名称): Turtle 笔的颜色发生变化。

fillcolor(颜色名称): 用于填充特定形状的颜色已更改。

标题(): 返回当前标题。

position(): 返回当前位置。

Goto(x, y): 将海龟的位置移动到坐标 x, y。

end_fill(): 关闭多边形后填充当前填充颜色。

begin_fill(): 记住填充多边形的起点。

dot(): 点留在当前位置。

stamp(): 海龟形状的印象留在当前位置。

Shape(): 应该是 – ‘turtle’, ‘classic’, ‘arrow’ 或 ‘circle’。

上代码:

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()

    def mouth(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t

        t.fillcolor('#88141D')
        t.begin_fill()

        # Lower Lip
        l1 = []
        l2 = []
        t.seth(190)
        a = 0.7
        for i in range(28):
            a += 0.1
            t.right(3)
            t.fd(a)
            l1.append(t.position())

        self.noTrace_goto(x, y)

        t.seth(10)
        a = 0.7
        for i in range(28):
            a += 0.1
            t.left(3)
            t.fd(a)
            l2.append(t.position())

        # Upper Lip
        t.seth(10)
        t.circle(50, 15)
        t.left(180)
        t.circle(-50, 15)

        t.circle(-50, 40)
        t.seth(233)
        t.circle(-50, 55)
        t.left(180)
        t.circle(50, 12.1)
        t.end_fill()

        # Tongue
        self.noTrace_goto(17, 54)
        t.fillcolor('#DD716F')
        t.begin_fill()
        t.seth(145)
        t.circle(40, 86)
        t.penup()
        for pos in reversed(l1[:20]):
            t.goto(pos[0], pos[1] + 1.5)
        for pos in l2[:20]:
            t.goto(pos[0], pos[1] + 1.5)
        t.pendown()
        t.end_fill()

        # Nose
        self.noTrace_goto(-17, 94)
        t.seth(8)
        t.fd(4)
        t.back(8)

    # Red Cheeks
    def leftCheek(self, x, y):
        turtle.tracer(False)
        t = self.t
        self.noTrace_goto(x, y)
        t.seth(300)
        t.fillcolor('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                t.lt(3)
                t.fd(a)
            else:
                a += 0.05
                t.lt(3)
                t.fd(a)
        t.end_fill()
        turtle.tracer(True)

    def rightCheek(self, x, y):
        t = self.t
        turtle.tracer(False)
        self.noTrace_goto(x, y)
        t.seth(60)
        t.fillcolor('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                t.lt(3)
                t.fd(a)
            else:
                a += 0.05
                t.lt(3)
                t.fd(a)
        t.end_fill()
        turtle.tracer(True)

    def colorLeftEar(self, x, y):
        t = self.t
        self.noTrace_goto(x, y)
        t.fillcolor('#000000')
        t.begin_fill()
        t.seth(330)
        t.circle(100, 35)
        t.seth(219)
        t.circle(-300, 19)
        t.seth(110)
        t.circle(-30, 50)
        t.circle(-300, 10)
        t.end_fill()

    def colorRightEar(self, x, y):
        t = self.t
        self.noTrace_goto(x, y)
        t.fillcolor('#000000')
        t.begin_fill()
        t.seth(300)
        t.circle(-100, 30)
        t.seth(35)
        t.circle(300, 15)
        t.circle(30, 50)
        t.seth(190)
        t.circle(300, 17)
        t.end_fill()

    def body(self):
        t = self.t

        t.fillcolor('#F6D02F')
        t.begin_fill()
        # Right face contour
        t.penup()
        t.circle(130, 40)
        t.pendown()
        t.circle(100, 105)
        t.left(180)
        t.circle(-100, 5)

        # Right ear
        t.seth(20)
        t.circle(300, 30)
        t.circle(30, 50)
        t.seth(190)
        t.circle(300, 36)

        # Upper profile
        t.seth(150)
        t.circle(150, 70)

        # Left ear
        t.seth(200)
        t.circle(300, 40)
        t.circle(30, 50)
        t.seth(20)
        t.circle(300, 35)
        #print(t.pos())

        # Left face contour
        t.seth(240)
        t.circle(105, 95)
        t.left(180)
        t.circle(-105, 5)

        # Left hand
        t.seth(210)
        t.circle(500, 18)
        t.seth(200)
        t.fd(10)
        t.seth(280)
        t.fd(7)
        t.seth(210)
        t.fd(10)
        t.seth(300)
        t.circle(10, 80)
        t.seth(220)
        t.fd(10)
        t.seth(300)
        t.circle(10, 80)
        t.seth(240)
        t.fd(12)
        t.seth(0)
        t.fd(13)
        t.seth(240)
        t.circle(10, 70)
        t.seth(10)
        t.circle(10, 70)
        t.seth(10)
        t.circle(300, 18)

        t.seth(75)
        t.circle(500, 8)
        t.left(180)
        t.circle(-500, 15)
        t.seth(250)
        t.circle(100, 65)

        # Left foot
        t.seth(320)
        t.circle(100, 5)
        t.left(180)
        t.circle(-100, 5)
        t.seth(220)
        t.circle(200, 20)
        t.circle(20, 70)

        t.seth(60)
        t.circle(-100, 20)
        t.left(180)
        t.circle(100, 20)
        t.seth(300)
        t.circle(10, 70)

        t.seth(60)
        t.circle(-100, 20)
        t.left(180)
        t.circle(100, 20)
        t.seth(10)
        t.circle(100, 60)

        # Horizontal
        t.seth(180)
        t.circle(-100, 10)
        t.left(180)
        t.circle(100, 10)
        t.seth(5)
        t.circle(100, 10)
        t.circle(-100, 40)
        t.circle(100, 35)
        t.left(180)
        t.circle(-100, 10)

        # Right foot
        t.seth(290)
        t.circle(100, 55)
        t.circle(10, 50)

        t.seth(120)
        t.circle(100, 20)
        t.left(180)
        t.circle(-100, 20)

        t.seth(0)
        t.circle(10, 50)

        t.seth(110)
        t.circle(100, 20)
        t.left(180)
        t.circle(-100, 20)

        t.seth(30)
        t.circle(20, 50)

        t.seth(100)
        t.circle(100, 40)

        # Right body contour
        t.seth(200)
        t.circle(-100, 5)
        t.left(180)
        t.circle(100, 5)
        t.left(30)
        t.circle(100, 75)
        t.right(15)
        t.circle(-300, 21)
        t.left(180)
        t.circle(300, 3)

        # Right hand
        t.seth(43)
        t.circle(200, 60)

        t.right(10)
        t.fd(10)

        t.circle(5, 160)
        t.seth(90)
        t.circle(5, 160)
        t.seth(90)

        t.fd(10)
        t.seth(90)
        t.circle(5, 180)
        t.fd(10)

        t.left(180)
        t.left(20)
        t.fd(10)
        t.circle(5, 170)
        t.fd(10)
        t.seth(240)
        t.circle(50, 30)

        t.end_fill()
        self.noTrace_goto(130, 125)
        t.seth(-20)
        t.fd(5)
        t.circle(-5, 160)
        t.fd(5)

        # Fingers
        self.noTrace_goto(166, 130)
        t.seth(-90)
        t.fd(3)
        t.circle(-4, 180)
        t.fd(3)
        t.seth(-90)
        t.fd(3)
        t.circle(-4, 180)
        t.fd(3)

        # Tail
        self.noTrace_goto(168, 134)
        t.fillcolor('#F6D02F')
        t.begin_fill()
        t.seth(40)
        t.fd(200)
        t.seth(-80)
        t.fd(150)
        t.seth(210)
        t.fd(150)
        t.left(90)
        t.fd(100)
        t.right(95)
        t.fd(100)
        t.left(110)
        t.fd(70)
        t.right(110)
        t.fd(80)
        t.left(110)
        t.fd(30)
        t.right(110)
        t.fd(32)

        t.right(106)
        t.circle(100, 25)
        t.right(15)
        t.circle(-300, 2)
        #print(t.pos())
        t.seth(30)
        t.fd(40)
        t.left(100)
        t.fd(70)
        t.right(100)
        t.fd(80)
        t.left(100)
        t.fd(46)
        t.seth(66)
        t.circle(200, 38)
        t.right(10)
        t.fd(10)
        t.end_fill()

        # Tail Pattern
        t.fillcolor('#923E24')
        self.noTrace_goto(126.82, -156.84)
        t.begin_fill()

        t.seth(30)
        t.fd(40)
        t.left(100)
        t.fd(40)
        t.pencolor('#923e24')
        t.seth(-30)
        t.fd(30)
        t.left(140)
        t.fd(20)
        t.right(150)
        t.fd(20)
        t.left(150)
        t.fd(20)
        t.right(150)
        t.fd(20)
        t.left(130)
        t.fd(18)
        t.pencolor('#000000')
        t.seth(-45)
        t.fd(67)
        t.right(110)
        t.fd(80)
        t.left(110)
        t.fd(30)
        t.right(110)
        t.fd(32)
        t.right(106)
        t.circle(100, 25)
        t.right(15)
        t.circle(-300, 2)
        t.end_fill()

        # Hat, Eye, Mouth, Cheek
        self.cap(-134.07, 147.81)
        self.mouth(-5, 25)
        self.leftCheek(-126, 32)
        self.rightCheek(107, 63)
        self.colorLeftEar(-250, 100)
        self.colorRightEar(140, 270)
        self.leftEye(-85, 90)
        self.rightEye(50, 110)
        t.hideturtle()

    def cap(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t
        t.fillcolor('#CD0000')
        t.begin_fill()
        t.seth(200)
        t.circle(400, 7)
        t.left(180)
        t.circle(-400, 30)
        t.circle(30, 60)
        t.fd(50)
        t.circle(30, 45)
        t.fd(60)
        t.left(5)
        t.circle(30, 70)
        t.right(20)
        t.circle(200, 70)
        t.circle(30, 60)
        t.fd(70)
        #print(t.pos())
        t.right(35)
        t.fd(50)
        t.circle(8, 100)
        t.end_fill()
        self.noTrace_goto(-168.47, 185.52)
        t.seth(36)
        t.circle(-270, 54)
        t.left(180)
        t.circle(270, 27)
        t.circle(-80, 98)

        t.fillcolor('#444444')
        t.begin_fill()
        t.left(180)
        t.circle(80, 197)
        t.left(58)
        t.circle(200, 45)
        t.end_fill()

        self.noTrace_goto(-58, 270)
        t.pencolor('#228B22')
        t.dot(35)

        self.noTrace_goto(-30, 280)
        t.fillcolor('#228B22')
        t.begin_fill()
        t.seth(100)
        t.circle(30, 180)
        t.seth(190)
        t.fd(15)
        t.seth(100)
        t.circle(-45, 180)
        t.right(90)
        t.fd(15)
        t.end_fill()
        t.pencolor('#000000')

    def start(self):
        self.body()


def main():
    print('Painting the Pikachu... ')
    wn = turtle.Screen()
    wn.setup(width=600, height=800)
    pikachu = Pikachu()
    pikachu.start()
    turtle.mainloop()


if __name__ == '__main__':
    main()

到此这篇关于用python画一只帅气的皮卡丘的文章就介绍到这了,更多相关python皮卡丘内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: 用python画一只帅气的皮卡丘

本文链接: https://www.lsjlt.com/news/162425.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 用python画一只帅气的皮卡丘
    没错,全网最帅的比卡丘在我这~~~ 为了访问 Python 库,您需要将它导入到您的 Python 环境中,使用以下命令将其导入 turtle到您的 Python 脚本中。 im...
    99+
    2024-04-02
  • 怎么用python画一只帅气的皮卡丘
    今天小编给大家分享一下怎么用python画一只帅气的皮卡丘的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。为了访问 Pytho...
    99+
    2023-06-26
  • 怎么使用python画皮卡丘
    这篇文章主要介绍怎么使用python画皮卡丘,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!python的数据类型有哪些python的数据类型:1. 数字类型,包括int(整型)、long(长整型)和float(浮点型...
    99+
    2023-06-14
  • python的皮卡丘如何写代码,用python皮卡丘的代码
    大家好,小编为大家解答python的皮卡丘如何写代码的问题。很多人还不知道python皮卡丘字符打印代码,现在让我们一起来看看吧! 一、哆啦A梦 由于代码过长,这里仅显示部分代码: from turtle import \...
    99+
    2023-10-12
    python
  • 用Python制作一个可以聊天的皮卡丘版桌面宠物
    目录导语开发工具原理简介步骤实现导语 前段时间有小伙伴留言说想让我带大家写写桌面小挂件,今天就满足一下留过类似言的小伙伴的请求呗~不过感觉写桌面的挂历啥的没意思,就简单带大家做一只桌...
    99+
    2024-04-02
  • 怎么用Python制作一个可以聊天的皮卡丘版桌面宠物
    这篇文章主要介绍了怎么用Python制作一个可以聊天的皮卡丘版桌面宠物,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。开发工具Python版本:3.6.4相关模块:PyQt5模...
    99+
    2023-06-29
  • python怎么实现利用声音控制皮卡丘不断前进游戏
    这篇文章主要介绍“python怎么实现利用声音控制皮卡丘不断前进游戏”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“python怎么实现利用声音控制皮卡丘不断前进游戏”文章能帮助大家解决问题。开发工具...
    99+
    2023-06-27
  • ikun必学!python 画一个简单的只因
    大家好呀,我是阿潘。 现在有很多虚假的ikun 看似维护鸡哥,实则想吃鸡哥下的蛋 每次看到这种网络攻击,鼻子一酸,泪流不止。这个世界太不友善了,真的不知道面对那么多无端的谩骂他是怎么熬过来的。作为一位ikun真的麻木了,心累了。黄昏见...
    99+
    2023-09-07
    python bug 代码规范 人工智能 debug
  • 其实python真的很简单!今天就教会你,用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!附上源码,不信你还学不会!
    一、哆啦A梦 由于代码过长,这里仅显示部分代码: from turtle import \*import turtle as tfrom random import \*#五轨迹跳跃def my\_...
    99+
    2023-10-20
    python 开发语言 pycharm
  • 怎么用纯CSS实现一只移动的小白兔动画效果
    这篇文章主要介绍怎么用纯CSS实现一只移动的小白兔动画效果,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!   代码解读   定义dom,页面中包含2个元素,分别代表兔子和云朵: ...
    99+
    2024-04-02
  • 利用Python制作一个简单的天气播报系统
    目录前言工具天气数据来源代码实现总结前言 大家好,我是辣条 相信大家都能感觉到最近天气的多变,好几次出门半路天气转变。辣条也深受其扰,直接给我整感冒,就差被隔离起来了,既然天气我没法...
    99+
    2024-04-02
  • 用python的turtle库画一个小猪佩奇
             小猪佩奇是一个可爱的小猪。她已经四岁了,与她的妈妈,爸爸,和弟弟乔治生活在一起。佩奇最喜欢做的事情是玩游戏,打扮的漂亮,度假,以及在小泥坑里快乐的跳上跳下和与小羊苏西(她最好的朋友)乔治(她的弟弟)一起玩儿,拜访她的姥姥(...
    99+
    2023-10-19
    python 小猪佩奇
  • 使用Python画一个可爱的冰墩墩
    利用Python绘制可爱的冰墩墩 冰墩墩,作为北京冬奥会的吉祥物,可爱的形象深受广大人们的喜爱。在这篇文章中,我们将使用Python语言来绘制一个可爱的冰墩墩的图像。首先,我们需要了解Python的绘图库matplotlib和n...
    99+
    2024-01-13
    Python绘图 可爱形象设计 冰墩墩绘画
  • 怎么利用Python制作一个简单的天气播报系统
    本篇内容介绍了“怎么利用Python制作一个简单的天气播报系统”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!工具python3.7pycha...
    99+
    2023-06-30
  • python 中的 cupy 库中的 amax 和 max 函数在使用只有一列或只有一行的矩阵时是否会出错?
    问题内容 我尝试使用 cupy 进行 gpu 加速来实现用于机器学习和图像分类的 softmax 激活函数。我观察到,对于形状为 nx1 或 1xn 的数组,cupys max 函数会...
    99+
    2024-02-06
  • 如何用python代码画一朵好看又有趣的小花花
    本篇文章给大家分享的是有关如何用python代码画一朵好看又有趣的小花花,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。今天为大家介绍一个简单又有趣的小案例,图形绘画,自动帮你绘...
    99+
    2023-06-02
  • 如何用python的小海龟Turtle画一朵好看又有趣的小花
    本篇文章给大家分享的是有关如何用python的小海龟Turtle画一朵好看又有趣的小花,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。      1...
    99+
    2023-06-02
  • (Python)使用清华源进行python的pip安装(任何环境,不用换源,用时只需加上一行代码
    (Python)使用清华源进行python的pip安装及pip批量安装的方法 一、介绍二、pip安装三、扩展批量安装库 一、介绍 当我们在下载pip时是否因为速度太慢而失去耐心,甚至由...
    99+
    2023-09-03
    python pip
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作