用Python代码画出海绵宝宝
会代码的依古比古
编辑于 2023年04月23日 04:55

简介

用Python代码画出海绵宝宝,仅仅使用turtle库,先来上一波绘图结果:

绘画过程可以观看UP主视频:快速用代码画出海绵宝宝,挺简单的嘛​

代码

代码块
Python
自动换行
复制代码
# coding=gbk

import turtle

def plotLine(points, pencolor=None, width=None, speed=None):
    '''
    功能:画折线
    参数:
    - points : 一系列点,用列表或元组表示
    - pencolor : 画笔颜色,默认不变
    - width : 画笔宽度,默认不变
    - speed : 绘制速度,默认不变
    '''
    # 记录旧参数
    oldpencolor = turtle.pencolor()
    oldwidth = turtle.width()
    oldspeed = turtle.speed()

    # 修改新参数
    if pencolor is not None:
        turtle.pencolor(pencolor)
    if width is not None:
        turtle.width(width)
    if speed is not None:
        turtle.speed(speed)
    
    # 绘制折线
    turtle.up()
    turtle.goto(points[0])
    turtle.down()
    for point in points[1:]:
        turtle.goto(point)
    
    # 恢复旧参数
    turtle.pencolor(oldpencolor)
    turtle.width(oldwidth)
    turtle.speed(oldspeed)


def plotPoly(points, fill=False, pencolor=None, fillcolor=None,
             width=None, speed=None):
    '''
    功能:绘制封闭多边形
    '''
    # 保存旧参数
    oldfillcolor = turtle.fillcolor()

    # 更新新参数
    if fillcolor is not None:
        turtle.fillcolor(fillcolor)

    # 绘制封闭多边形
    points_plotline = list(points) + [points[0]]
    if fill:
        turtle.begin_fill()
        plotLine(points_plotline, pencolor, width, speed)
        turtle.end_fill()
    else:
        plotLine(points_plotline, pencolor, width, speed)

    # 恢复旧参数
    turtle.fillcolor(oldfillcolor)

# 设置一些参数
turtle.setup(600, 559, 50, 50)
turtle.speed(10)
turtle.turtlesize(1.5, 1.5, 1.5)

# 绘画

# 脸部轮廓
points = [
    (-139, 267), (-144, 265), (-148, 264), (-152, 260), (-156, 255), 
    (-160, 247), (-163, 232), (-162, 226), (-162, 221), (-163, 215), 
    (-165, 207), (-172, 191), (-176, 178), (-181, 163), (-182, 156), 
    (-183, 150), (-181, 142), (-181, 132), (-181, 120), (-181, 112), 
    (-184, 103), (-188, 96), (-190, 89), (-192, 84), (-195, 76), 
    (-196, 73), (-197, 58), (-197, 47), (-195, 35), (-195, 22), 
    (-196, 10), (-197, 1), (-199, -5), (-200, -9), (-200, -20), 
    (-198, -27), (-196, -35), (-195, -45), (-195, -55), (-196, -62), 
    (-197, -70), (-197, -77), (-196, -81), (-193, -86), (-189, -89), 
    (-185, -90), (-178, -92), (-170, -94), (-153, -94), (-149, -96), 
    (-143, -99), (-138, -102), (-134, -105), (-129, -106), (-119, -107), 
    (-104, -107), (-94, -108), (-87, -108), (-80, -111), (-71, -117), 
    (-64, -119), (-49, -121), (-33, -122), (-23, -123), (-15, -125), 
    (-8, -128), (0, -132), (7, -135), (15, -137), (24, -137), 
    (35, -138), (40, -140), (57, -145), (60, -146), (66, -147), 
    (71, -147), (76, -146), (83, -143), (91, -139), (97, -138), 
    (116, -141), (144, -139), (147, -131), (152, -111), (154, -106), 
    (156, -103), (156, -79), (156, -75), (159, -71), (164, -63), 
    (168, -57), (170, -52), (171, -44), (172, -23), (173, -18), 
    (175, -14), (182, -7), (190, 2), (194, 9), (197, 15), 
    (199, 24), (201, 39), (204, 47), (208, 53), (215, 57), 
    (222, 61), (225, 66), (228, 74), (231, 87), (233, 95), 
    (236, 99), (242, 105), (247, 109), (249, 113), (253, 118), 
    (255, 123), (255, 127), (253, 132), (250, 135), (245, 139), 
    (241, 143), (239, 147), (237, 150), (236, 157), (235, 160), 
    (233, 163), (230, 166), (227, 168), (222, 170), (216, 175), 
    (214, 179), (211, 185), (211, 193), (209, 198), (205, 204), 
    (202, 207), (198, 209), (171, 209), (166, 209), (161, 212), 
    (154, 217), (148, 220), (142, 222), (136, 223), (128, 223), 
    (120, 221), (114, 220), (107, 222), (100, 223), (95, 225), 
    (76, 234), (70, 237), (65, 238), (55, 238), (37, 238), 
    (33, 239), (23, 242), (12, 245), (5, 246), (-4, 245), 
    (-14, 244), (-22, 242), (-29, 242), (-38, 244), (-44, 247), 
    (-52, 251), (-57, 254), (-62, 257), (-71, 258), (-95, 258), 
    (-100, 258), (-105, 258), (-111, 262), (-117, 264), (-127, 267), 
    ]
