1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Python画海绵宝宝 小猪佩奇 皮卡丘

Python画海绵宝宝 小猪佩奇 皮卡丘

时间:2021-03-12 07:47:30

相关推荐

Python画海绵宝宝 小猪佩奇 皮卡丘

文章目录

海绵宝宝小猪佩奇皮卡丘

海绵宝宝

效果图:

学姐的代码:

from turtle import *def go_to(x, y):penup()goto(x, y)pendown()def help_do():go_to(-400, 0)forward(800)go_to(-400, 100)forward(800)go_to(-400,200)forward(800)go_to(-400, -100)forward(800)go_to(-400, -200)forward(800)left(90)go_to(0,-300)forward(600)go_to(100, -300)forward(600)go_to(-100, -300)forward(600)go_to(-200, -300)forward(600)go_to(200, -300)forward(600)def head():go_to(-200, 180)fillcolor('yellow')begin_fill()seth(-30)for _ in range(6):circle(36, 60)circle(-36, 60)seth(-125)for _ in range(5):circle(40,60)circle(-40,60)seth(-210)for _ in range(4):circle(45,60)circle(-45,60)seth(65)for _ in range(5):circle(40,60)circle(-40,60)end_fill()def eye():# 眼白go_to(14, -5)fillcolor('#f0f0f0')begin_fill()circle(65, 360)end_fill()begin_fill()go_to(13,12)seth(98)circle(-65,360)end_fill()#眼球go_to(-10,20)fillcolor('blue')begin_fill()circle(20,360)end_fill()go_to(-22,20)fillcolor('black')begin_fill()circle(7,360)end_fill()go_to(40,15)fillcolor('blue')begin_fill()circle(-20, 360)end_fill()go_to(53,15)fillcolor('black')begin_fill()circle(-7,360)end_fill()#睫毛go_to(-95,65)left(20)forward(40)go_to(-50,87)right(25)forward(32)go_to(0,70)right(25)forward(40)go_to(40, 75)left(35)forward(40)go_to(90, 87)right(18)forward(30)go_to(120, 70)right(25)forward(40)def nose():fillcolor('yellow')go_to(0, -7)begin_fill()right(50)circle(-60, 30)color('yellow')goto(15,-40)end_fill()color('black')go_to(0, -7)seth(-75)forward(30)go_to(30,-7)seth(-105)forward(30)def mouth():go_to(-120, - 60)seth(-45)circle(200, 30)seth(0)forward(100)seth(15)circle(200, 30)def tooth():go_to(-30,-114)seth(-95)fillcolor('white')begin_fill()forward(30)seth(0)forward(40)seth(95)forward(30)go_to(-30,-114)end_fill()go_to(30, -114)seth(-95)fillcolor('white')begin_fill()forward(30)seth(0)forward(40)seth(95)forward(30)go_to(60, -114)end_fill()def hole():go_to(-160,160)# fillcolor('#ffd700')# begin_fill()circle(30, 360)# a=1# for i in range(120):#if 0<=i<30 or 60<=i<90:# a=a+0.2# lt(3)# forward(a)#else:# a=a-0.2# lt(3)# forward(a)# end_fill()def face():eye()nose()mouth()tooth()# hole()def body():go_to(-170,-180)seth(-120)circle(150, 30)seth(0)forward(40)seth(100)forward(35)seth(-80)forward(100)fillcolor('brown')begin_fill()seth(0)forward(300)seth(80)forward(110)seth(-100)forward(65)seth(180)forward(315)go_to(-118,-400)end_fill()go_to(-170,-255)fillcolor('yellow')begin_fill()seth(-75)forward(80)seth(0)forward(17)seth(105)forward(85)end_fill()go_to(200, -170)seth(-60)circle(-150,30)seth(-180)forward(45)begin_fill()seth(0)forward(20)seth(-100)forward(85)seth(180)forward(20)end_fill()def tie():go_to(-50,-225)seth(-40)forward(40)seth(30)forward(52)go_to(30,-225)seth(-30)forward(40)seth(40)forward(45)fillcolor('red')go_to(0, -240)begin_fill()seth(-60)forward(10)seth(0)forward(30)seth(60)forward(15)go_to(30,-225)end_fill()go_to(4,-250)begin_fill()seth(-100)forward(80)seth(0)forward(55)seth(100)forward(80)end_fill()def spongeBob():# help_do()head()face()body()tie()if __name__=='__main__':screensize(800, 600, 'white')pensize(3)speed(10)go_to(0, 0)spongeBob()go_to(-100,240)write('海绵宝宝',font=('BRUSHSCI.TTF', '30', 'bold'))mainloop()

