关注,回复python,获取80G免费python实战文档和视频资料!
摘要:本文由以数据之名分享。左手代码,右手带娃;Running Code,Laughing Baby。今天,让我们跟随着小编的节奏,首先了解下如何用Python代码,勾画出一幅幅生动的动态画面,居家带娃不设限,代码出画动态变。

1.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:贪吃蛇源码# Project Name:RetroSnaker.py# import保留字,引入名为turtle的绘图库# 用 from turtle import* 可以把下面所有的turtle.省略,但可能有程序重名的冲突# import turtle as t 就可以使用t.进行代替import turtle# setup()函数设置窗体大小及位置,只有需要控制窗体的大小和显示位置时才需要使用setup函数# turtle.setup(width,height,startx,starty) 后两位不指定则默认窗体在屏幕正中心turtle.setup(650,350,200,200) #设定窗体,宽度650像素,高度350像素,位置左上角坐标(200,200)#penup抬起画笔,海龟在飞行,不在画布上留下图案turtle.penup()#turtle.forward(d) 别名turtle.fd(d)向前运行#turtle.bk(d)向后运行turtle.fd(-250) #让海龟后退250像素,但由于海龟在飞行,所以不留下痕迹。即海龟由画布上的原点到左侧的位置上。#pendown落下画笔,海龟在爬行;penup与pendown一般成对出现turtle.pendown() #让海龟落下turtle.pensize(25) #设置海龟腰围,设置当前画笔宽度为25像素#RGB小数值turtle.pencolor(0.63,0.13,0.94)#RGB元组类型turtle.pencolor((0.63,0.13,0.94))turtle.pencolor("purple")#颜色字符串#turtle.setheading(angle) 别名turtle.seth(angle) 改变海龟行进方向 ·只改变方向但不行进 ·angle是绝对角度#turtle.left(angle) turtle.right(angle) 海龟分别向左右转 ·angle是海龟旋转的角度turtle.seth(-40) #将海龟的方向指向坐标系中绝对-40的方向#准备启动绘制Python蟒蛇#range(2,5) 打印2,3,4for i in range(4): #打印效果0 1 2 3turtle.circle(40,80) #使用40像素的半径,绘制80°的弧度turtle.circle(-40,80)#turtle.circle(r,angle)以海龟左侧某一点为圆心曲线运行;不给角度默认绘制圆形;半径为负数则圆心在海龟右侧turtle.circle(40,80/2)turtle.fd(40)turtle.circle(16,180)turtle.fd(40*2/3)turtle.done() #程序运行后不会退出,需要手动关闭窗体退出;去掉则自动退出
1.2、运行效果

