这是一个一年半前Thonny写的小马绘画代码。。整体上花了我一周左右零散时间才完全做出这效果。另外在实际实现效果里如果不是用Thonny运行会出现画框越界的情况。因为结构里好多起笔的地方都是坐标和方向混用,我没办法修改了(流泪)因为当时一点一点用turtle的语句也一边了解,整个代码结构和优化不是很好,各位可当娱乐参考一下。
运行结果完整的话效果会如下
具体实现代码:
import turtle as t
from time import perf_counter
start = perf_counter()
t.setup(1980,980,0,0)
#当不需要辅助网格作为坐标参考参数时,可去掉网格显示函数。注意不要轻易改动判别函数。
#无网格判断
s = 0
#网格建立函数
####################
##这里原本是会画的时候为了方便参考坐标位置我设置了一个网格线,测试好画完后我删除了
######################
#暮光绘制函数{总}
t.speed(0)
t.penup()
#暮光起始坐标修正函数
if s < 1:
t.fd(-600)
t.seth(90)
t.fd(332)
t.seth(240)
else:
t.fd(-400)
t.seth(90)
t.fd(300)
t.seth(240)
t.pendown()
t.pensize(8)
#色块补充1
t.pencolor("MediumOrchid1")
t.fillcolor("MediumOrchid1")
t.begin_fill()
t.circle(200,38.5)
t.seth(190)
t.circle(17,4)
t.fd(40)
t.circle(10,70)
t.seth(260)
t.circle(50,70)
t.fd(3)
t.circle(400,28)
t.seth(180)
t.circle(-400,2)
t.seth(72.5)
t.fd(204.5)
t.seth(150)
t.circle(500,23.8)
t.end_fill()
t.seth(240)
#暮光鼻子及前脸轮廓线
t.pencolor("purple")
t.circle(200,38.5)
t.seth(190)
t.circle(17,4)
t.fd(40)
t.circle(10,70)
t.seth(260)
t.circle(50,70)
t.fd(3)
t.circle(400,28)
t.seth(180)
t.circle(-400,2)
t.penup()
t.seth(72.5)
t.fd(207)
t.pendown()
#木光头发1
t.pensize(5)
t.seth(215)
t.pencolor("RoyalBlue4")
t.fillcolor("darkblue")
t.begin_fill()
t.seth(150)
t.circle(500,28)
t.seth(95)
t.fd(45)
t.seth(240)
t.circle(200,13)
t.seth(170)
t.circle(300,8)
t.seth(70)
t.circle(-155,75)
t.end_fill()
####暮光的角
t.penup()
t.seth(275)
t.fd(60)
t.pendown()
t.pencolor("purple")
t.fillcolor("MediumOrchid1")
t.begin_fill()
t.seth(95)
t.fd(80)
t.circle(-4,155)
t.fd(81)
t.end_fill()
t.penup()
t.seth(0)
t.fd(4)
t.pendown()
#暮光的头发2
t.penup()
t.seth(120)
t.fd(50)
t.pendown()
t.pencolor("RoyalBlue4")
t.fillcolor("darkblue")
t.begin_fill()
t.seth(-30)
t.fd(150)
t.seth(250)
t.circle(200,30)
t.pencolor("darkblue")
t.seth(146)
t.circle(500,18)
t.seth(90)
t.circle(-80,60)
t.end_fill()
t.seth(-53)
t.fd(170)
t.fillcolor("MediumOrchid1")
t.begin_fill()
#暮光的耳朵
t.pencolor("purple")
t.penup()
t.seth(85)
t.fd(100)
t.pendown()
t.seth(75)
t.circle(-100,45)
t.circle(-10,105)
t.circle(-300,35)
t.end_fill()
#色块补充
t.pencolor("MediumOrchid1")
t.fillcolor("MediumOrchid1")
t.begin_fill()
t.seth(150)
t.fd(70)
t.goto(-475,77)
t.seth(-40)
t.fd(120)
t.end_fill()
t.penup()
t.goto(-480,73)
t.pendown()
#前半边身体
t.pencolor("purple")
t.fillcolor("MediumOrchid1")
t.begin_fill()
t.pensize(8)
t.seth(-80)
t.circle(-500,8)
t.seth(255)
t.circle(190,50)
t.seth(-35)
t.circle(300,4)
t.seth(-80)
t.fd(100)
t.circle(-500,20)
t.seth(-30)
t.circle(110,50)
t.seth(88)
t.circle(800,23)
t.seth(291)
t.circle(-800,3)
t.seth(-25)
t.circle(170,60)
t.seth(40)
t.circle(80,40)
t.seth(179.5)
t.end_fill()
t.penup()
t.fd(314)
t.pendown()
#前蹄2
t.fillcolor("MediumOrchid3")
t.begin_fill()
t.seth(172)
t.fd(70)
t.circle(20,90)
t.seth(255)
t.circle(300,40)
t.circle(10,60)
t.circle(10,35)
t.circle(100,75)
t.seth(140)
t.fd(40)
t.seth(110)
t.fd(27)
t.circle(-5,120)
t.circle(200,20)
t.end_fill()
#后蹄子
t.penup()
t.seth(0)
t.fd(273)
t.pendown()
t.fillcolor("MediumOrchid3")
t.begin_fill()
t.seth(-56)
t.pensize(6)
t.fd(120)
t.seth(-68)
t.circle(-200,50)
t.circle(5,120)
t.fd(46)
t.pensize(8)
t.seth(80)
t.circle(330,57)
t.end_fill()
t.fillcolor("MediumOrchid1")
t.begin_fill()
t.seth(-43)
t.circle(-330,58.5)
t.pensize(6)
t.seth(-30)
t.circle(110,50)
t.seth(94)
t.circle(800,21)
t.circle(20,80)
t.circle(-20,95)
t.seth(75)
t.fd(30)
t.circle(200,30)
t.circle(80,75)
t.seth(185)
t.fd(20)
t.circle(200,25)
t.end_fill()
#暮光的头发3
t.pensize(6)
t.pencolor("RoyalBlue4")
t.fillcolor("darkblue")
t.begin_fill()
t.seth(128)
t.circle(-340,39)
t.seth(230)
t.fd(50)
t.seth(264)
t.circle(-140,20)
t.seth(230)
t.circle(-140,25)
t.seth(-80)
t.fd(70)
t.seth(20)
t.circle(100,40)
t.seth(260)
t.circle(-150,37)
t.seth(-65)
t.circle(220,35)
t.seth(45)
t.circle(200,38.5)
t.end_fill()
#色块补充
t.pencolor("MediumOrchid1")
t.fillcolor("MediumOrchid1")
t.begin_fill()
t.back(0)
t.circle(200,-38.5)
t.seth(-1)
t.fd(130)
t.seth(122)
t.fd(135)
t.end_fill()
#暮光的尾巴
t.pencolor("RoyalBlue4")
t.seth(0)
t.penup()
t.fd(164)
t.pendown()
t.fillcolor("darkblue")
t.begin_fill()
t.pensize(5)
t.seth(55)
t.circle(-200,120)
t.circle(-800,14.3)
t.fd(30)
t.seth(210)
t.fd(50)
t.seth(100)
t.fd(70)
t.seth(265)
t.fd(80)
t.seth(213)
t.fd(267)
t.seth(95)
t.penup()
t.fd(20)
t.pendown()
t.seth(55)
t.circle(400,45)
t.circle(200,20)
t.circle(90,90)
t.fd(29.3)
t.end_fill()
#目光细节部分
t.penup()
t.goto(-510,308)
t.pendown()
#暮光眼睛
#(1)外眼线部分
t.pencolor("black")
t.fillcolor("white")
t.begin_fill()
t.seth(-40)
t.circle(150,40)
t.seth(176.5)
t.circle(-150,40)
t.seth(210)
t.pensize(5)
t.circle(200,15)
t.circle(10,10)
t.circle(200,25)
t.seth(266)
t.circle(100,10)
t.pensize(3)
t.seth(0)
t.circle(-130,30)
t.seth(15)
t.pensize(2)
t.circle(100,86)
t.seth(170.5)
t.circle(-150,12.5)
t.end_fill()
#瞳孔部分2
#调色板:
#t.fillcolor("DarkOrchid4 MediumOrchid3 ")
#t.begin_fill()
#t.end_fill()
#外瞳孔
t.pensize(4)
t.pencolor("DarkOrchid4")
t.seth(-85)
t.fillcolor("Purple4")
t.begin_fill()
t.circle(-100,60)
t.circle(-30,30)
t.circle(-80,10)
t.circle(-30,10)
t.fd(28)
t.seth(80)
t.circle(-200,6)
t.seth(-20)
t.pencolor("black")
t.fd(18)
t.circle(20,10)
t.circle(56,10)
t.circle(20,30)
t.seth(15)
t.circle(60,60)
t.circle(120,20)
t.end_fill()
#内瞳仁
t.fillcolor("black")
t.begin_fill()
t.seth(158)
t.circle(-150,8)
t.seth(210)
t.circle(200,15)
t.circle(10,10)
t.circle(200,19)
t.seth(-20)
t.fd(18)
t.circle(20,10)
t.circle(56,10)
t.circle(20,30)
t.seth(15)
t.circle(60,60)
t.circle(120,21)
t.end_fill()
##内高光
t.penup()
t.seth(160)
t.fd(27)
t.pendown()
t.fillcolor("white")
t.begin_fill()
t.pencolor("white")
t.seth(-60)
t.circle(-30,30)
t.circle(-60,20)
t.circle(-15,120)
t.circle(-10,50)
t.circle(-60,5)
t.end_fill()
##高光2
t.penup()
t.seth(-90)
t.fd(40)
t.pendown()
t.seth(-60)
t.fillcolor("white")
t.begin_fill()
t.circle(-10,30)
t.circle(-20,20)
t.circle(-6,120)
t.circle(-4,30)
t.circle(-20,30)
t.circle(-10,35)
t.circle(-4,90)
t.end_fill()
#嘴巴,鼻子
t.penup()
t.seth(215)
t.fd(110)
t.pendown()
t.pencolor("DarkOrchid3")
t.circle(-20,60)
t.penup()
t.seth(270)
t.fd(45)
t.pendown()
t.seth(-25)
t.circle(40,90)
#尾巴挑染
t.penup()
t.home()
t.back(108)
t.seth(90)
t.fd(30)
t.pendown()
t.pencolor("midnight blue")
t.pensize(15)
#尾巴外边线
t.seth(55)
t.circle(-202,120)
t.circle(-805,14.3)
t.fd(31)
t.seth(210)
t.fd(50)
t.seth(100)
t.fd(70)
t.seth(265)
t.fd(80)
t.seth(213)
t.fd(267)
t.seth(95)
t.penup()
t.fd(20)
t.pendown()
t.seth(55)
t.circle(400,45)
t.circle(200,20)
t.circle(90,90)
t.fd(29.3)
#1紫色挑染线
t.pensize(2)
t.seth(120)
t.circle(50,10)
t.pencolor("dark violet")
t.fillcolor("dark violet")
t.begin_fill()
###
#尾巴曲线函数
###down()
t.seth(40)
t.fd(29.3)
t.circle(-130,90)
t.circle(-100,30)
t.seth(-75)
t.circle(-400,47)
t.seth(35)
t.fd(60)
###up()
t.seth(65)
t.circle(400,45)
t.circle(150,20)
t.circle(200,15)
t.circle(114,76)
t.fd(60)
t.end_fill()
#深粉挑染
t.pensize(2)
t.pencolor("deeppink")
t.fillcolor("deeppink")
t.begin_fill()
#down()
t.seth(40)
t.fd(29.3)
t.circle(-150,90)
t.circle(-150,32)
t.seth(-80)
t.circle(-400,45)
t.seth(33)
t.fd(60)
###up()
t.seth(63)
t.circle(400,45)
t.circle(150,20)
t.circle(200,10)
t.circle(200,15)
t.circle(113,68)
t.fd(65)
t.end_fill()
#######
t.penup()
t.home()
t.goto(-200,-40)
t.seth(0)
t.pendown()
###可爱标志函数
x = pow(2,0.5)
t.begin_fill()
t.pensize(2)
t.pencolor("MediumOrchid1")
t.fillcolor("white")
t.begin_fill()
####几何图循环实现部分
for i in range(6):
t.left(15)
t.fd(30/x)
t.left(90)
t.fd(30/x)
t.right(165)
t.end_fill()
t.penup()
t.left(90)
t.fd(40)
t.right(90)
t.fd(30)
t.right(90)
t.pendown()
t.pencolor("VioletRed3")
t.fillcolor("VioletRed3")
t.begin_fill()
for i in range(6):
t.left(15)
t.fd(40/x)
t.left(90)
t.fd(40/x)
t.right(165)
t.end_fill()
t.penup()
t.back(10)
t.seth(0)
t.fd(60)
t.seth(-90)
t.fd(50)
t.pendown()
t.pencolor("VioletRed3")
t.pensize(1)
t.speed(0)
for i in range(6):
t.penup()
t.circle(-60,60)
t.pendown()
t.fillcolor("white")
t.begin_fill()
for k in range(6):
t.left(15)
t.fd(10/x)
t.left(90)
t.fd(10/x)
t.right(165)
t.end_fill()
##头发挑染
t.speed(7)
t.penup()
t.home()
t.goto(-300,80)
t.pendown()
t.pensize(2)
t.pencolor("deeppink")
t.fillcolor("deeppink")
t.begin_fill()
###线条实现部分
t.seth(260)
t.circle(-200,42)
t.seth(-49)
t.circle(220,5)
t.seth(39)
t.circle(200,40)
t.seth(125)
t.circle(-340,7)
t.end_fill()
#紫色挑染
t.pencolor("dark violet")
t.fillcolor("dark violet")
t.begin_fill()
t.seth(260)
t.circle(-200,42)
t.seth(-49)
t.circle(220,5)
t.seth(39)
t.circle(200,40)
t.seth(125)
t.circle(-340,5)
t.end_fill()
#外边线描绘二次
##条件部分
t.pencolor("midnight blue")
t.penup()
t.goto(-275,32)
t.pendown()
t.pensize(8)
####线条实现部分
t.seth(128)
t.circle(-340,39)
t.seth(230)
t.fd(50)
t.seth(264)
t.circle(-140,20)
t.seth(230)
t.circle(-140,25)
t.seth(-80)
t.fd(70)
t.seth(20)
t.circle(100,40)
t.seth(260)
t.circle(-150,37)
t.seth(-65)
t.circle(220,35)
t.seth(45)
t.circle(200,38.5)
#耳朵线条补充
t.penup()
t.goto(-350,370)
t.pencolor("dark violet")
t.pensize(4)
t.pendown()
t.seth(270)
t.circle(-200,25)
##头顶挑染
##画笔设置部分
t.penup()
t.goto(-400,370)
t.pensize(6)
t.pencolor("midnight blue")
t.pendown()
t.fillcolor("dark blue")
t.begin_fill()
##色块补充
t.seth(250)
t.circle(200,29)
t.seth(95)
t.circle(-200,29)
t.seth(160)
t.fd(20)
t.end_fill()
#上色部分位置确定
t.penup()
t.goto(-450,400)
t.pendown()
t.pencolor("deeppink")
t.fillcolor("deeppink")
t.begin_fill()
t.pensize(4)
##图形上色
t.seth(255)
t.circle(-400,14)
t.seth(149)
t.circle(200,20)
t.seth(40)
t.circle(400,16)
t.end_fill()
#紫色挑染
t.pencolor("dark violet")
t.fillcolor("dark violet")
t.begin_fill()
t.seth(236)
t.circle(-400,16)
t.seth(167)
t.circle(500,5)
t.seth(60)
t.circle(-150,25)
t.seth(5)
t.circle(100,45)
t.end_fill()
##边线描绘
t.penup()
t.pensize(7)
t.pencolor("midnight blue")
t.goto(-420,275)
t.pendown()
t.seth(215)
t.seth(150)
t.circle(500,28)
t.seth(95)
t.fd(45)
t.seth(240)
t.circle(200,13)
t.seth(170)
t.circle(300,8)
t.seth(70)
t.circle(-155,75)
t.penup()
t.fd(22)
t.pendown()
t.seth(-30)
t.fd(150)
t.seth(250)
t.circle(200,30)
###角旋纹
t.penup()
t.goto(-550,425)
t.pencolor("dark violet")
t.pensize(4)
t.pendown()
t.seth(-40)
t.circle(50,40)
t.penup()
t.goto(-555,450)
t.pendown()
t.seth(-30)
t.circle(50,23)
t.penup()
###
#眼睛光渐变以及睫毛细节
t.goto(-490,250)
t.pendown()
t.pencolor("MediumPurple3")
t.fillcolor("Purple2")
t.begin_fill()
t.pensize(2)
t.fd(10)
t.seth(260)
t.circle(-50,40)
t.seth(160)
t.fd(14)
t.end_fill()
t.pencolor("MediumPurple2")
t.fillcolor("MediumPurple2")
t.begin_fill()
t.seth(220)
t.circle(-40,30)
t.seth(-50)
t.fd(16)
t.seth(55)
t.circle(-50,28)
t.end_fill()
t.penup()
t.goto(-510,308)
t.pendown()
t.pencolor("black")
t.seth(210)
t.pensize(8)
t.circle(200,15)
t.circle(10,10)
t.circle(200,30)
t.penup()
t.goto(-443,250)
t.pencolor("black")
t.fillcolor("black")
t.begin_fill()
t.pensize(3)
t.pendown()
t.seth(0)
t.circle(100,20)
t.seth(14)
t.circle(120,-18)
t.end_fill()
t.penup()
t.goto(-444,230)
t.pendown()
t.pencolor("black")
t.fillcolor("black")
t.begin_fill()
t.pensize(3)
t.pendown()
t.seth(1)
t.circle(100,20)
t.seth(15)
t.circle(120,-18)
t.end_fill()
t.penup()
t.goto(-470,200)
t.pendown()
t.pencolor("black")
t.fillcolor("black")
t.begin_fill()
t.pensize(3)
t.pendown()
t.seth(-15)
t.circle(-100,20)
t.seth(-25)
t.circle(-120,-18)
t.end_fill()
t.penup()
t.goto(-482,187)
t.pendown()
t.pencolor("black")
t.fillcolor("black")
t.begin_fill()
t.pensize(3)
t.pendown()
t.seth(-15)
t.circle(-100,20)
t.seth(-25)
t.circle(-120,-18)
t.end_fill()
t.penup()
t.goto(-510,170)
t.pendown()
t.pencolor("black")
t.fillcolor("black")
t.begin_fill()
t.pensize(3)
t.pendown()
t.seth(-20)
t.circle(-100,20)
t.seth(-30)
t.circle(-120,-18)
t.end_fill()
print("运行时间是:{:.5f}s".format(perf_counter()-start))
转载请注明出处。