Python画皮卡丘

博主分享了使用Python创作生动有趣的皮卡丘过程,耗时三天完成。

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

 这只皮卡丘生动有趣,十分可爱,我用了三天时间把它完成。

代码:

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()
        # 下嘴唇
        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())

        # 上嘴唇

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

        t.circle(-50, 40)
        t.seth(233)
 
Python代码是指使用Python语言编写的一个程序,可以在控制台或者图形界面上显示出皮的图像。这个程序通常使用Python的图形库来实现,比如Tkinter或者Pygame。 以下是一个简单的Python代码示例: ```python import turtle # 设置画布和画笔 screen = turtle.Screen() screen.bgcolor("yellow") pen = turtle.Turtle() # 绘制皮的头部 pen.penup() pen.goto(-50, 0) pen.pendown() pen.begin_fill() pen.color("black") pen.circle(100) pen.end_fill() # 绘制皮的眼睛 pen.penup() pen.goto(-30, 60) pen.pendown() pen.begin_fill() pen.color("white") pen.circle(20) pen.end_fill() pen.penup() pen.goto(-70, 60) pen.pendown() pen.begin_fill() pen.color("white") pen.circle(20) pen.end_fill() # 绘制皮的眼珠 pen.penup() pen.goto(-40, 80) pen.pendown() pen.begin_fill() pen.color("black") pen.circle(10) pen.end_fill() pen.penup() pen.goto(-80, 80) pen.pendown() pen.begin_fill() pen.color("black") pen.circle(10) pen.end_fill() # 绘制皮的嘴巴 pen.penup() pen.goto(-60, 20) pen.pendown() pen.width(5) pen.color("black") pen.goto(-40, 0) pen.goto(-20, 20) # 绘制皮的脸颊 pen.penup() pen.goto(-70, -20) pen.pendown() pen.begin_fill() pen.color("red") pen.circle(15) pen.end_fill() pen.penup() pen.goto(-30, -20) pen.pendown() pen.begin_fill() pen.color("red") pen.circle(15) pen.end_fill() # 隐藏画笔 pen.hideturtle() # 关闭画布 turtle.done() ``` 这段代码使用了turtle库来绘制皮的图像。通过设置画布和画笔,然后使用一系列的绘图命令来绘制出皮的头部、眼睛、嘴巴和脸颊等特征。
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值