2.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:国宝熊猫源码# Project Name:Panda.pyimport turtle as tt.title("国宝熊猫")t.shape("classic")t.pensize(3)t.color("black")t.fillcolor("black")t.speed(100)t.hideturtle()#左耳t.penup()t.goto(-105,97)t.setheading(160)t.begin_fill()t.pendown()t.circle(-30,230)t.setheading(180)t.circle(37,90)t.end_fill()#右耳t.penup()t.goto(105,97)t.setheading(20)t.begin_fill()t.pendown()t.circle(30,230)t.setheading(0)t.circle(-37,90)t.end_fill()#头部轮廓t.penup()t.goto(-67,140)t.setheading(30)t.pendown()t.circle(-134,60)t.penup()t.goto(-50,-25)t.setheading(180)t.pendown()t.circle(-100,30)t.circle(-30,90)t.setheading(100)t.circle(-200,20)t.penup()t.goto(50,-25)t.setheading(0)t.pendown()t.circle(100,30)t.circle(30,90)t.setheading(80)t.circle(200,20)#两熊猫眼#左眼t.penup()t.goto(-90,25)t.setheading(-45)t.begin_fill()t.pendown()#椭圆绘制技巧a = 0.2for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.1t.lt(3) #向左转3度t.fd(a) #向前走a的步长else:a=a-0.1t.lt(3)t.fd(a)t.end_fill()t.fillcolor("white")t.penup()t.goto(-53,43)t.setheading(0)t.begin_fill()t.pendown()t.circle(13,360)t.end_fill()t.penup()t.pensize(4)t.goto(-60,57)t.setheading(30)t.pendown()t.circle(-12,60)#右眼t.penup()t.goto(90,25)t.setheading(45)t.pensize(2)t.fillcolor("black")t.begin_fill()t.pendown()#椭圆绘制技巧a = 0.2for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.1t.lt(3) #向左转3度t.fd(a) #向前走a的步长else:a=a-0.1t.lt(3)t.fd(a)t.end_fill()t.fillcolor("white")t.penup()t.goto(53,43)t.setheading(0)t.begin_fill()t.pendown()t.circle(13,360)t.end_fill()t.penup()t.pensize(4)t.goto(60,57)t.setheading(150)t.pendown()t.circle(12,60)#鼻子和嘴吧t.penup()t.goto(-16,20)t.setheading(-90)t.fillcolor("black")t.begin_fill()t.pendown()a = 0.2for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.03t.lt(3)t.fd(a)else:a = a - 0.03t.lt(3)t.fd(a)t.end_fill()t.penup()t.goto(-24,0)t.setheading(-60)t.pendown()t.circle(28,120)#熊肢体#左肢t.penup()t.goto(-65,-24)t.setheading(-140)t.begin_fill()t.pendown()t.circle(100,40)t.setheading(180)t.circle(30,40)t.setheading(-40)t.circle(40,40)t.setheading(-150)a = 0.5for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.05t.lt(3) #向左转3度t.fd(a) #向前走a的步长elif 30 <= i < 60 or 90<=i <100:a=a-0.05t.lt(3)t.fd(a)t.setheading(93)t.circle(-150,30)t.end_fill()t.penup()t.goto(-85,-115)t.setheading(-150)t.color("gray","gray")t.begin_fill()t.pendown()a = 0.3for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.03t.lt(3) #向左转3度t.fd(a) #向前走a的步长else:a=a-0.03t.lt(3)t.fd(a)t.end_fill()#每个脚趾绘制函数def toe(x,y):t.begin_fill()t.goto(x,y)t.circle(3,360)t.end_fill()t.penup()toe(-98,-120)toe(-96,-110)toe(-88,-105)toe(-80,-105)#右肢t.color("black")t.penup()t.goto(65,-24)t.setheading(-40)t.begin_fill()t.pendown()t.circle(-100,40)t.setheading(0)t.circle(-30,40)t.setheading(-140)t.circle(-40,40)t.setheading(-30)a = 0.5for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.05t.rt(3) #向左转3度t.fd(a) #向前走a的步长elif 30 <= i < 60 or 90<=i <100:a=a-0.05t.rt(3)t.fd(a)t.setheading(87)t.circle(150,30)t.end_fill()t.penup()t.goto(85,-115)t.setheading(150)t.color("gray","gray")t.begin_fill()t.pendown()a = 0.3for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.03t.lt(3) #向左转3度t.fd(a) #向前走a的步长else:a=a-0.03t.lt(3)t.fd(a)t.end_fill()t.penup()toe(98,-120)toe(96,-110)toe(88,-105)toe(80,-105)t.goto(-57,-140)t.color("black")t.setheading(-20)t.pendown()t.circle(165,40)t.penup()t.goto(0,180)t.write("Pandas are the most lovely animals", align = "center",font = ("Times", 18, "bold"))t.done()
2.2、运行效果


