python实现的彩绘皮卡丘

本文展示了如何使用Python的turtle库来实现一个简单的彩绘皮卡丘程序。通过定义不同的函数,如眼睛、嘴巴、脸颊等,实现了皮卡丘的形象绘制。代码中详细地描述了各个部分的坐标定位和形状绘制。

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

以下是代码

# !/usr/bin/env python3

# -*- coding: utf-8 -*-

# @Author: dong

# @Date: 2018-09-24 10:11:47

# @Env: python 3.6

# @Github: https://github.com/PerpetualSmile

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)

t.circle(-50, 55)

t.left(180)

t

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值