小猪佩奇

效果图:

学姐的代码:

# coding:utf-8import timeimport turtle as tt.pensize(4) # 设置画笔的大小t.colormode(255) # 设置GBK颜色范围为0-255t.color((255,155,192),"pink") # 设置画笔颜色和填充颜色(pink)t.setup(840,500) # 设置主窗口的大小为840*500t.speed(10) # 设置画笔速度为10#鼻子t.pu() # 提笔t.goto(-100,100) # 画笔前往F坐标(-100,100)t.pd() # 下笔t.seth(-30) # 笔的角度为-30°t.begin_fill() # 外形填充的开始标志a=0.4for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.08t.lt(3) #向左转3度t.fd(a) #向前走a的步长else:a=a-0.08t.lt(3)t.fd(a)t.end_fill() # 依据轮廓填充t.pu() # 提笔t.seth(90) # 笔的角度为90度t.fd(25) # 向前移动25t.seth(0) # 转换画笔的角度为0t.fd(10)t.pd()t.pencolor(255,155,192) # 设置画笔颜色t.seth(10)t.begin_fill()t.circle(5) # 画一个半径为5的圆t.color(160,82,45) # 设置画笔和填充颜色t.end_fill()t.pu()t.seth(0)t.fd(20)t.pd()t.pencolor(255,155,192)t.seth(10)t.begin_fill()t.circle(5)t.color(160,82,45)t.end_fill()#头t.color((255,155,192),"pink")t.pu()t.seth(90)t.fd(41)t.seth(0)t.fd(0)t.pd()t.begin_fill()t.seth(180)t.circle(300,-30) # 顺时针画一个半径为300,圆心角为30°的园t.circle(100,-60)t.circle(80,-100)t.circle(150,-20)t.circle(60,-95)t.seth(161)t.circle(-300,15)t.pu()t.goto(-100,100)t.pd()t.seth(-30)a=0.4for i in range(60):if 0<=i<30 or 60<=i<90:a=a+0.08t.lt(3) #向左转3度t.fd(a) #向前走a的步长else:a=a-0.08t.lt(3)t.fd(a)t.end_fill()#耳朵t.color((255,155,192),"pink")t.pu()t.seth(90)t.fd(-7)t.seth(0)t.fd(70)t.pd()t.begin_fill()t.seth(100)t.circle(-50,50)t.circle(-10,120)t.circle(-50,54)t.end_fill()t.pu()t.seth(90)t.fd(-12)t.seth(0)t.fd(30)t.pd()t.begin_fill()t.seth(100)t.circle(-50,50)t.circle(-10,120)t.circle(-50,56)t.end_fill()#眼睛t.color((255,155,192),"white")t.pu()t.seth(90)t.fd(-20)t.seth(0)t.fd(-95)t.pd()t.begin_fill()t.circle(15)t.end_fill()t.color("black")t.pu()t.seth(90)t.fd(12)t.seth(0)t.fd(-3)t.pd()t.begin_fill()t.circle(3)t.end_fill()t.color((255,155,192),"white")t.pu()t.seth(90)t.fd(-25)t.seth(0)t.fd(40)t.pd()t.begin_fill()t.circle(15)t.end_fill()t.color("black")t.pu()t.seth(90)t.fd(12)t.seth(0)t.fd(-3)t.pd()t.begin_fill()t.circle(3)t.end_fill()#腮t.color((255,155,192))t.pu()t.seth(90)t.fd(-95)t.seth(0)t.fd(65)t.pd()t.begin_fill()t.circle(30)t.end_fill()#嘴t.color(239,69,19)t.pu()t.seth(90)t.fd(15)t.seth(0)t.fd(-100)t.pd()t.seth(-80)t.circle(30,40)t.circle(40,80)#身体t.color("red",(255,99,71))t.pu()t.seth(90)t.fd(-20)t.seth(0)t.fd(-78)t.pd()t.begin_fill()t.seth(-130)t.circle(100,10)t.circle(300,30)t.seth(0)t.fd(230)t.seth(90)t.circle(300,30)t.circle(100,3)t.color((255,155,192),(255,100,100))t.seth(-135)t.circle(-80,63)t.circle(-150,24)t.end_fill()#手t.color((255,155,192))t.pu()t.seth(90)t.fd(-40)t.seth(0)t.fd(-27)t.pd()t.seth(-160)t.circle(300,15)t.pu()t.seth(90)t.fd(15)t.seth(0)t.fd(0)t.pd()t.seth(-10)t.circle(-20,90)t.pu()t.seth(90)t.fd(30)t.seth(0)t.fd(237)t.pd()t.seth(-20)t.circle(-300,15)t.pu()t.seth(90)t.fd(20)t.seth(0)t.fd(0)t.pd()t.seth(-170)t.circle(20,90)#脚t.pensize(10)t.color((240,128,128))t.pu()t.seth(90)t.fd(-75)t.seth(0)t.fd(-180)t.pd()t.seth(-90)t.fd(40)t.seth(-180)t.color("black")t.pensize(15)t.fd(20)t.pensize(10)t.color((240,128,128))t.pu()t.seth(90)t.fd(40)t.seth(0)t.fd(90)t.pd()t.seth(-90)t.fd(40)t.seth(-180)t.color("black")t.pensize(15)t.fd(20)#尾巴t.pensize(4)t.color((255,155,192))t.pu()t.seth(90)t.fd(70)t.seth(0)t.fd(95)t.pd()t.seth(0)t.circle(70,20)t.circle(10,330)t.circle(70,30)