3.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:轻松熊源码# Project Name:Rilakkuma.pyfrom turtle import *tracer(10)ht()fillcolor('#B8860B')#填充颜色的rgb码pensize(10)#画笔的尺寸pencolor('#5E2612')#画笔颜色#body----身体部分penup()#抬起画笔goto(-70,-85)#设置起始位置seth(135)#设置起始方向pendown()#落下画笔begin_fill()circle(18,180)#半径为18圆心角为180的圆circle(200,17)seth(-90)circle(400,13)circle(18,180)seth(-104)circle(18,180)circle(400,13)seth(28)circle(200,17)circle(18,180)end_fill()#body whitepenup()goto(0,-185)fillcolor("white")pencolor("white")seth(0)pendown()begin_fill()circle(20,22.5)circle(30,135)circle(20,45)circle(30,135)circle(20,22.5)end_fill()#face-----脸部分fillcolor('#B8860B')pencolor('#5E2612')seth(-22.5)penup()goto(0,0)fd(120)pendown()seth(60)begin_fill()circle(75,45)circle(125,135)circle(75,45)circle(125,135)end_fill()pensize(17)penup()goto(45,0)pendown()circle(5,360)penup()goto(-45,0)pendown()circle(5,360)#face whitepenup()seth(-22.5)fd(75)seth(60)pendown()fillcolor("white")begin_fill()pencolor("white")circle(15,45)circle(30,135)circle(15,45)circle(30,135)end_fill()#face2------脸补充函数fillcolor('#B8860B')pencolor('#5E2612')penup()goto(0,-15)pendown()pensize(10)seth(0)circle(5,360)seth(-45)fd(20)penup()goto(0,-15)seth(-135)pendown()fd(20)penup()goto(65,100)circle(35,170)pendown()begin_fill()circle(35,205)end_fill()penup()goto(-65,100)seth(-45)circle(-35,175)pendown()begin_fill()circle(-35,195)end_fill()#heartpenup()goto(150,150)seth(45)pencolor("red")fillcolor("red")pendown()begin_fill()fd(19)circle(25,45)circle(11.25,180)seth(90)circle(11.25,180)circle(25,45)fd(19)end_fill()update()
3.2、运行效果


