简单代码画⽪卡丘_超酷!⽤Python教你绘制⽪卡丘和哆啦A梦
本⽂利⽤ Python 绘制两个卡通⾓⾊,并带⼤家熟悉⼀下绘图程序包 turtle 的⼀些⽤法,先看⼀下 最终⽪卡丘的绘制效果
在使⽤之前请确保 turtle 已经安装成功,第⼀次安装 turtle 时,⽤的是 pip 安装包,但总会出现下⾯的错误,
经查阅资料到了⼀种可⾏的解决⽅法:
1,从⽹上下载 turtle 程序包,下载链接为:
/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-
0.0.
ValueError,ve ;
2,解压 1 中的压缩包,修改其中的 setup.py 脚本:修改⽅法在40⾏处的 ValueError,ve
except ValueError, ve:
改为
except (ValueError, ve):
3, 使⽤ pip 命令对本地下载⽂件进⾏安装
pip install C:UsersXXXDesktopturtle-0.0.2
2, turtle 命令介绍
turtle 绘图时有个特点,代码⾏数看起来⽐较⼤,但⽤到的也就是命令操作,来回使⽤;这⾥我提前把 turtle ⼏个常⽤的命令罗列出来,并在旁边简单介绍⼀下其⽤法,⽅便⼤家的学习:
Func(函数)Para type(参数类型)Desc(描述)
注 : func 中换⾏表⽰或的意思,每种函数名有它的缩写,所以存在函数 有2-3 种 不同写法,但函数功能是⼀样的, - 表⽰⽆参数;
3,绘制⽪卡丘
录制_2020_08_01_22_15_39_710.gif
代码部分
'''
绘制⽪卡丘
oracle11g默认密码
'''
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) #画笔速度
def onTrace_goto(self,x,y):
<(x,y)
ps切片工具怎么切图保存不了
def leftEye(self,x,y):
t = self.t
t.seth(0)
t.fillcolor('#333333')
t.begin_fill()
t.circle(22)
t.fillcolor('#000000')
t.begin_fill()
t.circle(10)
t.fillcolor('#ffffff')
t.begin_fill()
t.circle(10)
def rightEye(self,x,y):
t = self.t
t.seth(0)
python代码画图案t.fillcolor('#333333')
t.begin_fill()
t.circle(22)
t.begin_fill()
t.circle(10)
t.begin_fill()
t.circle(10)
def mouth(self,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())
t.seth(10)
a = 0.7
for i in range(28):
a +=0.1local可数吗
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)x86架构安卓应用商店
t.circle(50,12.1)
# ⾆头
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]:
<(pos[0],pos[1]+1.5)
<(pos[0],pos[1]+1.5)        t.pendown()
# ⿐⼦
t.seth(8)
t.fd(4)
t.back(8)
# 红脸颊
def leftCheck(self,x,y):
t = self.t
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)
def rightCheck(self,x,y):
t = self.t
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)
def colorLeftEar(self,x,y):
t = self.t
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)
timestamp类型长度def colorRightEar(self,x,y):
t = self.t
t = self.t
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)
def body(self):
t = self.t
t.fillcolor('#F6D02F')        # 右脸轮廓
t.penup()
t.circle(130,40)
t.pendown()
t.circle(100,105)
t.left(180)
t.circle(-100,5)
# 右⽿朵
t.seth(20)
t.circle(300,30)
t.circle(30,50)
t.seth(190)
t.circle(300,36)
# 上轮廓
t.seth(150)
t.circle(150,70)
#左⽿朵
t.seth(200)
t.circle(300,40)
t.circle(30,50)
t.seth(20)
t.circle(300,35)
# 左脸轮廓
t.seth(240)
t.circle(105,95)
t.left(180)
t.circle(-105,5)
#左⼿
t.seth(210)
t.circle(500,18)
t.seth(200)
t.fd(10)
t.seth(280)
t.fd(7)
t.seth(210)
t.seth(300)
t.circle(10,80)
t.seth(220)
t.seth(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)