plotPoly(points, True, pencolor=(0.55, 0.56, 0.1),
         fillcolor=(1.0, 0.96, 0.34), width=5)

# 脸部线条
points = [
    (199, 208), (199, 201), (199, 193), (198, 190), (195, 185), 
    (191, 178), (186, 172), (180, 166), (174, 161), (169, 155), 
    (166, 149), (165, 144), (163, 128), (162, 121), (161, 117), 
    (158, 111), (154, 105), (152, 101), (150, 99), (146, 95), 
    (142, 91), (138, 87), (136, 84), (135, 79), (135, 72), 
    (134, 65), (134, 57), (133, 53), (132, 49), (130, 45), 
    (126, 40), (123, 36), (118, 31), (113, 27), (110, 22), 
    (107, 18), (105, 12), (106, 6), (106, 0), (106, -6), 
    (105, -14), (104, -18), (100, -24), (96, -29), (92, -35), 
    (89, -41), (87, -45), (85, -49), (85, -58), (86, -70), 
    (85, -81), (84, -87), (82, -92), (80, -96), (77, -101), 
    (75, -105), (72, -109), (71, -112), (71, -129), (71, -134), 
    (69, -138), (68, -140), (66, -142), (63, -144), (61, -145), 
    ]
plotLine(points, pencolor=(0.55, 0.56, 0.1), width=4)

# 脸部斑点
points = [
    (-129, 238), (-134, 237), (-139, 235), (-143, 231), (-145, 226), 
    (-147, 221), (-147, 213), (-145, 208), (-142, 204), (-139, 202), 
    (-136, 202), (-131, 203), (-127, 206), (-123, 210), (-121, 215), 
    (-119, 220), (-118, 224), (-118, 226), (-119, 229), (-121, 232), 
    (-123, 235), (-126, 237), 
    ]
plotPoly(points, True, pencolor=(0.66, 0.73, 0.15),
         fillcolor=(0.66, 0.73, 0.15), width=1)

# 脸部斑点
points = [
    (-149, 189), (-151, 190), (-154, 190), (-157, 188), (-160, 185), 
    (-162, 181), (-163, 178), (-163, 170), (-161, 168), (-159, 166), 
    (-154, 165), (-150, 167), (-148, 170), (-146, 174), (-144, 177), 
    (-145, 184), (-147, 187), 
    ]
plotPoly(points, True, pencolor=(0.66, 0.73, 0.15),
         fillcolor=(0.66, 0.73, 0.15), width=1)

# 脸部斑点
points = [
    (147, 195), (143, 196), (140, 195), (136, 193), (132, 191), 
    (129, 186), (127, 181), (125, 177), (125, 171), (127, 165), 
    (130, 160), (134, 158), (138, 156), (143, 155), (148, 156), 
    (152, 160), (155, 165), (156, 170), (157, 177), (156, 183), 
    (154, 188), (151, 192), 
    ]
plotPoly(points, True, pencolor=(0.66, 0.73, 0.15),
         fillcolor=(0.66, 0.73, 0.15), width=1)