4.1、完整代码
#!/usr/bin/env python# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:彩色皮卡丘源码# Project Name:Pikachu.pyfrom turtle import *'''绘制皮卡丘头部'''def face(x,y):"""画脸"""begin_fill()penup()# 将海龟移动到指定的坐标goto(x, y)pendown()# 设置海龟的方向setheading(40)circle(-150, 69)fillcolor("#FBD624")# 将海龟移动到指定的坐标penup()goto(53.14, 113.29)pendown()setheading(300)circle(-150, 30)setheading(295)circle(-140, 20)print(position())forward(5)setheading(260)circle(-80, 70)print(position())penup()goto(-74.43,-79.09)pendown()penup()# 将海龟移动到指定的坐标goto(-144,103)pendown()setheading(242)circle(110, 35)right(10)forward(10)setheading(250)circle(80, 115)print(position())penup()goto(-74.43,-79.09)pendown()setheading(10)penup()goto(-144, 103)pendown()penup()goto(x, y)pendown()end_fill()# 下巴penup()goto(-50, -82.09)pendown()pencolor("#DDA120")fillcolor("#DDA120")begin_fill()setheading(-12)circle(120, 25)setheading(-145)forward(30)setheading(180)circle(-20, 20)setheading(143)forward(30)end_fill()# penup()# # 将海龟移动到指定的坐标# goto(0, 0)# pendown()def eye():"""画眼睛"""# 左眼color("black","black")penup()goto(-110, 27)pendown()begin_fill()setheading(0)circle(24)end_fill()# 左眼仁color("white", "white")penup()goto(-105, 51)pendown()begin_fill()setheading(0)circle(10)end_fill()# 右眼color("black", "black")penup()goto(25, 40)pendown()begin_fill()setheading(0)circle(24)end_fill()# 右眼仁color("white", "white")penup()goto(17, 62)pendown()begin_fill()setheading(0)circle(10)end_fill()def cheek():"""画脸颊"""# 右边color("#9E4406", "#FE2C21")penup()goto(-130, -50)pendown()begin_fill()setheading(0)circle(27)end_fill()# 左边color("#9E4406", "#FE2C21")penup()goto(53, -20)pendown()begin_fill()setheading(0)circle(27)end_fill()def nose():"""画鼻子"""color("black", "black")penup()goto(-40, 38)pendown()begin_fill()circle(7,steps = 3)end_fill()def mouth():"""画嘴"""color("black", "#F35590")# 嘴唇penup()goto(-10, 22)pendown()begin_fill()setheading(260)forward(60)circle(-11, 150)forward(55)print(position())penup()goto(-38.46, 21.97)pendown()end_fill()# 舌头color("#6A070D", "#6A070D")begin_fill()penup()goto(-10.00, 22.00)pendown()penup()goto(-14.29, -1.7)pendown()penup()goto(-52, -5)pendown()penup()goto(-60.40, 12.74)pendown()penup()goto(-38.46, 21.97)pendown()penup()goto(-10.00, 22.00)pendown()end_fill()color("black","#FFD624")penup()goto(-78, 15)pendown()begin_fill()setheading(-25)for i in range(2):setheading(-25)circle(35, 70)end_fill()color("#AB1945", "#AB1945")penup()goto(-52, -5)pendown()begin_fill()setheading(40)circle(-33, 70)goto(-16,-1.7)penup()goto(-18,-17)pendown()setheading(155)circle(25, 70)end_fill()def ear():"""画耳朵"""# 左耳color("black","#FFD624")penup()goto(-145, 93)pendown()begin_fill()setheading(165)circle(-248,50)right(120)circle(-248,50)end_fill()color("black", "black")penup()goto(-240, 143)pendown()begin_fill()setheading(107)circle(-170, 25)left(80)circle(229, 15)left(120)circle(300, 15)end_fill()# 右耳color("black", "#FFD624")penup()goto(30, 136)pendown()begin_fill()setheading(64)circle(-248, 50)right(120)circle(-248, 50)end_fill()color("black", "black")penup()goto(160, 200)pendown()begin_fill()setheading(52)circle(170, 25)left(116)circle(229, 15)left(71)circle(-300, 15)end_fill()def setting():"""设置参数"""pensize(2)# 隐藏海龟hideturtle()speed(10)def main():"""主函数"""setting()face(-132,115)eye()cheek()nose()mouth()ear()done()if __name__ == '__main__':main()
4.2、运行效果