皮卡丘

效果图:

杨总的代码:

import turtledef getPosition(x, y):turtle.setx(x)turtle.sety(y)print(x, y)class Pikachu:def __init__(self):self.t = turtle.Turtle()t = self.tt.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.tt.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.tt.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.tt.fillcolor('#88141D')t.begin_fill()# 下嘴唇l1 = []l2 = []t.seth(190)a = 0.7for i in range(28):a += 0.1t.right(3)t.fd(a)l1.append(t.position())self.noTrace_goto(x, y)t.seth(10)a = 0.7for i in range(28):a += 0.1t.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.circle(50, 12.1)t.end_fill()# 舌头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()# 鼻子self.noTrace_goto(-17, 94)t.seth(8)t.fd(4)t.back(8)# 红脸颊def leftCheek(self, x, y):turtle.tracer(False)t = self.tself.noTrace_goto(x, y)t.seth(300)t.fillcolor('#DD4D28')t.begin_fill()a = 2.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a -= 0.05t.lt(3)t.fd(a)else:a += 0.05t.lt(3)t.fd(a)t.end_fill()turtle.tracer(True)def rightCheek(self, x, y):t = self.tturtle.tracer(False)self.noTrace_goto(x, y)t.seth(60)t.fillcolor('#DD4D28')t.begin_fill()a = 2.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a -= 0.05t.lt(3)t.fd(a)else:a += 0.05t.lt(3)t.fd(a)t.end_fill()turtle.tracer(True)def colorLeftEar(self, x, y):t = self.tself.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.tself.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.tt.fillcolor('#F6D02F')t.begin_fill()# 右脸轮廓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)# print(t.pos())# 左脸轮廓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.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)# 左脚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)# 横向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)# 右脚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)# 右侧身体轮廓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)# 右手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)# 手指纹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)# 尾巴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()# 尾巴花纹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()# 帽子、眼睛、嘴巴、脸颊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.tt.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... ')turtle.screensize(800, 600)turtle.title('Pikachu')pikachu = Pikachu()pikachu.start()turtle.mainloop()if __name__ == '__main__':main()

python turtle绘图-案例集锦:/July__July/article/details/99543992

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。