# 脸部斑点
points = [
    (-154, 21), (-159, 20), (-164, 18), (-168, 14), (-172, 10), 
    (-175, 5), (-176, 1), (-176, -6), (-174, -12), (-171, -17), 
    (-167, -20), (-163, -22), (-157, -23), (-154, -22), (-149, -19), 
    (-145, -15), (-142, -10), (-141, -4), (-141, 3), (-142, 8), 
    (-143, 13), (-146, 16), (-149, 19), 
    ]
plotPoly(points, True, pencolor=(0.66, 0.73, 0.15),
         fillcolor=(0.66, 0.73, 0.15), width=1)

# 脸部斑点
points = [
    (-147, -43), (-151, -43), (-155, -46), (-159, -50), (-162, -54), 
    (-164, -59), (-164, -64), (-161, -69), (-156, -71), (-150, -71), 
    (-145, -68), (-141, -64), (-140, -58), (-139, -54), (-140, -49), 
    (-143, -45), 
    ]
plotPoly(points, True, pencolor=(0.66, 0.73, 0.15),
         fillcolor=(0.66, 0.73, 0.15), width=1)

# 脸部斑点
points = [
    (65, -24), (59, -24), (56, -26), (52, -29), (50, -34), 
    (49, -38), (50, -44), (52, -49), (55, -51), (58, -52), 
    (62, -51), (66, -48), (69, -44), (71, -40), (71, -33), 
    (69, -28), 
    ]
plotPoly(points, True, pencolor=(0.66, 0.73, 0.15),
         fillcolor=(0.66, 0.73, 0.15), width=1)

# 脸部斑点
points = [
    (42, -66), (38, -67), (32, -71), (28, -75), (26, -80), 
    (24, -85), (24, -94), (26, -101), (28, -106), (31, -109), 
    (34, -111), (38, -112), (45, -111), (51, -107), (55, -102), 
    (57, -96), (58, -89), (59, -82), (57, -76), (54, -71), 
    (52, -69), (47, -67), 
    ]
plotPoly(points, True, pencolor=(0.66, 0.73, 0.15),
         fillcolor=(0.66, 0.73, 0.15), width=1)

# 脸旁斑点
points = [
    (204, 160), (195, 160), (191, 157), (187, 153), (184, 148), 
    (182, 143), (182, 137), (183, 131), (184, 124), (186, 119), 
    (189, 116), (193, 112), (198, 110), (204, 109), (210, 111), 
    (215, 114), (218, 119), (220, 126), (220, 133), (219, 141), 
    (217, 148), (214, 153), (210, 157), 
    ]
plotPoly(points, True, pencolor=(0.57, 0.57, 0.01),
         fillcolor=(0.57, 0.57, 0.01), width=1)

# 脸旁斑点
points = [
    (187, 88), (183, 87), (180, 85), (177, 81), (175, 76), 
    (176, 70), (178, 64), (181, 59), (185, 57), (190, 57), 
    (194, 60), (197, 64), (199, 69), (199, 73), (199, 76), 
    (197, 80), (194, 84), (191, 86), 
    ]
plotPoly(points, True, pencolor=(0.57, 0.57, 0.01),
         fillcolor=(0.57, 0.57, 0.01), width=1)

# 脸旁斑点
points = [
    (145, 47), (150, 46), (156, 44), (160, 41), (163, 37), 
    (164, 32), (166, 26), (166, 18), (165, 12), (164, 7), 
    (161, 3), (158, -1), (155, -3), (147, -3), (142, 0), 
    (137, 4), (134, 11), (132, 20), (133, 28), (135, 35), 
    (139, 41), (142, 44), 
    ]
plotPoly(points, True, pencolor=(0.57, 0.57, 0.01),
         fillcolor=(0.57, 0.57, 0.01), width=1)

# 脸旁斑点
points = [
    (136, -23), (141, -24), (145, -27), (147, -30), (148, -34), 
    (148, -38), (147, -42), (145, -45), (143, -47), (139, -47), 
    (136, -44), (133, -41), (131, -36), (130, -31), (132, -26), 
    ]
plotPoly(points, True, pencolor=(0.57, 0.57, 0.01),
         fillcolor=(0.57, 0.57, 0.01), width=1)