5.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:彩色皮卡丘局部源码# Project Name:BlackAndWhitePikachu.pyimport turtle as tdef infoPrt():print('coordinate: ' + str(t.pos()))print('angle: ' + str(t.heading()))t.pensize(3)t.hideturtle()t.colormode(255)t.color("black")t.setup(700, 650)t.speed(10)t.st()#t.dot()t.pu()#t.goto(-150,100)t.goto(-210,86)t.pd()infoPrt()# 头print('头')t.seth(85)t.circle(-100,50)#t.seth(78)#t.circle(-100,25)infoPrt()t.seth(25)t.circle(-170,50)infoPrt()# 右耳print('右耳')t.seth(40)#t.circle(-250,52)t.circle(-250,30)infoPrt()# 右耳尖t.begin_fill()# 左t.circle(-250,22)#t.fillcolor("pink")# 右t.seth(227)t.circle(-270, 15)prePos = t.pos()infoPrt()# 下t.seth(105)t.circle(100, 32)t.end_fill()t.pu()t.setpos(prePos)t.pd()t.seth(212)t.circle(-270, 28)prePos = t.pos()t.pu()t.goto(t.xcor()+5,t.ycor()-2)t.pd()# 躯干print('躯干')t.seth(280)t.circle(500, 30)infoPrt()# 臀部print('臀部')t.seth(120)#t.circle(150, -55)t.circle(150, -11)p_tail=t.pos()t.circle(150, -44)p_butt=t.pos()infoPrt()# 尾巴t.pu()t.setpos(p_tail)t.pd()t.begin_fill()t.seth(50)t.fd(25)t.seth(-50)t.fd(30)p_tail1=t.post.seth(-140)t.fd(36)t.end_fill()t.seth(39)# 右尾和h1t.fd(72)# 右尾和v1t.seth(125)t.fd(48)# 右尾和h2t.seth(40)t.fd(53)# 右尾和v2t.seth(88)t.fd(45)# 右尾和h3t.seth(35)t.fd(105)# 右尾和v3t.seth(105)t.circle(850, 8)#t.fd(105)t.seth(215)#t.fd(125)t.circle(850, 11)t.seth(280)t.fd(110)t.seth(220)t.fd(50)t.seth(309)t.fd(56)# 底盘print('底盘')t.pu()t.setpos(p_butt)t.pd()t.seth(20)t.circle(120, -45)infoPrt()t.seth(330)t.circle(-150, -30)infoPrt()prePos = t.pos()t.pu()t.goto(t.xcor()+20,t.ycor())t.pd()t.seth(230)t.circle(-70, 120)p_bot=t.pos()# 两脚-rightt.pu()t.setpos(p_butt)t.setpos(t.xcor()+5,t.ycor()+5)t.pd()t.seth(-86)t.fd(30)t.seth(-93)t.fd(33)t.seth(-225)t.circle(-150, 22)# 两脚-leftt.pu()t.setpos(p_bot)t.setpos(t.xcor()+85,t.ycor()-43)t.pd()t.seth(-105)t.fd(50)t.seth(-225)t.circle(-150, 22)# 左躯干print('躯干')t.pu()t.setpos(p_bot)t.pd()t.seth(90)t.circle(450, 13)p_lfhd = t.pos()t.circle(450, 5)t.pu()t.circle(450, 5)t.pd()t.circle(450, 6)infoPrt()# 左脸print('左脸')t.seth(330)t.circle(50, -90)infoPrt()# 左酒窝t.seth(30)t.circle(-15, 120)t.seth(-70)t.circle(-30, 90)# 左手t.pu()t.setpos(p_lfhd)t.pd()t.seth(160)t.circle(150, 30)infoPrt()t.seth(180)t.circle(-30, 150)t.fd(67)t.pu()t.setpos(t.xcor()-40,t.ycor()-60)t.pd()t.seth(200)t.circle(-5, 180)# 右手t.pu()t.setpos(p_lfhd)t.setpos(t.xcor()+180,t.ycor()+5)t.pd()t.seth(200)t.circle(-50, 100)t.pu()t.circle(-50, 15)t.pd()t.circle(-50, 65)t.pu()t.setpos(t.xcor()+10,t.ycor()-45)t.pd()#t.seth(270)#t.circle(-30, -180)t.seth(80)t.fd(10)t.seth(165)t.circle(10, 60)t.seth(90)t.fd(5)t.seth(165)t.circle(10, 60)t.seth(95)t.fd(5)t.seth(185)t.circle(10, 60)t.seth(105)t.fd(10)t.seth(230)t.fd(20)t.seth(145)t.fd(10)t.seth(285)t.fd(20)# 右酒窝t.pu()t.setpos(t.xcor()-40,t.ycor()+110)t.pd()t.circle(27, 360)# 嘴t.pu()t.setpos(t.xcor()-30,t.ycor()+28)t.pd()t.seth(280)t.circle(-130, 30)t.seth(270)t.circle(-6, 160)t.seth(130)t.circle(-130, 30)t.pu()t.setpos(t.xcor()-5,t.ycor()+5)t.pd()t.seth(160)t.circle(-20, -70)t.seth(160)t.circle(-30, -60)t.pu()t.setpos(t.xcor(),t.ycor()-28)t.pd()t.seth(200)t.circle(50, 58)# 左眼t.pu()t.setpos(t.xcor()-40,t.ycor()+90)t.pd()t.circle(5)t.pu()t.setpos(t.xcor()+5,t.ycor()+10)t.pd()t.begin_fill()t.seth(190)t.circle(15, 130)t.seth(310)t.circle(10, 15)t.seth(0)t.circle(17, 133)t.seth(90)t.circle(10, 15)t.end_fill()t.pu()t.setpos(t.xcor()+2,t.ycor()-15)t.pd()t.color("white")t.begin_fill()t.circle(5)t.end_fill()# 右眼t.pu()t.setpos(t.xcor()+85,t.ycor()+15)t.pd()t.color("black")t.circle(5)t.pu()t.setpos(t.xcor()+5,t.ycor()+10)t.pd()t.begin_fill()t.seth(190)t.circle(20, 130)t.seth(310)t.circle(10, 15)t.seth(0)t.circle(22, 133)t.seth(90)t.circle(13, 15)t.end_fill()t.pu()t.setpos(t.xcor()-7,t.ycor()-15)t.pd()t.color("white")t.begin_fill()t.circle(7)t.end_fill()# 左耳t.color("black")t.pu()t.goto(-210,86)t.setpos(t.xcor()+15,t.ycor()+38)t.pd()t.seth(90)t.circle(-250,30)t.begin_fill()# 左t.circle(-250,18)# 右t.seth(270)t.circle(-270, 12)prePos = t.pos()# 下t.seth(180)t.circle(100, 30)t.end_fill()t.pu()t.setpos(prePos)t.pd()t.seth(270)t.circle(-270, 18)t.done()
5.2、运行效果


