这难道是用python实现的灰太狼?

picture.image

点击上方“蓝字”关注我们了解更多精彩

我一定会回来的!!

picture.image

系列文章

picture.image

序号文章目录直达链接
表白系列
1浪漫520表白代码无限弹窗!满屏表白代码来啦,快来看看吧
2满屏表白代码Python满屏表白代码
3跳动的爱心Python跳动的爱心源码
4漂浮爱心Python漂浮爱心源码
5爱心光波Python爱心光波代码
6流星雨Python流星雨源码
7玫瑰花叮咚,您的玫瑰花已送达~
节日系列
1生日快乐Python生日蛋糕代码
2圣诞节Python圣诞树源码
3中秋节中秋佳节将至,一起来赏月吧
4国庆节目光所至皆华夏,五星闪耀为信仰
5儿童节让代码创造童话,共建快乐世界
6万圣节终于要到我这只可爱鬼的节日啦!
7新年快乐Python烟花秀源码
动漫系列
1柯南真相只有一个!名侦探柯南来袭~
2皮卡丘我用python实现了三只可爱的皮卡丘!
3hellokitty粉红色限定丨你好我是HelloKitty!
4小灰灰谁会拒绝一只呆萌的小灰灰呢~
5喜羊羊我用python实现了一只呆萌的喜羊羊!
6Tom&Jerry汤姆永远抓不到杰瑞,我们的故事永远不会结束
7懒羊羊教你用python实现一只可爱的懒羊羊!
其他
1满天星Python星星源码
2雪花(2022)Python雪花源码‍
3雪花(2023)这个冬天让我们用python送她一场飘雪吧!
4模拟星空Python模拟星空代码
5樱花树樱花树下的约定,是承诺也是青春
6七彩花朵Python七彩花朵代码
7恶搞代码Python恶搞代码
8代码雨三十行代码教你实现《黑客帝国》炫酷代码雨
9蝙蝠代码万圣节特辑(一)丨 一只蝙蝠的诞生!
10南瓜头万圣节特辑(二)丨 你好恶魔南瓜头!

picture.image

写在前面

picture.image

picture.image

“我一定会回来的!”是多少人的童年吖,继小灰灰、喜羊羊和懒羊羊后,小编用python实现了一只灰太狼送给大家,一起来看看吧!

picture.image

1

Python是什么?

Python是一种高级编程语言,由Guido van Rossum于1989年创建。Python是一种动态语言,它具有面向对象、函数式编程和结构化编程的特性。Python是一种解释性语言,这意味着在执行时不需要先进行编译。Python的使用广泛,它在数据科学、机器学习、人工智能、Web开发、自动化和科学计算等领域都有广泛应用。Python的语法简单易学,具有高度可读性和可维护性。同时,Python还拥有丰富的标准库和第三方库,可以简化编程并提高效率。

2

Turtle是什么?

Turtle是Python语言中的一个绘图库,它可以通过编程语言来控制一个小海龟(turtle),让它在屏幕上绘制图形。Turtle这个名字来源于英语中的“海龟”(turtle),因为这个绘图库就像一个小海龟,在屏幕上“爬行”并绘制图形。使用Turtle库可以实现各种图形的绘制,例如线条,圆形,矩形,多边形等形状。同时,它还可以实现复杂的图像绘制,例如螺旋线、太阳花等。Turtle库最初是Logo语言中的一个组件,Logo语言是一种教育性编程语言,旨在帮助儿童学习编程。现在,Turtle已经成为Python语言中最受欢迎的绘图库之一,尤其适合用于学生的计算机图形学习。

picture.image

Turtle怎么用

picture.image

picture.image

使用Turtle库,我们可以在Python程序中轻松地绘制图形。下面是一个简单的示例程序,演示如何使用Turtle库绘制一个正方形:

import turtle# 创建一个画布canvas = turtle.Screen()# 创建一个画笔pen = turtle.Turtle()# 绘制正方形for i in range(4): pen.forward(100) pen.left(90)# 关闭画布canvas.exitonclick()  
  

picture.image