# 嘴巴
points = [
    (-85, 17), (-95, -13), (-103, -33), (-107, -46), (-108, -51), 
    (-108, -56), (-105, -60), (-99, -67), (-93, -70), (-86, -74), 
    (-76, -78), (-64, -82), (-51, -83), (-35, -83), (-27, -81), 
    (-21, -79), (-14, -75), (-3, -67), (9, -56), (19, -44), 
    (29, -29), (39, -12), (48, 7), (53, 23), (60, 38), 
    (56, 40), (51, 37), (43, 30), (33, 25), (20, 20), 
    (10, 16), (-3, 13), (-19, 11), (-35, 10), (-53, 11), 
    (-67, 13), (-76, 15), 
    ]
plotPoly(points, True, pencolor=(0.05, 0.0, 0.05),
         fillcolor=(0.54, 0.12, 0.02), width=4)

# 舌头
points = [
    (-98, -66), (-93, -59), (-88, -53), (-82, -49), (-76, -46), 
    (-69, -44), (-62, -43), (-53, -44), (-45, -46), (-38, -48), 
    (-33, -50), (-31, -52), (-26, -49), (-20, -47), (-14, -46), 
    (-8, -45), (-1, -46), (5, -48), (11, -52), (6, -59), 
    (-2, -65), (-9, -71), (-18, -77), (-25, -81), (-30, -82), 
    (-39, -84), (-55, -83), (-67, -81), (-78, -78), (-86, -74), 
    (-92, -71), 
    ]
plotPoly(points, True, pencolor=(0.02, 0.03, 0.06),
         fillcolor=(0.95, 0.61, 0.55), width=4)

# 舌头
points = [
    (-33, -51), (-36, -54), (-38, -56), (-40, -58), (-43, -61), 
    (-45, -64), (-47, -67), (-43, -64), (-41, -62), (-39, -60), 
    (-36, -58), (-32, -55), (-29, -53), (-28, -52), (-26, -50), 
    (-30, -51), 
    ]
plotPoly(points, True, pencolor=(0.02, 0.03, 0.06),
         fillcolor=(0.02, 0.03, 0.06), width=0)

# 牙齿
points = [
    (-101, 22), (-112, -6), (-98, -13), (-92, -15), (-86, -16), 
    (-81, -17), (-77, -17), (-73, -5), (-70, 6), (-69, 13), 
    (-74, 14), (-80, 15), (-86, 17), (-91, 19), (-96, 21), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(1.0, 1.0, 1.0), width=4)

# 牙齿
points = [
    (-53, 11), (-58, -16), (-58, -18), (-54, -20), (-43, -23), 
    (-30, -25), (-23, -26), (-20, -20), (-18, -11), (-17, -1), 
    (-17, 10), (-24, 10), (-31, 10), (-41, 10), (-48, 10), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(1.0, 1.0, 1.0), width=4)

# 鼻子
points = [
    (-99, 22), (-107, 26), (-117, 32), (-127, 39), (-136, 46), 
    (-143, 52), (-145, 53), (-145, 54), 
    ]
plotLine(points, pencolor=(0.0, 0.0, 0.02), width=4)

# 鼻子
points = [
    (-145, 54), (-144, 55), (-138, 55), (-124, 56), (-115, 57), 
    ]
plotLine(points, pencolor=(0.0, 0.0, 0.02), width=2)

# 鼻子
points = [
    (-56, 49), (-67, 48), (-80, 48), (-92, 50), (-103, 53), 
    (-114, 58), (-123, 63), (-131, 69), (-141, 76), (-149, 84), 
    (-154, 90), (-158, 99), (-160, 106), (-160, 114), (-159, 116), 
    (-158, 118), (-156, 120), (-154, 121), (-151, 122), (-141, 122), 
    (-138, 121), (-135, 120), (-133, 119), (-129, 116), (-123, 111), 
    (-117, 105), (-111, 99), (-104, 93), (-95, 86), (-87, 81), 
    (-79, 77), (-71, 73), (-63, 71), (-56, 69), (-52, 68), 
    ]
plotLine(points, pencolor=(0.0, 0.0, 0.02), width=4)