6.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:彩色皮卡丘局部源码# Project Name:Pikachu.pyimport turtle as tdef nose():t.penup()t.seth(90)t.fd(100)t.pendown()t.begin_fill()t.fillcolor('black')t.seth(45)t.fd(25)t.seth(135)t.circle(25,90)t.seth(315)t.fd(25)t.end_fill()def eyes(seth,fd,c):t.penup()t.seth(seth)t.fd(fd)t.pendown()t.begin_fill()t.fillcolor('black')t.circle(50)t.end_fill()t.penup()t.circle(50, c)t.pendown()t.begin_fill()t.fillcolor('white')t.circle(20)t.end_fill()def face(seth,fd):t.penup()t.seth(seth)t.fd(fd)t.pendown()t.begin_fill()t.fillcolor('red')t.circle(70)t.end_fill()def lip():t.penup()t.seth(135)t.fd(250)t.pendown()t.seth(-300)t.circle(30, -65)t.begin_fill()t.fillcolor('Firebrick')t.seth(165)t.fd(140)t.seth(195)t.fd(140)t.seth(-360)t.circle(30, -65)t.penup()t.seth(-60)t.circle(30, 65)t.pendown()t.seth(-70)t.fd(240)t.circle(55, 140)t.seth(70)t.fd(240)t.end_fill()t.seth(-110)t.fd(80)t.begin_fill()t.fillcolor('Firebrick1')t.seth(120)t.circle(120, 123)t.seth(-70)t.fd(165)t.circle(55, 140)t.seth(72)t.fd(165)t.end_fill()def setting():t.pensize(4)t.hideturtle()t.setup(1000, 600)t.speed(10)t.screensize(bg='yellow')def main():setting()nose()eyes(160, 250, 60)eyes(-9.5, 530, 230)face(195, 600)face(-11, 720)lip()t.done()if __name__ =='__main__':main()
6.2、运行效果