运行这个程序,会弹出一个窗口,显示绘制的正方形。上述程序中,import turtle语句导入了Turtle库,canvas = turtle.Screen()语句创建了一个画布,pen = turtle.Turtle()语句创建了一个画笔(也就是一个小海龟),pen.forward(100)pen.left(90)语句用于控制小海龟移动和旋转,从而绘制出正方形。最后,canvas.exitonclick()语句用于关闭画布。

picture.image

除了绘制正方形,Turtle库还可以绘制许多其他形状,例如圆形、矩形、三角形、星形等等。要了解更多关于Turtle库的用法和绘制方法,可以查看Turtle库的文档或者相关的Python编程教程。

picture.image

绘制灰太狼

picture.image

picture.image

完整程序

picture.image

# coding=gbkimport turtleturtle.setup(0.7, 0.7, None, 100) # 调整画布大小turtle.title("灰太狼")t = turtle.Turtle()t.screen.delay(0)t.hideturtle()def plotLine(points, pencolor=None, width=None, speed=None): oldpencolor = t.pencolor() oldwidth = t.width() oldspeed = t.speed() if pencolor is not None: t.pencolor(pencolor) if width is not None: t.width(width) if speed is not None: t.speed(speed) t.up() t.goto(points[0]) t.down() for point in points[1:]: t.goto(point) t.pencolor(oldpencolor) t.width(oldwidth) t.speed(oldspeed)def plotPoly(points, fill=False, pencolor=None, fillcolor=None, width=None, speed=None): oldfillcolor = t.fillcolor() if fillcolor is not None: t.fillcolor(fillcolor) points_plotline = list(points) + [points[0]] if fill: t.begin_fill() plotLine(points_plotline, pencolor, width, speed) t.end_fill() else: plotLine(points_plotline, pencolor, width, speed) t.fillcolor(oldfillcolor)# 轮廓points = [ (-116, 152), (-132, 159), (-147, 166), (-163, 172), (-183, 179), (-200, 183), (-218, 187), (-242, 192), (-255, 194), (-264, 194), (-272, 195), (-268, 187), (-262, 173), (-258, 163), (-252, 149), (-249, 140), (-243, 127), (-239, 116), (-235, 106), (-230, 94), (-225, 83), (-219, 70), (-215, 58), (-210, 47), (-206, 38), (-203, 31), (-203, 30), (-206, 30), (-214, 24), (-220, 18), (-227, 11), (-234, 4), (-239, -2), (-245, -9), (-250, -17), (-256, -26), (-261, -37), (-266, -47), (-269, -56), (-272, -63), (-275, -73), (-278, -82), (-281, -91), (-274, -91), (-266, -91), (-260, -92), (-251, -95), (-244, -97), (-240, -101), (-239, -105), (-240, -109), (-243, -114), (-247, -118), (-250, -121), (-243, -122), (-232, -124), (-220, -127), (-210, -129), (-200, -132), (-192, -135), (-188, -136), (-186, -137), (-185, -141), (-182, -150), (-179, -160), (-175, -168), (-171, -177), (-165, -186), (-160, -193), (-157, -197), (-152, -203), (-146, -209), (-139, -216), (-132, -221), (-125, -226), (-120, -230), (-121, -238), (-123, -248), (-124, -257), (-124, -264), (-123, -272), (-122, -279), (-121, -286), (-121, -292), (171, -293), (176, -288), (183, -282), (190, -275), (196, -269), (199, -266), (202, -261), (203, -257), (202, -252), (197, -247), (189, -239), (181, -232), (173, -226), (168, -222), (176, -214), (185, -206), (195, -196), (203, -186), (211, -174), (217, -162), (220, -150), (224, -141), (224, -134), (230, -132), (237, -127), (245, -123), (253, -120), (262, -116), (274, -112), (284, -109), (292, -107), (301, -105), (297, -103), (292, -97), (289, -94), (289, -89), (289, -86), (293, -82), (301, -79), (309, -76), (319, -74), (329, -73), (328, -67), (324, -58), (319, -48), (315, -37), (308, -26), (303, -17), (295, -5), (285, 7), (275, 18), (265, 27), (255, 35), (245, 43), (245, 47), (247, 51), (250, 59), (254, 70), (257, 78), (259, 86), (259, 88), (254, 90), (247, 96), (245, 103), (245, 110), (247, 115), (251, 119), (255, 122), (259, 123), (266, 123), (270, 122), (271, 121), (273, 126), (276, 136), (279, 147), (284, 161), (288, 172), (291, 182), (295, 195), (299, 205), (302, 214), (290, 213), (280, 211), (267, 208), (251, 204), (236, 199), (220, 193), (204, 187), (191, 182), (173, 173), (160, 167), (149, 160), (138, 155), (124, 146), (110, 143), (87, 144), (53, 146), (31, 146), (0, 146), (-27, 146), (-54, 145), (-78, 140), (-96, 137), (-104, 145), (-116, 152),]plotPoly(points, True, pencolor=(0.03, 0.0, 0.0), fillcolor=(0.38, 0.39, 0.38), width=2)# 帽子points = [ (-115, 152), (-122, 145), (-128, 137), (-134, 129), (-139, 120), (-144, 112), (-146, 106), (-146, 100), (-143, 93), (-140, 90), (-134, 86), (-126, 83), (-119, 83), (-104, 83), (-91, 85), (-71, 88), (-51, 92), (-27, 96), (-7, 100), (14, 104), (40, 110), (63, 115), (87, 120), (103, 124), (112, 127), (118, 130), (124, 133), (129, 138), (133, 144), (137, 152), (138, 161), (138, 171), (136, 180), (132, 190), (122, 205), (111, 215), (100, 223), (88, 227), (78, 230), (65, 231), (46, 231), (31, 229), (16, 226), (0, 222), (-9, 219), (-22, 214), (-41, 207), (-55, 200), (-67, 193), (-73, 187), (-83, 181), (-91, 175), (-98, 169), (-107, 160),]plotPoly(points, True, pencolor=(0.13, 0.01, 0.0), fillcolor=(0.87, 0.4, 0.18), width=1)# 帽子points = [ (-141, 116), (-144, 111), (-145, 106), (-145, 100), (-143, 95), (-138, 90), (-134, 88), (-131, 86), (-127, 85), (-122, 84), (-114, 84), (-107, 84), (-102, 85), (-95, 86), (-86, 87), (-78, 88), (-70, 89), (-63, 90), (-59, 91), (-53, 92), (-46, 93), (-36, 95), (-27, 97), (-15, 99), (-2, 101), (9, 104), (21, 107), (35, 110), (49, 113), (62, 116), (72, 118), (85, 121), (95, 123), (111, 127), (117, 129), (121, 132), (125, 135), (128, 138), (131, 142), (133, 146), (135, 150), (136, 154), (136, 158), (136, 162), (136, 167), (136, 171), (136, 175), (135, 177), (133, 170), (130, 165), (127, 161), (124, 158), (120, 155), (116, 152), (110, 149), (105, 147), (101, 146), (97, 145), (92, 144), (87, 143), (83, 142), (79, 141), (74, 140), (68, 138), (59, 136), (53, 134), (48, 133), (40, 131), (35, 130), (27, 128), (17, 126), (7, 124), (1, 122), (-9, 120), (-16, 118), (-23, 116), (-31, 114), (-40, 112), (-49, 110), (-61, 107), (-66, 106), (-74, 104), (-83, 102), (-91, 101), (-96, 100), (-104, 100), (-114, 100), (-119, 101), (-123, 102), (-127, 104), (-131, 106), (-134, 109), (-136, 111), (-137, 113), (-138, 114), (-139, 116),]plotPoly(points, True, pencolor=(0.95, 0.64, 0.55), fillcolor=(0.95, 0.64, 0.55), width=1)# 帽子points = [ (-133, 126), (-136, 123), (-138, 120), (-140, 116), (-137, 111), (-134, 108), (-131, 106), (-129, 104), (-127, 103), (-124, 101), (-119, 100), (-112, 100), (-104, 100), (-98, 100), (-89, 101), (-84, 102), (-78, 103), (-69, 105), (-60, 107), (-52, 109), (-43, 111), (-35, 113), (-27, 115), (-20, 117), (-13, 119), (-6, 121), (4, 123), (11, 125), (17, 126), (23, 128), (31, 129), (36, 130), (41, 132), (50, 134), (57, 136), (65, 137), (72, 139), (79, 141), (87, 143), (92, 144), (100, 146), (108, 148), (115, 151), (119, 153), (123, 156), (127, 160), (130, 164), (132, 167), (133, 170), (135, 173), (135, 178), (135, 182), (133, 185), (132, 187), (130, 188), (128, 187), (125, 186), (120, 183), (115, 180), (110, 177), (107, 174), (103, 170), (95, 165), (88, 161), (82, 158), (75, 154), (68, 151), (62, 149), (56, 146), (48, 143), (42, 141), (35, 138), (26, 135), (18, 133), (9, 130), (1, 128), (-9, 125), (-19, 122), (-29, 119), (-38, 117), (-46, 115), (-56, 113), (-64, 111), (-73, 110), (-77, 109), (-83, 108), (-88, 107), (-95, 107), (-106, 107), (-114, 108), (-120, 110), (-124, 111), (-128, 115), (-130, 118), (-132, 122),]plotPoly(points, True, pencolor=(0.67, 0.26, 0.09), fillcolor=(0.67, 0.26, 0.09), width=2)# 帽子points = [ (14, 226), (8, 220), (2, 215), (-3, 209), (-7, 204), (-12, 200), (-17, 195), (-21, 191), (-16, 192), (-8, 193), (-1, 194), (13, 194), (28, 194), (35, 194), (45, 192), (54, 191), (62, 188), (69, 185), (76, 182), (83, 178), (87, 174), (90, 169), (95, 173), (101, 177), (107, 181), (114, 184), (123, 187), (129, 188), (132, 189), (127, 198), (122, 204), (116, 210), (110, 216), (102, 220), (95, 224), (87, 227), (80, 230), (68, 231), (53, 231), (42, 230), (32, 229), (27, 228), (19, 227),]plotPoly(points, True, pencolor=(0.03, 0.09, 0.06), fillcolor=(1.0, 0.86, 0.5), width=2)# 帽子上针线points = [ (-5, 214), (3, 215), (11, 215), (15, 216),]plotLine(points, pencolor=(0.3, 0.18, 0.0), width=2)#points = [ (-21, 203), (-11, 204), (1, 205),]plotLine(points, pencolor=(0.17, 0.12, 0.0), width=2)#points = [ (9, 201), (4, 196), (-1, 192), (-6, 188), (-7, 188),]plotLine(points, pencolor=(0.4, 0.0, 0.0), width=2)#points = [ (20, 200), (18, 196), (15, 192), (13, 189),]plotLine(points, pencolor=(0.29, 0.0, 0.0), width=2)#points = [ (36, 200), (34, 195), (31, 191), (30, 187),]plotLine(points, pencolor=(0.42, 0.04, 0.0), width=2)#points = [ (53, 198), (50, 193), (47, 190), (45, 185),]plotLine(points, pencolor=(0.6, 0.17, 0.01), width=2)#points = [ (68, 193), (66, 189), (63, 185), (61, 181),]plotLine(points, pencolor=(0.42, 0.02, 0.0), width=2)#points = [ (83, 189), (81, 184), (79, 179), (76, 172),]plotLine(points, pencolor=(0.44, 0.04, 0.0), width=2)#points = [ (95, 185), (103, 178), (111, 169),]plotLine(points, pencolor=(0.41, 0.07, 0.0), width=2)#points = [ (110, 191), (119, 186), (129, 178),]plotLine(points, pencolor=(0.26, 0.1, 0.0), width=2)# 下巴曲线points = [ (-120, -230), (-112, -235), (-105, -239), (-96, -244), (-85, -248), (-75, -252), (-63, -257), (-52, -259), (-40, -262), (-27, -265), (-19, -267), (-9, -268), (3, -269), (17, -270), (30, -270), (48, -268), (62, -266), (70, -265), (76, -264), (85, -262), (90, -261), (99, -258), (112, -254), (121, -250), (130, -246), (138, -241), (147, -237), (153, -233), (159, -228), (164, -224), (170, -220),]plotLine(points, pencolor=(0.1, 0.07, 0.03), width=2)# 围巾points = [ (-25, -266), (-19, -269), (-11, -273), (-3, -277), (6, -280), (16, -284), (25, -287), (31, -288), (35, -289), (36, -289), (40, -287), (44, -285), (48, -283), (52, -280), (57, -277), (62, -274), (66, -271), (70, -269), (76, -265), (75, -264), (72, -265), (68, -265), (62, -266), (57, -267), (51, -267), (46, -268), (41, -269), (34, -269), (26, -270), (10, -270), (-1, -269), (-6, -268), (-11, -267), (-16, -267), (-21, -266),]plotPoly(points, True, pencolor=(0.05, 0.05, 0.04), fillcolor=(0.97, 0.9, 0.63), width=2)# 右胳膊points = [ (-89, -247), (-89, -267), (-89, -271), (-91, -271), (-90, -276), (-90, -281), (-89, -286), (-89, -291),]plotLine(points, pencolor=(0.04, 0.04, 0.04), width=2)# 左胳膊points = [ (145, -238), (146, -245), (146, -253), (146, -260), (145, -269), (146, -276), (145, -282), (145, -287), (144, -291),]plotLine(points, pencolor=(0.02, 0.02, 0.02), width=2)#points = [ (146, -248), (149, -248), (152, -251), (156, -255), (162, -260), (156, -264), (152, -268), (148, -271), (146, -271), (146, -258),]plotPoly(points, True, pencolor=(0.03, 0.0, 0.0), fillcolor=(1, 1, 1), width=2)#points = [ (177, -246), (173, -250), (169, -253), (164, -258), (160, -261),]plotLine(points, pencolor=(0.09, 0.06, 0.03), width=2)# 右耳points = [ (-271, 195), (-266, 181), (-262, 172), (-255, 156), (-250, 142), (-245, 131), (-241, 121), (-236, 110), (-231, 97), (-225, 82), (-218, 65), (-211, 51), (-205, 36), (-204, 32), (-203, 29), (-201, 31), (-200, 34), (-199, 35), (-198, 37), (-195, 36), (-190, 36), (-193, 38), (-196, 41), (-196, 42), (-193, 43), (-181, 43), (-182, 46), (-184, 49), (-185, 50), (-185, 51), (-177, 51), (-170, 50), (-167, 48), (-169, 52), (-173, 59), (-178, 67), (-183, 74), (-189, 84), (-194, 92), (-200, 102), (-206, 110), (-213, 120), (-220, 129), (-228, 140), (-234, 149), (-242, 159), (-248, 167), (-254, 174), (-259, 180), (-263, 185),]plotPoly(points, True, pencolor=(0.0, 0.0, 0.01), fillcolor=(0.6, 0.6, 0.61), width=2)# 左耳points = [ (301, 214), (296, 208), (289, 197), (281, 186), (274, 176), (266, 163), (259, 152), (251, 139), (243, 126), (235, 112), (227, 96), (220, 82), (214, 72), (209, 63), (209, 61), (213, 62), (217, 64), (226, 65), (226, 63), (222, 59), (223, 58), (236, 58), (239, 57), (237, 55), (233, 51), (233, 50), (242, 51), (243, 49), (244, 48), (246, 47), (250, 57), (254, 72), (259, 84), (259, 86), (259, 88), (254, 89), (250, 93), (247, 96), (245, 101), (244, 105), (245, 110), (246, 114), (250, 118), (254, 121), (258, 123), (264, 124), (268, 123), (271, 122), (273, 129), (276, 138), (280, 150), (283, 160), (286, 169), (291, 182), (294, 193), (298, 202), (300, 208),]plotPoly(points, True, pencolor=(0.02, 0.05, 0.06), fillcolor=(0.6, 0.6, 0.61), width=2)# 右眼points = [ (-124, 21), (-134, 14), (-142, 5), (-149, -6), (-154, -18), (-156, -29), (-157, -38), (-155, -50), (-150, -65), (-140, -79), (-128, -90), (-113, -98), (-102, -102), (-86, -103), (-71, -102), (-56, -97), (-43, -89), (-30, -78), (-21, -63), (-16, -47), (-15, -34), (-18, -19), (-23, -5), (-30, 5), (-37, 13), (-45, 19), (-54, 23), (-65, 27), (-78, 30), (-92, 30), (-105, 28), (-115, 26),]plotPoly(points, True, pencolor=(0.01, 0.01, 0.01), fillcolor=(1.0, 1.0, 1.0), width=2)t.up()t.goto((-50, -47))t.down()t.pencolor((0.0, 0.0, 0.01))t.dot(20)# 左眼points = [ (114, 25), (96, 22), (83, 17), (74, 12), (65, 5), (57, -4), (51, -14), (47, -26), (44, -38), (45, -52), (49, -66), (56, -79), (64, -90), (76, -99), (88, -106), (102, -110), (115, -111), (129, -110), (142, -106), (153, -100), (164, -91), (173, -81), (181, -70), (186, -54), (186, -42), (184, -28), (176, -10), (167, 2), (157, 12), (148, 17), (135, 22), (125, 24),]plotPoly(points, True, pencolor=(0.04, 0.04, 0.04), fillcolor=(0.99, 0.99, 0.99), width=2)t.up()t.goto((143, -50))t.down()t.pencolor((0.01, 0.01, 0.02))t.dot(20)# 右眉points = [ (-146, 66), (-146, 58), (-147, 50), (-147, 42),]plotLine(points, pencolor=(0.08, 0.08, 0.08), width=3)# 右眉points = [ (-139, 61), (-140, 54), (-141, 46), (-142, 38),]plotLine(points, pencolor=(0.08, 0.08, 0.08), width=3)# 右眉points = [ (-136, 56), (-137, 45), (-138, 36), (-138, 33), (-134, 28), (-129, 25), (-125, 22), (-118, 19), (-111, 16), (-106, 14), (-99, 13), (-88, 12), (-75, 12), (-66, 13), (-58, 15), (-52, 17), (-47, 20), (-41, 22), (-35, 26), (-30, 31), (-25, 36), (-21, 41), (-18, 45), (-17, 47), (-17, 48), (-19, 51), (-21, 54), (-22, 56), (-23, 56), (-27, 53), (-33, 50), (-39, 47), (-45, 44), (-51, 42), (-57, 40), (-62, 39), (-70, 37), (-77, 37), (-87, 37), (-95, 38), (-105, 40), (-112, 42), (-120, 45), (-127, 49), (-131, 51), (-134, 54),]plotPoly(points, True, pencolor=(0.0, 0.02, 0.01), fillcolor=(0.0, 0.02, 0.01), width=2)# 左眉points = [ (47, 82), (47, 81), (52, 73), (53, 73), (58, 76), (65, 79), (73, 82), (79, 84), (87, 86), (94, 87), (106, 88), (118, 87), (129, 85), (137, 83), (144, 80), (152, 76), (159, 72), (163, 68), (166, 64), (167, 68), (168, 73), (169, 79), (170, 85), (170, 89), (166, 93), (161, 98), (155, 102), (149, 105), (142, 108), (131, 111), (125, 112), (110, 113), (95, 112), (88, 111), (79, 108), (75, 106), (69, 103), (64, 100), (60, 97), (57, 94), (53, 90), (51, 87), (48, 84),]plotPoly(points, True, pencolor=(0.0, 0.0, 0.0), fillcolor=(0.0, 0.0, 0.0), width=2)# 左眉points = [ (174, 83), (172, 73), (170, 65), (169, 59),]plotLine(points, pencolor=(0.04, 0.04, 0.04), width=3)#points = [ (178, 77), (177, 70), (176, 62), (175, 54),]plotLine(points, pencolor=(0.08, 0.08, 0.08), width=3)# 鼻子points = [ (15, -80), (1, -81), (-11, -83), (-18, -85), (-24, -88), (-28, -91), (-32, -96), (-35, -101), (-37, -107), (-36, -115), (-33, -121), (-28, -125), (-21, -129), (-13, -132), (-4, -134), (8, -135), (17, -135), (28, -134), (39, -131), (46, -129), (55, -123), (61, -116), (63, -109), (62, -100), (58, -93), (51, -88), (43, -84), (35, -81), (27, -80),]plotPoly(points, True, pencolor=(0.0, 0.0, 0.0), fillcolor=(0.0, 0.0, 0.0), width=2)# 鼻子points = [ (-17, -90), (-23, -91), (-27, -93), (-29, -95), (-30, -97), (-31, -99), (-30, -103), (-26, -106), (-22, -108), (-14, -108), (-10, -107), (-7, -105), (-4, -102), (-4, -98), (-5, -95), (-7, -93), (-11, -91),]plotPoly(points, True, pencolor=(1.0, 1.0, 1.0), fillcolor=(1.0, 1.0, 1.0), width=2)# 鼻涕points = [ (30, -135), (30, -141), (29, -149), (28, -157), (28, -164), (30, -168), (33, -171), (36, -172), (38, -171), (40, -169), (42, -166), (42, -158), (42, -151), (40, -146), (39, -139), (39, -134), (39, -131), (35, -132), (33, -133),]plotPoly(points, True, pencolor=(0.17, 0.19, 0.19), fillcolor=(0.86, 0.98, 1.0), width=2)# 嘴巴points = [ (-51, -200), (-63, -203), (-71, -206), (-75, -208), (-77, -210), (-77, -213), (-75, -215), (-71, -217), (-66, -218), (-59, -219), (-49, -220), (-38, -220), (-14, -220), (27, -219), (53, -219), (84, -218), (104, -217), (117, -215), (126, -213), (132, -211), (135, -209), (136, -207), (136, -205), (133, -202), (128, -200), (120, -198), (113, -197), (104, -195), (96, -194), (88, -193), (68, -192), (43, -192), (15, -193), (0, -194), (-10, -195), (-23, -196), (-31, -197), (-40, -198), (-44, -199),]plotPoly(points, True, pencolor=(0.15, 0.07, 0.05), fillcolor=(0.99, 0.69, 0.59), width=2)# 牙齿points = [ (-51, -208), (-57, -217), (-58, -219), (-58, -220), (-52, -221), (-48, -221), (-43, -221), (-43, -220), (-43, -219), (-44, -217),]plotPoly(points, True, pencolor=(0.22, 0.06, 0.04), fillcolor=(0.99, 0.96, 0.89), width=2)#points = [ (102, -216), (103, -213), (109, -201), (117, -212), (118, -214), (118, -215), (115, -215), (112, -216), (108, -216),]plotPoly(points, True, pencolor=(0.05, 0.04, 0.04), fillcolor=(1.0, 0.99, 0.98), width=2)#points = [ (93, -194), (101, -194), (109, -196), (116, -197), (124, -199), (130, -200), (134, -203), (135, -205), (135, -208), (133, -210), (131, -211), (129, -212), (127, -213), (124, -213), (124, -211), (121, -208), (117, -205), (113, -203), (109, -201), (104, -199), (99, -197),]plotPoly(points, True, pencolor=(0.12, 0.05, 0.0), fillcolor=(0.33, 0.14, 0.15), width=2)# 疤痕points = [ (-189, -35), (-169, -85), (-158, -114), (-147, -142), (-132, -177), (-124, -199),]plotLine(points, pencolor=(0.03, 0.04, 0.04), width=2)# 疤痕points = [ (-158, -62), (-169, -67), (-177, -71), (-183, -75), (-190, -77),]plotLine(points, pencolor=(0.03, 0.04, 0.04), width=2)#points = [ (-153, -90), (-164, -96), (-173, -101), (-179, -104),]plotLine(points, pencolor=(0.02, 0.02, 0.02), width=2)# 疤痕points = [ (-147, -113), (-172, -126),]plotLine(points, pencolor=(0.03, 0.04, 0.04), width=2)#points = [ (-140, -133), (-148, -138), (-157, -143),]plotLine(points, pencolor=(0.04, 0.04, 0.04), width=2)#points = [ (-129, -159), (-141, -164), (-154, -169),]plotLine(points, pencolor=(0.0, 0.0, 0.01), width=2)#points = [ (-126, -176), (-138, -181),]plotLine(points, pencolor=(0.06, 0.06, 0.06), width=2)# 胡子points = [ (-146, -191), (-157, -197), (-170, -203), (-189, -211),]plotLine(points, pencolor=(0.03, 0.04, 0.04), width=2)# 胡子points = [ (-121, -217), (-126, -224), (-132, -227), (-138, -229), (-148, -229),]plotLine(points, pencolor=(0.03, 0.04, 0.04), width=2)#points = [ (-96, -237), (-100, -242), (-104, -247), (-110, -252),]plotLine(points, pencolor=(0.0, 0.0, 0.0), width=2)#points = [ (-55, -248), (-56, -251), (-58, -257), (-60, -263), (-61, -270), (-62, -276), (-62, -280),]plotLine(points, pencolor=(0.05, 0.05, 0.05), width=2)#points = [ (-20, -259), (-20, -265), (-21, -269), (-21, -276), (-21, -288), (-21, -291),]plotLine(points, pencolor=(0.02, 0.02, 0.04), width=2)#points = [ (37, -259), (37, -268), (38, -276), (38, -279),]plotLine(points, pencolor=(0.0, 0.0, 0.0), width=2)#points = [ (55, -264), (58, -270), (59, -275), (59, -279),]plotLine(points, pencolor=(0.0, 0.0, 0.0), width=2)#points = [ (75, -244), (80, -253), (86, -264), (92, -274), (99, -286),]plotLine(points, pencolor=(0.04, 0.04, 0.04), width=2)#points = [ (107, -246), (108, -256), (109, -264),]plotLine(points, pencolor=(0.02, 0.02, 0.04), width=2)#points = [ (142, -228), (150, -236), (157, -244), (159, -251),]plotLine(points, pencolor=(0.02, 0.02, 0.04), width=2)#points = [ (163, -217), (167, -221), (170, -225), (172, -231),]plotLine(points, pencolor=(0.02, 0.02, 0.04), width=2)#points = [ (179, -196), (188, -201), (196, -206), (206, -212),]plotLine(points, pencolor=(0.02, 0.02, 0.04), width=2)#points = [ (198, -161), (208, -175), (215, -183), (220, -189), (227, -198), (232, -203),]plotLine(points, pencolor=(0.02, 0.02, 0.04), width=2)turtle.mainloop()  
  