# 右眼
points = [
    (-71, 198), (-83, 198), (-93, 196), (-102, 194), (-112, 189), 
    (-118, 184), (-123, 179), (-129, 173), (-134, 165), (-138, 157), 
    (-141, 149), (-143, 140), (-143, 133), (-143, 123), (-140, 122), 
    (-137, 121), (-135, 120), (-131, 118), (-126, 113), (-118, 106), 
    (-113, 101), (-106, 95), (-99, 89), (-91, 84), (-78, 76), 
    (-67, 72), (-61, 70), (-57, 70), (-54, 72), (-49, 75), 
    (-44, 78), (-39, 81), (-35, 84), (-28, 92), (-23, 99), 
    (-19, 110), (-16, 122), (-15, 134), (-15, 143), (-16, 154), 
    (-19, 162), (-24, 170), (-31, 179), (-38, 186), (-46, 190), 
    (-53, 194), (-60, 196), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(1.0, 1.0, 1.0), width=3)

# 右眼珠
points = [
    (-69, 155), (-76, 155), (-82, 153), (-87, 150), (-91, 145), 
    (-93, 140), (-94, 135), (-95, 129), (-93, 123), (-89, 118), 
    (-86, 115), (-82, 112), (-78, 111), (-69, 111), (-63, 112), 
    (-59, 115), (-55, 119), (-52, 123), (-50, 129), (-49, 134), 
    (-50, 139), (-53, 144), (-57, 149), (-62, 153), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.01, 0.63, 0.82), width=3)