7.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:小猪佩奇源码# Project Name:PeppaPig.py"""绘制小猪佩奇"""from turtle import *def nose(x,y):"""画鼻子"""penup()# 将海龟移动到指定的坐标goto(x,y)pendown()# 设置海龟的方向(0-东、90-北、180-西、270-南)setheading(-30)begin_fill()a = 0.4for i in range(120):if 0 <= i < 30 or 60 <= i <90:a = a + 0.08# 向左转3度left(3)# 向前走forward(a)else:a = a - 0.08left(3)forward(a)end_fill()penup()setheading(90)forward(25)setheading(0)forward(10)pendown()# 设置画笔的颜色(红, 绿, 蓝)pencolor(255, 155, 192)setheading(10)begin_fill()circle(5)color(160, 82, 45)end_fill()penup()setheading(0)forward(20)pendown()pencolor(255, 155, 192)setheading(10)begin_fill()circle(5)color(160, 82, 45)end_fill()def head(x, y):"""画头"""color((255, 155, 192), "pink")penup()goto(x,y)setheading(0)pendown()begin_fill()setheading(180)circle(300, -30)circle(100, -60)circle(80, -100)circle(150, -20)circle(60, -95)setheading(161)circle(-300, 15)penup()goto(-100, 100)pendown()setheading(-30)a = 0.4for i in range(60):if 0<= i < 30 or 60 <= i < 90:a = a + 0.08lt(3) #向左转3度fd(a) #向前走a的步长else:a = a - 0.08lt(3)fd(a)end_fill()def ears(x,y):"""画耳朵"""color((255, 155, 192), "pink")penup()goto(x, y)pendown()begin_fill()setheading(100)circle(-50, 50)circle(-10, 120)circle(-50, 54)end_fill()penup()setheading(90)forward(-12)setheading(0)forward(30)pendown()begin_fill()setheading(100)circle(-50, 50)circle(-10, 120)circle(-50, 56)end_fill()def eyes(x,y):"""画眼睛"""color((255, 155, 192), "white")penup()setheading(90)forward(-20)setheading(0)forward(-95)pendown()begin_fill()circle(15)end_fill()color("black")penup()setheading(90)forward(12)setheading(0)forward(-3)pendown()begin_fill()circle(3)end_fill()color((255, 155, 192), "white")penup()seth(90)forward(-25)seth(0)forward(40)pendown()begin_fill()circle(15)end_fill()color("black")penup()setheading(90)forward(12)setheading(0)forward(-3)pendown()begin_fill()circle(3)end_fill()def cheek(x,y):"""画脸颊"""color((255, 155, 192))penup()goto(x,y)pendown()setheading(0)begin_fill()circle(30)end_fill()def mouth(x,y):"""画嘴巴"""color(239, 69, 19)penup()goto(x, y)pendown()setheading(-80)circle(30, 40)circle(40, 80)def setting():"""设置参数"""pensize(4)# 隐藏海龟hideturtle()colormode(255)color((255, 155, 192), "pink")setup(840, 500)speed(10)def main():"""主函数"""setting()nose(-100, 100)head(-69, 167)ears(0, 160)eyes(0, 140)cheek(80, 10)mouth(-20, 30)done()if __name__ == '__main__':main()
7.2、运行效果


8.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:小猪佩奇源码# Project Name:PeppaPig.pyimport turtle as tt.pensize(4)t.hideturtle()t.colormode(255)t.color((255,155,192),"pink")t.setup(840,500)t.speed(10)#鼻子t.pu()t.goto(-100,100)t.pd()t.seth(-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)t.fd(25)t.seth(0)t.fd(10)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.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)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)t.done()
8.2、运行效果


