python画皮卡丘全身立体_超酷!用 Python 教你绘制皮卡丘和哆啦A梦

本文介绍了如何使用Python的turtle库来绘制皮卡丘和哆啦A梦的全身立体图像。文章通过详细代码展示了绘制过程,包括基本的turtle命令使用,并解释了关键函数和几何构造思路。读者可以通过运行代码来实践并理解turtle库的绘图技巧。
摘要由CSDN通过智能技术生成

本文利用 Python 绘制两个卡通角色,并带大家熟悉一下绘图程序包 turtle 的一些用法,先看一下 最终皮卡丘的绘制效果录制_2020_08_01_22_15_39_710.gif

在使用之前请确保 turtle 已经安装成功,第一次安装 turtle 时,用的是 pip 安装包,但总会出现下面的错误,

经查阅资料找到了一种可行的解决方法:

except ValueError, ve:

改为

except (ValueError, ve):3, 使用 pip 命令对本地下载文件进行安装

pip install C:\Users\XXX\Desktop\turtle-0.0.2

2, turtle 命令介绍

turtle 绘图时有个特点,代码行数看起来比较大,但用到的也就是命令操作,来回使用;这里我提前把 turtle 几个常用的命令罗列出来,并在旁边简单介绍一下其用法,方便大家的学习:ble data-draft-node="block" data-draft-type="table" data-size="normal" data-row-style="normal">

Func(函数)Para type(参数类型)Desc(描述)

Func(函数)Para type(参数类型)Desc(描述)

Func(函数)Para type(参数类型)Desc(描述)

Func(函数)Para type(参数类型)Desc(描述)

Func(函数)Para type(参数类型)Desc(描述)

Func(函数)Para type(参数类型)Desc(描述)

Func(函数)Para type(参数类型)Desc(描述)

Func(函数)Para type(参数类型)Desc(描述)

注 : func 中换行表示或的意思,每种函数名有它的缩写,所以存在函数 有2-3 种 不同写法,但函数功能是一样的, - 表示无参数;

3,绘制皮卡丘

代码部分

'''

绘制皮卡丘

'''

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 onTrace_goto(self,x,y):

self.t.penup()

self.t.goto(x,y)

self.t.pendown()

def leftEye(self,x,y):

self.onTrace_goto(x,y)

t = self.t

t.seth(0)

t.fillcolor('#333333')

t.begin_fill()

t.circle(22)

t.end_fill()

self.onTrace_goto(x,y+10)

t.fillcolor('#000000')

t.begin_fill()

t.circle(10)

t.end_fill()

self.onTrace_goto(x+6,y+22)

t.fillcolor('#ffffff')

t.begin_fill()

t.circle(10)

t.end_fill()

def rightEye(self,x,y):

self.onTrace_goto(x,y)

t = self.t

t.seth(0)

t.fillcolor('#333333')

t.begin_fill()

t.circle(22)

t.end_fill()

self.onTrace_goto(x,y+10)

t.fillcolor('#000000')

t.begin_fill()

t.circle(10)

t.end_fill()

self.onTrace_goto(x-6,y+22)

t.fillcolor('#ffffff')

t.begin_fill()

t.circle(10)

t.end_fill()

def mouth(self,x,y):

self.onTrace_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.onTrace_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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值