# 右眼珠
points = [
    (-71, 145), (-76, 144), (-79, 142), (-82, 139), (-84, 135), 
    (-84, 131), (-82, 126), (-79, 123), (-76, 121), (-72, 120), 
    (-67, 121), (-63, 124), (-61, 127), (-60, 130), (-60, 135), 
    (-61, 138), (-63, 141), (-66, 143), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 右眼睫毛
points = [
    (-97, 196), (-101, 214), (-101, 215), (-95, 217), (-93, 217), 
    (-91, 198), (-91, 197), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 右眼睫毛
points = [
    (-62, 197), (-59, 215), (-53, 215), (-52, 214), (-52, 213), 
    (-57, 196), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 右眼睫毛
points = [
    (-35, 184), (-24, 199), (-23, 199), (-19, 195), (-32, 180), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 左眼
points = [
    (30, 171), (19, 171), (9, 168), (-1, 164), (-8, 160), 
    (-15, 154), (-21, 148), (-27, 140), (-32, 132), (-35, 123), 
    (-37, 115), (-38, 108), (-37, 97), (-36, 89), (-32, 80), 
    (-28, 72), (-22, 63), (-16, 57), (-11, 52), (-2, 47), 
    (8, 43), (17, 40), (25, 40), (35, 40), (47, 43), 
    (58, 47), (67, 52), (74, 59), (81, 68), (86, 79), 
    (90, 89), (92, 102), (92, 115), (89, 128), (84, 138), 
    (77, 148), (72, 154), (62, 162), (51, 167), (42, 170), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(1.0, 1.0, 1.0), width=4)

# 左眼珠
points = [
    (25, 133), (19, 132), (13, 129), (9, 126), (6, 122), 
    (4, 117), (3, 111), (3, 103), (6, 97), (10, 93), 
    (15, 90), (20, 88), (25, 87), (33, 89), (39, 93), 
    (44, 99), (47, 107), (47, 115), (45, 120), (41, 125), 
    (38, 129), (33, 131), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.06, 0.65, 0.88), width=4)

# 左眼珠
points = [
    (27, 124), (21, 123), (18, 121), (16, 119), (14, 116), 
    (13, 111), (15, 104), (17, 101), (20, 99), (25, 98), 
    (31, 99), (35, 102), (37, 106), (38, 111), (36, 117), 
    (34, 120), (31, 122), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 左眼睫毛
points = [
    (11, 170), (8, 188), (13, 189), (16, 171), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 左眼睫毛
points = [
    (45, 170), (50, 187), (51, 187), (57, 186), (57, 186), 
    (50, 168), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 左眼睫毛
points = [
    (72, 155), (82, 170), (83, 170), (87, 166), (87, 165), 
    (74, 151), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=1)

# 脸上疙瘩
points = [
    (40, 36), (37, 43), (37, 50), (38, 56), (42, 62), 
    (49, 67), (56, 70), (65, 70), (72, 68), (78, 64), 
    (80, 62), (77, 56), (75, 53), (69, 47), (64, 44), 
    (59, 43), (54, 42), (50, 40), (46, 38), 
    ]
plotPoly(points, True, pencolor=(1.0, 0.96, 0.34),
         fillcolor=(1.0, 0.96, 0.34), width=0)

# 脸上疙瘩
points = [
    (50, 43), (52, 43), (56, 41), (61, 38), (64, 36), 
    (66, 34), (68, 32), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.0, 0.0, 0.02), width=2)

# 脸上疙瘩
points = [
    (40, 35), (37, 40), (36, 48), (37, 53), (39, 59), 
    (43, 64), (46, 66), (52, 69), (58, 70), (66, 70), 
    (71, 68), (76, 65), (81, 62), (86, 57), (89, 53), 
    (92, 48), (94, 42), (93, 35), (90, 28), (87, 24), 
    (83, 20), (77, 17), (73, 16), (66, 16), 
    ]
plotLine(points, pencolor=(0.83, 0.37, 0.21), width=4)

# 脸上疙瘩
points = [
    (64, 48), (65, 49), (69, 49), (70, 48), (70, 43), 
    (67, 45), (66, 46), 
    ]
plotPoly(points, True, pencolor=(0.83, 0.37, 0.21),
         fillcolor=(0.83, 0.37, 0.21), width=0)

# 脸上疙瘩
points = [
    (62, 61), (63, 62), (64, 63), (66, 63), (68, 61), 
    (69, 60), (69, 57), (68, 57), (65, 58), (63, 59), 
    (62, 60), 
    ]
plotPoly(points, True, pencolor=(0.83, 0.37, 0.21),
         fillcolor=(0.83, 0.37, 0.21), width=0)

# 脸上疙瘩
points = [
    (78, 51), (78, 52), (79, 53), (81, 52), (83, 50), 
    (84, 47), (83, 45), (82, 45), (80, 47), (79, 49), 
    (78, 50), 
    ]
plotPoly(points, True, pencolor=(0.83, 0.37, 0.21),
         fillcolor=(0.83, 0.37, 0.21), width=0)

# 裤子
points = [
    (-186, -121), (64, -176), (61, -223), (-182, -165), (-185, -146), 
    (-186, -140), 
    ]
plotPoly(points, True, pencolor=(0.02, 0.0, 0.01),
         fillcolor=(0.84, 0.55, 0.2), width=3)

# 裤子
points = [
    (64, -176), (143, -161), (143, -197), (64, -224), 
    ]
plotPoly(points, True, pencolor=(0.04, 0.02, 0.02),
         fillcolor=(0.61, 0.35, 0.03), width=2)

# 裤子
points = [
    (-189, -93), (-188, -117), (-187, -144), (-183, -167), (58, -225), 
    (64, -225), (143, -196), (143, -137), 
    ]
plotLine(points, pencolor=(0.04, 0.02, 0.02), width=6)

# 裤子
points = [
    (65, -149), (62, -223), 
    ]
plotLine(points, pencolor=(0.04, 0.02, 0.02), width=5)

# 右袖子
points = [
    (-198, -42), (-203, -51), (-207, -61), (-210, -72), (-212, -81), 
    (-212, -87), (-209, -92), (-203, -98), (-197, -102), (-190, -103), 
    ]
plotLine(points, pencolor=(0.02, 0.0, 0.01), width=5)

# 左袖子
points = [
    (128, -83), (122, -85), (117, -91), (113, -98), (109, -106), 
    (106, -117), (104, -128), (103, -139), (103, -146), (106, -150), 
    (115, -154), (124, -156), (134, -155), (144, -151), (151, -146), 
    (152, -136), (150, -124), (147, -110), (141, -94), (138, -86), 
    (133, -84), 
    ]
plotPoly(points, True, pencolor=(0.06, 0.06, 0.07),
         fillcolor=(1.0, 1.0, 1.0), width=5)

# 右手轮廓
points = [
    (-185, -159), (-190, -160), (-193, -162), (-195, -167), (-198, -173), 
    (-199, -180), (-200, -193), (-204, -198), (-207, -202), (-208, -205), 
    (-207, -207), (-205, -210), (-201, -211), (-196, -211), (-195, -215), 
    (-193, -220), (-191, -226), (-188, -230), (-184, -232), (-180, -232), 
    (-178, -230), (-176, -233), (-172, -235), (-169, -235), (-166, -234), 
    (-163, -231), (-159, -226), (-156, -223), (-153, -221), (-153, -217), 
    (-153, -210), (-156, -203), (-158, -198), (-158, -190), (-155, -175), 
    (-183, -167), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.01, 0.0),
         fillcolor=(1.0, 0.96, 0.33), width=5)

# 右手指
points = [
    (-184, -188), (-185, -193), (-187, -198), (-189, -203), (-191, -206), 
    (-194, -209), (-196, -211), 
    ]
plotLine(points, pencolor=(0.02, 0.0, 0.0), width=4)

# 右手指
points = [
    (-178, -231), (-177, -227), (-176, -223), (-177, -219), (-179, -213), 
    (-180, -207), (-180, -204), (-180, -201), (-175, -198), (-171, -196), 
    (-166, -196), (-168, -197), (-168, -202), (-168, -206), (-166, -210), 
    (-163, -216), (-161, -220), (-160, -227), 
    ]
plotLine(points, pencolor=(0.05, 0.06, 0.11), width=4)

# 左手臂和手轮廓
points = [
    (120, -155), (125, -156), (130, -156), (134, -156), (132, -191), 
    (130, -217), (131, -220), (133, -223), (136, -226), (139, -231), 
    (142, -236), (144, -242), (145, -250), (146, -272), (145, -277), 
    (144, -281), (103, -281), (105, -278), (107, -273), (107, -268), 
    (107, -262), (105, -260), (103, -259), (100, -261), (94, -264), 
    (90, -267), (87, -267), (84, -266), (81, -264), (80, -260), 
    (82, -258), (85, -254), (91, -252), (95, -248), (97, -243), 
    (99, -238), (100, -233), (102, -231), (105, -228), (109, -227), 
    (113, -225), (115, -223), (116, -219), (117, -209), (119, -181), 
    ]
plotPoly(points, True, pencolor=(0.01, 0.0, 0.0),
         fillcolor=(1.0, 0.96, 0.33), width=5)

# 左手指
points = [
    (121, -281), (122, -277), (123, -272), (124, -267), (124, -261), 
    ]
plotLine(points, pencolor=(0.01, 0.0, 0.0), width=4)

# 左手指
points = [
    (132, -281), (133, -277), (134, -271), (134, -265), (134, -260), 
    ]
plotLine(points, pencolor=(0.01, 0.0, 0.0), width=4)

# 右裤腿
points = [
    (-131, -181), (-132, -200), (-119, -206), (-104, -208), (-86, -208), 
    (-75, -206), (-67, -203), (-62, -198), (-88, -191), (-112, -185), 
    ]
plotPoly(points, True, pencolor=(0.01, 0.0, 0.0),
         fillcolor=(0.8, 0.56, 0.18), width=5)

# 左裤腿
points = [
    (-6, -210), (-9, -226), (-6, -230), (8, -234), (24, -237), 
    (41, -237), (50, -234), (58, -230), (60, -226), 
    ]
plotPoly(points, True, pencolor=(0.04, 0.05, 0.08),
         fillcolor=(0.82, 0.56, 0.15), width=5)

# 右腿
points = [
    (-104, -208), (-96, -208), (-90, -207), (-86, -226), (-84, -248), 
    (-91, -250), (-97, -250), (-101, -250), (-102, -234), (-104, -217), 
    (-105, -210), 
    ]
plotPoly(points, True, pencolor=(0.02, 0.02, 0.04),
         fillcolor=(0.99, 0.95, 0.36), width=4)

# 右袜子
points = [
    (-100, -250), (-84, -248), (-80, -281), (-99, -282), (-100, -265), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.03, 0.02),
         fillcolor=(0.98, 0.98, 0.98), width=4)

# 右袜子
points = [
    (-98, -260), (-83, -260), 
    ]
plotPoly(points, True, pencolor=(0.39, 0.46, 0.49),
         fillcolor=(0.39, 0.46, 0.49), width=2)

# 右袜子
points = [
    (-98, -271), (-83, -271), 
    ]
plotLine(points, pencolor=(0.86, 0.31, 0.24), width=4)

# 左腿
points = [
    (18, -236), (28, -237), (37, -237), (40, -255), (40, -268), 
    (31, -269), (22, -269), (19, -248), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.01, 0.02),
         fillcolor=(1.0, 0.93, 0.42), width=4)

# 左袜子
points = [
    (22, -269), (33, -269), (40, -268), (40, -281), (22, -281), 
    ]
plotPoly(points, True, pencolor=(0.04, 0.03, 0.04),
         fillcolor=(0.98, 0.98, 0.98), width=4)

# 裤子上的黑条
points = [
    (-171, -137), (-137, -143), (-138, -154), (-171, -148), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.01, 0.0),
         fillcolor=(0.0, 0.01, 0.0), width=0)

# 裤子上的黑条
points = [
    (-120, -148), (-85, -155), (-87, -165), (-121, -158), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.01, 0.0),
         fillcolor=(0.0, 0.01, 0.0), width=0)