9.1、完整代码
# -*- coding: UTF-8 -*-# Project Leader:以数据之名# Project:小猪佩奇源码# Project Name:PeppaPig.pyfrom turtle import*def nose(x,y):#鼻子pu()goto(x,y)pd()seth(-30)begin_fill()a=0.4for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.08lt(3) #向左转3度fd(a) #向前走a的步长else:a=a-0.08lt(3)fd(a)end_fill()pu()seth(90)fd(25)seth(0)fd(10)pd()pencolor(255,155,192)seth(10)begin_fill()circle(5)color(160,82,45)end_fill()pu()seth(0)fd(20)pd()pencolor(255,155,192)seth(10)begin_fill()circle(5)color(160,82,45)end_fill()def head(x,y):#头color((255,155,192),"pink")pu()goto(x,y)seth(0)pd()begin_fill()seth(180)circle(300,-30)circle(100,-60)circle(80,-100)circle(150,-20)circle(60,-95)seth(161)circle(-300,15)pu()goto(-100,100)pd()seth(-30)a=0.4for i in range(60):if 0<=i<30 or 60<=i<90:a=a+0.08lt(3) #向左转3度fd(a) #向前走a的步长else:a=a-0.08lt(3)fd(a)end_fill()def ears(x,y): #耳朵color((255,155,192),"pink")pu()goto(x,y)pd()begin_fill()seth(100)circle(-50,50)circle(-10,120)circle(-50,54)end_fill()pu()seth(90)fd(-12)seth(0)fd(30)pd()begin_fill()seth(100)circle(-50,50)circle(-10,120)circle(-50,56)end_fill()def eyes(x,y):#眼睛color((255,155,192),"white")pu()seth(90)fd(-20)seth(0)fd(-95)pd()begin_fill()circle(15)end_fill()color("black")pu()seth(90)fd(12)seth(0)fd(-3)pd()begin_fill()circle(3)end_fill()color((255,155,192),"white")pu()seth(90)fd(-25)seth(0)fd(40)pd()begin_fill()circle(15)end_fill()color("black")pu()seth(90)fd(12)seth(0)fd(-3)pd()begin_fill()circle(3)end_fill()def cheek(x,y):#腮color((255,155,192))pu()goto(x,y)pd()seth(0)begin_fill()circle(30)end_fill()def mouth(x,y): #嘴color(239,69,19)pu()goto(x,y)pd()seth(-80)circle(30,40)circle(40,80)def body(x,y):#身体color("red",(255,99,71))pu()goto(x,y)pd()begin_fill()seth(-130)circle(100,10)circle(300,30)seth(0)fd(230)seth(90)circle(300,30)circle(100,3)color((255,155,192),(255,100,100))seth(-135)circle(-80,63)circle(-150,24)end_fill()def hands(x,y):#手color((255,155,192))pu()goto(x,y)pd()seth(-160)circle(300,15)pu()seth(90)fd(15)seth(0)fd(0)pd()seth(-10)circle(-20,90)pu()seth(90)fd(30)seth(0)fd(237)pd()seth(-20)circle(-300,15)pu()seth(90)fd(20)seth(0)fd(0)pd()seth(-170)circle(20,90)def foot(x,y):#脚pensize(10)color((240,128,128))pu()goto(x,y)pd()seth(-90)fd(40)seth(-180)color("black")pensize(15)fd(20)pensize(10)color((240,128,128))pu()seth(90)fd(40)seth(0)fd(90)pd()seth(-90)fd(40)seth(-180)color("black")pensize(15)fd(20)def tail(x,y):#尾巴pensize(4)color((255,155,192))pu()goto(x,y)pd()seth(0)circle(70,20)circle(10,330)circle(70,30)def setting(): #参数设置title("小猪佩奇")pensize(4)hideturtle()colormode(255)color((255,155,192),"pink")setup(840,500)speed(10)def main():setting() #画布、画笔设置nose(-100,100) #鼻子head(-69,167) #头ears(0,160) #耳朵eyes(0,140) #眼睛cheek(80,10) #腮mouth(-20,30) #嘴body(-32,-8) #身体hands(-56,-45) #手foot(2,-177) #脚tail(148,-155) #尾巴done() #结束main()
9.2、运行效果
备注:受限于图像大小限制,此处展示的均为静态图片,实际效果以运行效果为准


09|Python专题
虽小编一己之力微弱,但读者众星之光璀璨。小编敞开心扉之门,还望倾囊赐教原创之文,期待之心满于胸怀,感激之情溢于言表。一句话,欢迎联系小编投稿您的原创文章!

文章转载自以数据之名,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。