picture.image

程序分析

picture.image

picture.image

这是一段使用Turtle模块画出灰太狼的Python代码。

picture.image

picture.image

  1. 导入turtle模块:这个模块是Python中的一个标准库,用于绘制图形和动画等。

picture.image

  1. 调整画布大小:通过调用setup函数来设置画布的大小,第一个参数是画布宽度占整个屏幕宽度的比例,第二个参数是画布高度占整个屏幕高度的比例,第三个参数是设置画布的起始坐标,这里设置为None表示起始坐标为画布中心,第四个参数是设置画布的缩放因子。

picture.image

  1. 设置窗口标题:通过调用title函数来设置窗口标题。

picture.image

  1. 创建Turtle对象:通过调用Turtle函数来创建一个Turtle对象,这个对象可以用来绘制图形。

picture.image

  1. 关闭动画效果:通过调用screen对象的delay函数来关闭动画效果,即绘制的图形不再是逐渐显示的,而是直接显示出来。

picture.image

  1. 隐藏画笔:通过调用hideturtle函数来隐藏画笔,即绘制的图形不会显示出画笔的路径。

picture.image

  1. 开始绘制灰太狼。

picture.image

  1. 调用mainloop函数来保持窗口不断刷新(防止窗口关闭)。

picture.image

总体来说,这段代码利用Turtle模块提供的画图功能,结合绘图命令和控制画笔的函数来绘制出灰太狼的图形。

picture.image

运行结果

picture.image

picture.image

picture.image

写在后面

picture.image

picture.image

我是一只有趣的兔子,感谢你的喜欢!

0
0
0
0
评论
未登录
暂无评论