# 裤子上的黑条
points = [
    (-63, -158), (-64, -170), (-26, -177), (-25, -167), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.01, 0.0),
         fillcolor=(0.0, 0.01, 0.0), width=0)

# 裤子上的黑条
points = [
    (-2, -172), (-2, -183), (47, -194), (47, -181), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.01, 0.0),
         fillcolor=(0.0, 0.01, 0.0), width=0)

# 裤子上的黑条
points = [
    (91, -181), (91, -194), (118, -186), (118, -175), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.01, 0.0),
         fillcolor=(0.0, 0.01, 0.0), width=0)

# 领带
points = [
    (-130, -109), (-120, -121), (-117, -126), (-110, -121), (-103, -116), 
    (-95, -112), 
    ]
plotLine(points, pencolor=(0.0, 0.01, 0.0), width=3)

# 领带
points = [
    (-47, -125), (-32, -144), (-18, -140), (-5, -134), 
    ]
plotLine(points, pencolor=(0.0, 0.01, 0.0), width=3)

# 领带
points = [
    (-92, -111), (-90, -110), (-87, -111), (-81, -113), (-77, -116), 
    (-74, -119), (-69, -120), (-63, -121), (-57, -123), (-55, -124), 
    (-58, -128), (-61, -132), (-64, -134), (-67, -137), (-75, -137), 
    (-78, -135), (-83, -132), (-85, -126), (-88, -120), (-89, -117), 
    (-91, -115), 
    ]
