Python利用Turtle绘制Technoblade的示例代码
Leleprogrammer 人气:0在刚过去不久的6月30日那天,国外一位在YouTube拥有上千万粉丝的我的世界游戏主播Technoblade因癌症与世长辞,年仅23岁,他并没有离开我们,只是用另外一种方式活在了这个世界上。
为了纪念他,特地写了这篇文章,教大家用Turtle绘制出Technoblade,运行效果如下:
代码如下:
首先,用坐标表示每个像素块的颜色,定义一个列表
POS=[ [4,0,(213,164,9)], [6,0,(213,164,9)], [9,0,(213,164,9)], [11,0,(213,164,9)], [4,1,(213,164,9)], [5,1,(213,164,9)], [7,1,(213,164,9)], [9,1,(213,164,9)], [11,1,(213,164,9)], [6,1,(55,72,160)], [8,1,(30,30,154)], [8,1,(30,30,154)], [10,1,(149,172,2)], [4,2,(208,153,8)], [5,2,(208,153,8)], [6,2,(208,153,8)], [7,2,(208,153,8)], [8,2,(208,153,8)], [9,2,(208,153,8)], [10,2,(208,153,8)], [11,2,(208,153,8)], [4,3,(0,0,0)], [5,3,(255,255,255)], [6,3,(242,134,132)], [7,3,(242,134,132)], [8,3,(242,134,132)], [9,3,(242,134,132)], [10,3,(255,255,255)], [11,3,(0,0,0)], [4,4,(242,134,132)], [5,4,(242,134,132)], [6,4,(241,168,162)], [7,4,(241,168,162)], [8,4,(241,168,162)], [9,4,(241,168,162)], [10,4,(242,134,132)], [11,4,(242,134,132)], [4,5,(242,134,132)], [5,5,(242,134,132)], [6,5,(127,46,43)], [7,5,(242,134,132)], [8,5,(242,134,132)], [9,5,(127,46,43)], [10,5,(242,134,132)], [11,5,(242,134,132)], [4,5,(242,134,132)], [5,5,(242,134,132)], [6,5,(116,27,29)], [7,5,(242,134,132)], [8,5,(242,134,132)], [9,5,(116,27,29)], [10,5,(242,134,132)], [11,5,(242,134,132)], [4,6,(242,134,132)], [5,6,(242,134,132)], [6,6,(212,103,108)], [7,6,(212,103,108)], [8,6,(212,103,108)], [9,6,(212,103,108)], [10,6,(242,134,132)], [11,6,(242,134,132)], [4,7,(242,134,132)], [5,7,(242,134,132)], [6,7,(242,134,132)], [7,7,(242,134,132)], [8,7,(242,134,132)], [9,7,(242,134,132)], [10,7,(242,134,132)], [11,7,(242,134,132)], [0,8,(184,25,38)], [1,8,(184,25,38)], [2,8,(184,25,38)], [3,8,(184,25,38)], [0,9,(184,25,38)], [1,9,(184,25,38)], [2,9,(184,25,38)], [3,9,(184,25,38)], [0,10,(184,25,38)], [1,10,(184,25,38)], [2,10,(184,25,38)], [3,10,(184,25,38)], [0,11,(184,25,38)], [1,11,(184,25,38)], [2,11,(184,25,38)], [3,11,(184,25,38)], [0,12,(184,25,38)], [1,12,(184,25,38)], [2,12,(184,25,38)], [3,12,(184,25,38)], [0,13,(163,26,36)], [1,13,(184,25,38)], [2,13,(163,26,36)], [3,13,(163,26,36)], [0,14,(163,26,36)], [1,14,(163,26,36)], [2,14,(163,26,36)], [3,14,(163,26,36)], [0,15,(229,196,187)], [1,15,(229,196,187)], [2,15,(155,121,112)], [3,15,(229,196,187)], [0,16,(155,121,112)], [1,16,(229,196,187)], [2,16,(229,196,187)], [3,16,(155,121,112)], [0,17,(245,119,126)], [1,17,(245,119,126)], [2,17,(245,119,126)], [3,17,(245,119,126)], [0,18,(245,119,126)], [1,18,(245,119,126)], [2,18,(245,119,126)], [3,18,(245,119,126)], [0,19,(245,119,126)], [1,19,(245,119,126)], [2,19,(245,119,126)], [3,19,(245,119,126)], [4,8,(195,31,48)], [4,9,(195,31,48)], [4,10,(195,31,48)], [4,11,(195,31,48)], [4,12,(195,31,48)], [4,13,(195,31,48)], [4,14,(195,31,48)], [5,8,(223,187,178)], [5,9,(195,31,48)], [5,10,(167,128,123)], [5,11,(167,128,123)], [5,12,(223,187,178)], [5,13,(223,187,178)], [5,14,(167,128,123)], [6,8,(167,128,123)], [6,9,(167,128,123)], [6,10,(223,187,178)], [6,11,(255,255,255)], [6,12,(255,255,255)], [6,13,(255,255,255)], [6,14,(255,255,255)], [7,8,(255,255,255)], [7,9,(255,255,255)], [7,10,(255,255,255)], [7,11,(255,255,255)], [7,12,(255,255,255)], [7,13,(255,255,255)], [7,14,(255,255,255)], [8,8,(255,255,255)], [8,9,(255,255,255)], [8,10,(252,207,4)], [8,11,(255,255,255)], [8,12,(252,207,4)], [8,13,(255,255,255)], [8,14,(252,207,4)], [9,8,(167,128,123)], [9,9,(223,187,178)], [9,10,(223,187,178)], [9,11,(255,255,255)], [9,12,(255,255,255)], [9,13,(255,255,255)], [9,14,(255,255,255)], [10,8,(202,27,44)], [10,9,(202,27,44)], [10,10,(223,187,178)], [10,11,(167,128,123)], [10,12,(223,187,178)], [10,13,(223,187,178)], [10,14,(167,128,123)], [11,8,(202,27,44)], [11,9,(202,27,44)], [11,10,(202,27,44)], [11,11,(202,27,44)], [11,12,(202,27,44)], [11,13,(223,187,178)], [11,14,(202,27,44)], [12,8,(184,25,38)], [13,8,(184,25,38)], [14,8,(184,25,38)], [15,8,(184,25,38)], [12,9,(184,25,38)], [13,9,(184,25,38)], [14,9,(184,25,38)], [15,9,(184,25,38)], [12,10,(184,25,38)], [13,10,(184,25,38)], [14,10,(184,25,38)], [15,10,(184,25,38)], [12,11,(184,25,38)], [13,11,(184,25,38)], [14,11,(184,25,38)], [15,11,(184,25,38)], [12,12,(184,25,38)], [13,12,(184,25,38)], [14,12,(184,25,38)], [15,12,(184,25,38)], [12,13,(163,26,36)], [13,13,(184,25,38)], [14,13,(163,26,36)], [15,13,(163,26,36)], [12,14,(163,26,36)], [13,14,(163,26,36)], [14,14,(163,26,36)], [15,14,(163,26,36)], [12,15,(229,196,187)], [13,15,(229,196,187)], [14,15,(155,121,112)], [15,15,(229,196,187)], [12,16,(155,121,112)], [13,16,(229,196,187)], [14,16,(229,196,187)], [15,16,(155,121,112)], [12,17,(245,119,126)], [13,17,(245,119,126)], [14,17,(245,119,126)], [15,17,(245,119,126)], [12,18,(245,119,126)], [13,18,(245,119,126)], [14,18,(245,119,126)], [15,18,(245,119,126)], [12,19,(245,119,126)], [13,19,(245,119,126)], [14,19,(245,119,126)], [15,19,(245,119,126)], [4,15,(223,187,178)], [5,15,(223,187,178)], [6,15,(255,255,255)], [7,15,(255,255,255)], [8,15,(255,255,255)], [9,15,(255,255,255)], [10,15,(167,128,123)], [11,15,(202,27,44)], [4,16,(202,27,44)], [5,16,(167,128,123)], [6,16,(247,34,56)], [7,16,(247,34,56)], [8,16,(247,34,56)], [9,16,(247,34,56)], [10,16,(223,187,178)], [11,16,(202,27,44)], [4,17,(202,27,44)], [5,17,(245,119,126)], [6,17,(247,34,56)], [7,17,(247,34,56)], [8,17,(247,34,56)], [9,17,(247,34,56)], [10,17,(245,119,126)], [11,17,(202,27,44)], [4,18,(245,119,126)], [5,18,(167,128,123)], [6,18,(247,34,56)], [7,18,(247,34,56)], [8,18,(247,34,56)], [9,18,(247,34,56)], [10,18,(167,128,123)], [4,19,(157,20,30)], [5,19,(157,20,30)], [6,19,(157,20,30)], [7,19,(157,20,30)], [8,19,(157,20,30)], [9,19,(157,20,30)], [10,19,(157,20,30)], [11,19,(157,20,30)], [4,20,(157,20,30)], [5,20,(157,20,30)], [6,20,(157,20,30)], [7,20,(157,20,30)], [8,20,(157,20,30)], [9,20,(157,20,30)], [10,20,(157,20,30)], [11,20,(157,20,30)], [4,21,(47,32,29)], [5,21,(47,32,29)], [6,21,(47,32,29)], [7,21,(47,32,29)], [8,21,(47,32,29)], [9,21,(47,32,29)], [10,21,(47,32,29)], [11,21,(47,32,29)], [4,22,(47,32,29)], [5,22,(161,128,119)], [6,22,(47,32,29)], [7,22,(161,128,119)], [8,22,(161,128,119)], [9,22,(47,32,29)], [10,22,(161,128,119)], [11,22,(47,32,29)], [4,23,(97,80,73)], [5,23,(47,32,29)], [6,23,(97,80,73)], [7,23,(47,32,29)], [8,23,(47,32,29)], [9,23,(97,80,73)], [10,23,(47,32,29)], [11,23,(97,80,73)], [4,24,(47,32,29)], [5,24,(97,80,73)], [6,24,(47,32,29)], [7,24,(97,80,73)], [8,24,(97,80,73)], [9,24,(47,32,29)], [10,24,(97,80,73)], [11,24,(47,32,29)], [4,25,(47,32,29)], [5,25,(47,32,29)], [6,25,(47,32,29)], [7,25,(47,32,29)], [8,25,(47,32,29)], [9,25,(47,32,29)], [10,25,(47,32,29)], [11,25,(47,32,29)], [4,26,(47,32,29)], [5,26,(47,32,29)], [6,26,(47,32,29)], [7,26,(47,32,29)], [8,26,(47,32,29)], [9,26,(47,32,29)], [10,26,(47,32,29)], [11,26,(47,32,29)], [4,27,(29,25,24)], [5,27,(29,25,24)], [6,27,(29,25,24)], [7,27,(29,25,24)], [8,27,(29,25,24)], [9,27,(29,25,24)], [10,27,(29,25,24)], [11,27,(29,25,24)], [4,28,(0,0,0)], [5,28,(0,0,0)], [6,28,(0,0,0)], [7,28,(0,0,0)], [8,28,(0,0,0)], [9,28,(0,0,0)], [10,28,(0,0,0)], [11,28,(0,0,0)], ]
我们要的坐标轴是x向右递增,y向下递增,但是y坐标和turtle的坐标轴反了,所以,在遍历并绘制的时候,y坐标这一项要求出相反数
导入Turtle模块,因为我们使用的是rgb,所以要先把colormode设置为255,然后加速,sx和sy表示起始坐标,这个可以自行设定,接下来遍历并绘制即可!最后别忘了隐藏画笔并保持窗口显示!
from turtle import * colormode(255) speed(0) W=20 sx,sy=-150,250 for x,y,(r,g,b) in POS: x2,y2=x*W+sx,(-y)*W+sy pu() goto(x2,y2) pd() color((r,g,b)) begin_fill() for i in range(4): fd(W) right(90) end_fill() ht() done()
加载全部内容