plotPoly(points, True, pencolor=(0.98, 0.25, 0.17),
         fillcolor=(0.98, 0.25, 0.17), width=0)

# 领带
points = [
    (-94, -112), (-92, -114), (-89, -120), (-87, -125), (-84, -131), 
    (-82, -134), (-79, -136), (-73, -137), (-67, -137), (-64, -136), 
    (-60, -131), (-56, -127), (-53, -124), 
    ]
plotLine(points, pencolor=(0.0, 0.0, 0.02), width=3)

# 领带
points = [
    (-82, -135), (-82, -139), (-84, -144), (-85, -149), (-86, -153), 
    (-88, -157), (-90, -161), (-93, -166), (-94, -169), (-94, -170), 
    (-92, -173), (-86, -180), (-81, -186), (-77, -190), (-73, -187), 
    (-68, -184), (-62, -180), (-57, -176), (-58, -175), (-59, -168), 
    (-61, -159), (-63, -149), (-65, -140), (-66, -137), (-69, -137), 
    (-73, -137), (-75, -137), (-78, -136), (-80, -135), 
    ]
plotPoly(points, True, pencolor=(0.0, 0.0, 0.02),
         fillcolor=(0.98, 0.25, 0.17), width=3)

# 隐藏海龟
turtle.hideturtle()
turtle.done() 
复制成功

运行效果

备注

视频可以在这里观看:快速用代码画出海绵宝宝,挺简单的嘛​

关注UP主可以及时获取最新消息!