前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >休闲娱乐|手把手教你在Python中使用turtle模块实现二次元少女(一)

休闲娱乐|手把手教你在Python中使用turtle模块实现二次元少女(一)

原创
作者头像
Aion
发布2024-04-07 01:23:22
3525
发布2024-04-07 01:23:22
举报

前言

小假期悄然走去,选题的任务还未完成,趁着年轻活力的余热好好找找资料来梳理下。今天想要学习的Python语言中的 turtle模块 工具。

准备工作

  • 一台笔记本(随意了,能运行起来Python环境即可)
  • Python IDEA(我选择了 VS Code)
  • Python 环境(目前情况一般都是Pythonn3)
  • 安装turtle模块(我这里执行了 python -m pip install turtle)

其他问题可以查找资料获取。

关于turtle模块

turtle模块是Python的一个标准库,提供了一个绘图的海龟机器人,可以使用Python代码控制海龟机器人的移动动作,从而实现绘制图形的功能。该模块支持绘制直线、圆、椭圆、曲线、填充颜色等功能,可以用来绘制各种各样的图形和图案。turtle模块是一个功能强大且易于使用的绘图工具,无论是初学者还是经验丰富的Python开发者,都可以从中受益。

turtle库中有许多操纵海龟绘图的命令,这些命令大致可以划分为以下几种:画笔控制命令、画笔运动命令、全局控制命令,以及其他命令。具体的可以参考下:https://baike.baidu.com/item/turtle/50354923?fr=ge_ala

绘制说明

使用Python语言,借助turtle库工具,画一个二次元少女,使用傅立叶转换可以做到,加油,我也可以的。

起初,搜索了一些关于使用turtle库创作的图形或者图案,都不能满意,那就开始学习呗。在创建这幅俊俏的二次元少女图画时,将会利用turtle模块的一系列主要功能,这些功能包括:画线、绘制多边形以及一些参数设定。

  • 画线

画图时提供一个画线函数,主要参数有在哪里画线(线所在坐标)、画笔的颜色、画笔的宽度以及绘画的速度。

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

    # 修改新参数
    if pencolor is not None:
        te.pencolor(pencolor)
    if width is not None:
        te.width(width)
    if speed is not None:
        te.speed(speed)

    # 绘制折线
    te.up()
    te.goto(points[0])
    te.down()
    for point in points[1:]:
        te.goto(point)

    # 恢复旧参数
    te.pencolor(oldpencolor)
    te.width(oldwidth)
    te.speed(oldspeed)
  • 多边图形

画图时提供一个绘制多边形函数,主要参数有在哪里画线(线所在坐标)、是否填充多边形颜色、画笔的颜色、填充颜色、画笔的宽度以及绘画的速度。

代码语言:javascript
复制
def plotPoly(points, fill=False, pencolor=None, fillcolor=None,
             width=None, speed=None):
    '''
    功能:绘制封闭多边形
    参数:
    - points : 一系列点,用列表或元组表示
    - fill : 是否填充,默认不填充
    - pencolor : 画笔颜色,默认不变
    - fillcolor : 填充颜色,默认不变
    - width : 画笔宽度,默认不变
    - speed : 绘制速度,默认不变
    '''
    # 保存旧参数
    oldfillcolor = te.fillcolor()

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

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

    # 恢复旧参数
    te.fillcolor(oldfillcolor)
  • 其他参数设定

一些初始化参数以及海龟设定都可以在此处设定

代码语言:javascript
复制
# 初始化位置
te.setup(512, 724, 100, 30)
# 方向指示箭头位置
te.turtlesize(1.5, 1.5, 1.5)
# 初始化速度
te.speed(10)

# 隐藏海龟
te.hideturtle()
# 绘制完成(结束)
te.done()

绘制步骤

这些功能步骤包括:上面部分(头部、头发、脸部)、中间部分(绘制上衣、内搭、胳膊、手臂、手掌、手指)、下面部分(裙摆、丝袜、腿形)。下面从代码层面开始:

步骤一

首先,我们可以绘制中间部分(绘制上衣、内搭、胳膊、手臂、手掌、手指)

代码语言:javascript
复制
# 1、外套、内搭、胳膊、领带部分

# 外套轮廓
points = [
    (-26, 153), (-29, 152), (-30, 151), (-32, 148), (-36, 145), 
    (-41, 141), (-47, 136), (-54, 132), (-60, 128), (-67, 124), 
    (-76, 119), (-79, 116), (-82, 114), (-85, 109), (-87, 105), 
    (-90, 98), (-91, 91), (-92, 86), (-92, 82), (-93, 80), 
    (-95, 78), (-97, 76), (-100, 74), (-103, 71), (-106, 68), 
    (-107, 67), (-107, 60), (-108, 54), (-109, 47), (-109, 45), 
    (-112, 42), (-113, 41), (-114, 38), (-118, 33), (-121, 29), 
    (-123, 26), (-124, 25), (-127, 21), (-129, 18), (-133, 13), 
    (-136, 9), (-138, 6), (-141, 3), (-143, 0), (-146, -4), 
    (-149, -8), (-153, -13), (-156, -17), (-160, -22), (-161, -23), 
    (-162, -24), (-164, -27), (-168, -30), (-171, -32), (-172, -33), 
    (-173, -34), (-172, -37), (-171, -40), (-170, -43), (-169, -46), 
    (-168, -48), (-167, -52), (-166, -55), (-165, -58), (-164, -61), 
    (-163, -64), (-162, -67), (-161, -70), (-159, -77), (-158, -80), 
    (-157, -82), (-156, -84), (-154, -88), (-151, -93), (-148, -98), 
    (-144, -105), (-140, -111), (-137, -116), (-134, -120), (-130, -126), 
    (-127, -131), (-123, -136), (-119, -142), (-116, -146), (-113, -150), 
    (-112, -151), (-112, -152), (-111, -153), (-109, -153), (-107, -152), 
    (-106, -151), (-105, -154), (-103, -158), (-102, -160), (-99, -160), 
    (-95, -160), (-94, -162), (-93, -163), (-93, -163), (-94, -165), 
    (-94, -171), (-93, -175), (-92, -179), (-95, -188), (-98, -198), 
    (-102, -209), (-104, -216), (-105, -220), (-105, -227), (-104, -230), 
    (-102, -236), (-100, -239), (-97, -243), (-96, -238), (-95, -233), 
    (-94, -224), (-94, -217), (-93, -215), (-88, -211), (-82, -207), 
    (-76, -203), (-70, -199), (-67, -197), (-65, -194), (-64, -191), 
    (-63, -188), (-62, -181), (-61, -174), (-60, -166), (-59, -157), 
    (-58, -143), (-53, -139), (-48, -135), (-42, -130), (-37, -126), 
    (-33, -123), (-29, -120), (-25, -117), (-19, -113), (-13, -109), 
    (-7, -105), (-1, -101), (4, -98), (9, -95), (14, -92), 
    (18, -90), (19, -91), (19, -97), (20, -105), (21, -113), 
    (22, -121), (23, -129), (24, -136), (25, -138), (26, -140), 
    (31, -140), (35, -137), (39, -134), (42, -132), (45, -130), 
    (50, -127), (56, -123), (63, -119), (70, -115), (77, -111), 
    (86, -107), (91, -105), (95, -104), (98, -103), (104, -103), 
    (116, -103), (124, -105), (131, -108), (140, -112), (148, -116), 
    (153, -119), (159, -123), (163, -127), (167, -131), (171, -136), 
    (174, -140), (177, -144), (180, -147), (181, -144), (182, -140), 
    (182, -138), (181, -136), (177, -131), (173, -127), (169, -122), 
    (165, -117), (162, -113), (156, -105), (151, -99), (146, -93), 
    (140, -86), (134, -80), (129, -74), (123, -68), (118, -63), 
    (113, -58), (108, -53), (103, -46), (98, -40), (95, -36), 
    (93, -32), (92, -30), (91, -27), (89, -23), (87, -18), 
    (85, -11), (83, -2), (82, 4), (81, 12), (81, 21), 
    (81, 28), (82, 34), (83, 38), (84, 44), (86, 53), 
    (88, 62), (89, 66), (90, 70), (91, 74), (91, 77), 
    (96, 70), (102, 61), (107, 54), (109, 51), (110, 47), 
    (118, 39), (124, 33), (127, 31), (132, 25), (136, 19), 
    (140, 15), (144, 13), (148, 10), (153, 7), (159, 3), 
    (161, 2), (166, 2), (170, 3), (173, 4), (175, 7), 
    (177, 14), (180, 21), (183, 27), (186, 34), (189, 39), 
    (189, 46), (190, 50), (191, 54), (192, 57), (193, 60), 
    (194, 62), (194, 64), (193, 66), (192, 68), (189, 71), 
    (188, 73), (186, 75), (185, 76), (184, 79), (183, 84), 
    (182, 91), (181, 96), (180, 103), (179, 108), (178, 114), 
    (177, 119), (176, 126), (175, 132), (174, 139), (173, 146), 
    (172, 148), (170, 150), (167, 152), (164, 153), (161, 154), 
    (156, 154), (155, 155), (157, 158), (159, 161), (160, 169), 
    (160, 190), (159, 192), (159, 198), (156, 201), (153, 201), 
    (151, 199), (150, 199), (149, 203), (147, 205), (145, 206), 
    (140, 206), (138, 204), (137, 203), (136, 205), (135, 207), 
    (133, 209), (127, 209), (125, 208), (123, 206), (122, 206), 
    (121, 211), (120, 216), (118, 226), (116, 236), (114, 244), 
    (113, 248), (112, 252), (111, 254), (110, 256), (109, 258), 
    (106, 258), (104, 256), (103, 252), (103, 248), (104, 241), 
    (105, 235), (106, 231), (107, 226), (108, 217), (109, 208), 
    (110, 202), (111, 194), (111, 179), (110, 180), (108, 183), 
    (104, 188), (99, 195), (95, 199), (92, 203), (86, 205), 
    (79, 207), (73, 208), (67, 207), (59, 205), (54, 202), 
    (49, 199), (44, 196), (40, 193), (36, 189), (33, 187), 
    (30, 186), (26, 186), (22, 186), (17, 184), (15, 183), 
    (11, 180), (8, 177), (3, 172), (-3, 167), (-9, 163), 
    (-18, 157), (-20, 155), (-21, 152), (-22, 151), (-24, 152), 
    (-25, 153), (-26, 153), 
    ]
# plotPoly(points, True, pencolor=(0.09, 0.04, 0.09),
#          fillcolor=(0.82, 0.71, 0.61), width=2)
plotPoly(points, True, pencolor=(0.09, 0.04, 0.09),
         fillcolor=(0.38, 0.45, 0.52), width=2)

# 右胳膊细节
points = [
    (-105, -47), (-107, -41), (-108, -39), (-111, -37), (-117, -35), 
    (-122, -33), (-128, -32), (-124, -30), (-119, -28), (-112, -28), 
    (-105, -29), (-102, -30), (-99, -32), (-98, -33), (-97, -35), 
    (-97, -36), (-99, -37), (-100, -37), (-102, -36), (-101, -35), 
    (-100, -34), (-99, -32), (-100, -34), (-102, -37), (-103, -39), 
    (-104, -42), (-104, -46), (-104, -47), 
    ]
plotPoly(points, True, pencolor=(0.09, 0.04, 0.03),
         fillcolor=(0.6, 0.49, 0.44), width=2)

# 右袖子
points = [
    (-109, -147), (-107, -150), (-105, -154), (-103, -158), (-103, -159), 
    (-100, -157), (-97, -151), (-94, -146), (-91, -141), (-88, -136), 
    (-85, -133), (-83, -132), (-80, -133), (-79, -133), (-78, -132), 
    (-78, -129), (-77, -125), (-76, -121), (-76, -118), (-80, -117), 
    (-83, -116), (-85, -115), (-87, -115), (-90, -118), (-93, -121), 
    (-96, -125), (-99, -129), (-102, -133), (-105, -137), (-107, -141), 
    ]
plotPoly(points, True, pencolor=(0.13, 0.09, 0.09),
         fillcolor=(0.98, 1.0, 0.98), width=2)


# 右手
points = [
    (-99, -156), (-97, -158), (-95, -160), (-94, -162), (-94, -168), 
    (-94, -171), (-93, -176), (-92, -179), (-90, -173), (-89, -168), 
    (-88, -163), (-86, -157), (-84, -150), (-82, -144), (-80, -138), 
    (-79, -134), (-79, -133), (-82, -132), (-84, -132), (-85, -133), 
    (-89, -138), (-92, -142), (-95, -147), (-97, -151), (-98, -153), 
    ]
plotPoly(points, True, pencolor=(0.19, 0.15, 0.13),
         fillcolor=(1.0, 0.93, 0.9), width=2)

# 右胳膊
points = [
    (-75, -9), (-81, -14), (-86, -20), (-90, -26), (-93, -29), 
    (-96, -33), (-97, -35), (-97, -36), (-100, -37), (-102, -37), 
    (-104, -41), (-104, -44), (-104, -47), (-103, -50), (-102, -55), 
    (-99, -60), (-98, -64), (-94, -67), (-91, -71), (-89, -72), 
    (-89, -87), (-87, -89), (-85, -91), (-83, -94), (-81, -96), 
    (-79, -99), (-75, -103), (-73, -106), (-73, -94), (-72, -80), 
    (-72, -63), (-72, -51), (-73, -39), (-73, -31), (-74, -19), 
    (-75, -13), (-75, -10), 
    ]
plotPoly(points, True, pencolor=(0.18, 0.14, 0.11),
         fillcolor=(0.99, 0.99, 0.99), width=2)

# 左手
points = [
    (124, 137), (122, 142), (122, 145), (121, 149), (119, 149), 
    (116, 152), (113, 155), (110, 160), (108, 165), (107, 169), 
    (107, 174), (108, 176), (110, 178), (111, 181), (111, 185), 
    (111, 193), (110, 202), (109, 208), (108, 217), (107, 225), 
    (106, 231), (105, 236), (104, 242), (103, 252), (104, 255), 
    (105, 257), (106, 258), (108, 258), (110, 256), (111, 254), 
    (112, 252), (113, 248), (115, 240), (116, 236), (117, 230), 
    (118, 226), (119, 221), (120, 216), (121, 211), (122, 207), 
    (123, 206), (125, 208), (127, 209), (130, 210), (133, 209), 
    (135, 207), (136, 206), (137, 204), (139, 205), (141, 206), 
    (145, 206), (147, 205), (149, 203), (150, 200), (151, 199), 
    (152, 200), (154, 201), (156, 201), (157, 200), (158, 199), 
    (159, 197), (159, 194), (159, 192), (160, 191), (160, 188), 
    (160, 171), (159, 164), (159, 161), (158, 159), (157, 158), 
    (156, 156), (156, 152), (156, 147), (156, 144), (154, 141), 
    (152, 139), (150, 136), (148, 135), (147, 133), (145, 131), 
    (144, 130), (143, 129), (140, 127), (135, 128), (133, 129), 
    (131, 130), (128, 132), (124, 135), 
    ]
plotPoly(points, True, pencolor=(0.04, 0.04, 0.09),
         fillcolor=(1.0, 0.93, 0.9), width=2)

# 左手
points = [
    (117, 167), (121, 170), (124, 173), (125, 174), (129, 178), 
    (131, 181), (132, 184), (133, 186), (132, 190), (131, 191), 
    (130, 192), (129, 193), (127, 193), (125, 191), (122, 189), 
    (118, 185), (113, 181), (111, 179), (108, 177), (107, 175), 
    (106, 172), (107, 168), (109, 164), (111, 158), (115, 153), 
    (117, 151), (121, 149), (125, 148), (130, 149), (132, 150), 
    ]
plotLine(points, pencolor=(0.05, 0.05, 0.04), width=2)


# 袖子
points = [
    (112, 139), (114, 135), (115, 132), (116, 130), (116, 128), 
    (115, 128), (112, 130), (110, 131), (108, 132), (106, 133), 
    (106, 134), (108, 136), (110, 138), 
    ]
plotPoly(points, True, pencolor=(0.68, 0.57, 0.48),
         fillcolor=(0.59, 0.48, 0.39), width=1)

# 袖子
points = [
    (162, 151), (162, 146), (163, 141), (164, 136), (166, 138), 
    (168, 141), (169, 143), (170, 145), (170, 147), (168, 148), 
    (165, 150), 
    ]
plotPoly(points, True, pencolor=(0.68, 0.6, 0.55),
         fillcolor=(0.59, 0.48, 0.39), width=1)

# 袖子
points = [
    (172, 148), (170, 143), (168, 139), (165, 135), (162, 131), 
    (159, 127), (156, 124), (152, 119), (149, 116), (146, 114), 
    (143, 113), (140, 112), (136, 113), (133, 114), (129, 117), 
    (125, 119), (124, 120), (120, 123), (116, 126), (113, 128), 
    (110, 130), (108, 131), (105, 133), 
    ]
plotLine(points, pencolor=(0.03, 0.08, 0.02), width=1)

# 右胳膊线条
points = [
    (59, 202), (56, 198), (54, 195), (52, 191), (51, 189), 
    (50, 186), (49, 183), (48, 179), (47, 172), (46, 163), 
    (47, 155), (49, 149), (50, 145), (52, 140), (53, 139), 
    ]
plotLine(points, pencolor=(0.13, 0.18, 0.12), width=1)

# 
points = [
    (52, 147), (57, 137), (61, 129), (66, 119), (71, 111), 
    (76, 102), (82, 92), (85, 87), (90, 79), (94, 73), 
    ]
plotLine(points, pencolor=(0.13, 0.19, 0.19), width=2)

# 
points = [
    (48, 137), (52, 131), (54, 129), (58, 125), (62, 121), 
    (64, 119), (68, 115), 
    ]
plotLine(points, pencolor=(0.12, 0.11, 0.14), width=2)


# 衣服装饰
points = [
    (-77, 115), (-78, 111), (-79, 108), (-80, 102), 
    ]
plotLine(points, pencolor=(0.64, 0.56, 0.48), width=1)

# 
points = [
    (-77, 104), (-79, 100), (-82, 95), (-85, 91), (-88, 86), 
    (-91, 80), (-93, 76), (-95, 71), (-97, 67), (-98, 61), 
    (-99, 57), (-98, 51), (-97, 48), (-95, 42), (-92, 35), 
    (-88, 27), (-85, 22), (-81, 14), (-76, 8), (-76, -2), 
    (-75, -9), 
    ]
plotLine(points, pencolor=(0.12, 0.07, 0.03), width=2)

# 衣服装饰
points = [
    (-34, 145), (-35, 141), (-39, 133), (-42, 126), (-45, 119), 
    (-49, 112), (-51, 108), (-54, 103), (-57, 98), (-59, 94), 
    (-62, 88), (-66, 82), (-70, 77), (-72, 74), (-74, 69), 
    (-76, 66), (-79, 60), (-81, 55), (-82, 53), (-83, 51), 
    (-84, 48), (-84, 45), (-82, 41), (-80, 37), (-76, 30), 
    (-74, 24), (-71, 18), (-69, 12), (-67, 6), (-65, 0), 
    (-64, -7), (-63, -11), (-62, -17), (-61, -24), (-60, -28), 
    (-59, -33), 
    ]
plotLine(points, pencolor=(0.2, 0.2, 0.2), width=1)



# 右口袋
points = [
    (-75, -109), (-72, -106), (-72, -114), (-72, -117), (-73, -122), 
    (-73, -124), (-74, -126), (-76, -129), (-77, -129), (-77, -125), 
    (-76, -120), (-76, -118), (-75, -112), 
    ]
plotPoly(points, True, pencolor=(0.15, 0.09, 0.0),
         fillcolor=(0.74, 0.68, 0.65), width=2)

# 衣服装饰
points = [
    (0, 134), (5, 136), (9, 138), (15, 140), (18, 142), 
    (23, 143), (27, 144), (26, 154), (27, 164), (27, 171), 
    (27, 177), (27, 183), (27, 184), (28, 186), 
    ]
plotLine(points, pencolor=(0.16, 0.09, 0.04), width=2)



# 衣服左边长线条
points = [
    (27, 119), (27, 114), (26, 109), (25, 103), (23, 97), 
    (22, 93), (20, 84), (18, 75), (16, 66), (15, 57), 
    (14, 49), (13, 42), (12, 34), (11, 23), (11, 13), 
    ]
plotLine(points, pencolor=(0.12, 0.12, 0.12), width=1)

# 左边胸前装饰
points = [
    (27, 117), (33, 121), (37, 125), (43, 129), (44, 128), 
    (44, 125), (45, 123), (46, 120), (45, 119), (40, 116), 
    (37, 113), (32, 110), (30, 108), (26, 105), (25, 106), 
    (26, 111), (27, 116), 
    ]
plotLine(points, pencolor=(0.17, 0.12, 0.08), width=2)

# 左边扣子缝
points = [
    (13, 6), (17, 9), 
    ]
plotLine(points, pencolor=(0.24, 0.12, 0.03), width=2)

# 左边扣子缝1
points = [
    (15, -28), (20, -25), 
    ]
plotLine(points, pencolor=(0.24, 0.12, 0.03), width=2)

# 左边扣子缝1
points = [
    (18, -62), (25, -58), 
    ]
plotLine(points, pencolor=(0.24, 0.12, 0.03), width=2)

# 左口袋
points = [
    (47, -19), (47, -23), (48, -28), (49, -33), (50, -36), 
    (52, -38), (55, -37), (61, -34), (66, -32), (72, -30), 
    (77, -29), (91, -29), (90, -25), (88, -21), (87, -17), 
    (85, -12), (85, -11), (82, -11), (78, -10), (71, -11), 
    (67, -12), (60, -13), (52, -17), 
    ]
plotLine(points, pencolor=(0.12, 0.11, 0.04), width=2)

# 里面衣服
points = [
    (-25, 153), (-27, 153), (-29, 151), (-32, 147), (-34, 144), 
    (-36, 139), (-38, 135), (-41, 129), (-42, 126), (-45, 120), 
    (-47, 116), (-50, 112), (-53, 106), (-55, 102), (-58, 95), 
    (-61, 90), (-62, 88), (-64, 83), (-65, 78), (-66, 71), 
    (-67, 64), (-68, 57), (-68, 50), (-67, 44), (-66, 35), 
    (-64, 22), (-62, 12), (-61, 4), (-60, -3), (-59, -10), 
    (-58, -17), (-57, -26), (-56, -37), (-56, -79), (-56, -98), 
    (-56, -116), (-56, -122), (-57, -129), (-58, -134), (-58, -138), 
    (-58, -143), (-57, -143), (-52, -138), (-48, -134), (-44, -131), 
    (-38, -127), (-34, -123), (-29, -119), (-21, -114), (-13, -109), 
    (-2, -102), (7, -96), (14, -92), (18, -90), (18, -83), 
    (17, -78), (16, -68), (15, -60), (14, -51), (13, -42), 
    (12, -32), (11, -22), (10, -12), (9, -2), (8, 5), 
    (6, 19), (4, 30), (1, 46), (-1, 60), (-3, 74), 
    (-5, 87), (-6, 97), (-7, 107), (-7, 117), (-6, 123), 
    (-5, 128), (-2, 134), (0, 139), (2, 144), (5, 150), 
    (7, 155), (9, 159), (11, 163), (13, 167), (16, 171), 
    (19, 179), (20, 184), (18, 185), (15, 183), (11, 180), 
    (7, 176), (4, 173), (0, 169), (-5, 166), (-10, 162), 
    (-15, 159), (-18, 157), (-20, 155), (-21, 151), (-23, 151), 
    (-24, 152), (-26, 153), 
    ]
plotPoly(points, True, pencolor=(0.09, 0.04, 0.09),
         fillcolor=(1.0, 1.0, 1.0), width=2)

# 里面衣服下边的线条
points = [
    (-57, -130), (-50, -124), (-43, -118), (-36, -112), (-29, -107), 
    (-23, -103), (-17, -99), (-12, -96), (-6, -92), (2, -87), 
    (8, -83), (13, -80), (17, -78), 
    ]
plotLine(points, pencolor=(0.18, 0.2, 0.12), width=2)

# 领口
points = [
    (13, 167), (16, 172), (19, 177), (21, 183), (20, 185), 
    (17, 184), (13, 182), (10, 179), (7, 175), (3, 172), 
    (-3, 167), (-7, 164), (-11, 161), (-16, 159), (-18, 157), 
    (-20, 156), (-20, 153), (-21, 151), (-23, 150), (-24, 152), 
    (-25, 153), (-27, 153), (-30, 151), (-32, 147), (-34, 143), 
    (-36, 139), (-38, 134), (-41, 128), (-43, 124), (-45, 119), 
    (-48, 113), (-51, 109), (-51, 108), (-49, 104), (-47, 100), 
    (-45, 96), (-43, 93), (-41, 91), (-39, 93), (-37, 96), 
    (-34, 99), (-31, 103), (-28, 108), (-25, 113), (-22, 117), 
    (-18, 122), (-14, 126), (-11, 129), (-5, 135), (-3, 138), 
    (-1, 137), (0, 139), (2, 145), (6, 154), (9, 159), 
    (11, 163), 
    ]
plotPoly(points, True, pencolor=(0.21, 0.16, 0.16),
         fillcolor=(1.0, 0.98, 1.0), width=2)

# 领口线条
points = [
    (-11, 161), (-9, 159), (-8, 157), (-6, 154), (-4, 151), 
    (-2, 149), (1, 146), (2, 144), 
    ]
plotLine(points, pencolor=(0.21, 0.15, 0.12), width=2)



# 领带(上一条也是领带)
points = [
    (-16, 154), (-14, 152), (-13, 149), (-15, 147), (-15, 144), 
    (-19, 141), (-21, 139), (-24, 137), (-27, 135), (-29, 134), 
    (-30, 134), (-30, 135), (-29, 136), (-27, 138), (-23, 141), 
    (-20, 143), (-19, 144), (-18, 148), (-17, 151), (-17, 154), 
    ]
plotPoly(points, True, pencolor=(0.07, 0.08, 0.14),
         fillcolor=(0.81, 0.38, 0.34), width=2)

# 里边衣服上线条
points = [
    (-54, 104), (-52, 99), (-49, 94), (-47, 90), (-45, 87), 
    ]
plotLine(points, pencolor=(0.15, 0.11, 0.15), width=2)

# 里边衣服上线条
points = [
    (-33, 90), (-29, 98), (-25, 105), (-22, 109), (-18, 114), 
    (-14, 119), (-10, 124), (-5, 128), 
    ]
plotLine(points, pencolor=(0.15, 0.11, 0.15), width=2)

步骤二

其次,我们再来绘制下面部分(裙摆、丝袜、腿形)。

代码语言:javascript
复制
# 2、裙子、丝袜、腿部等

# 裙子
points = [
    (-94, -216), (-94, -227), (-96, -238), (-97, -247), (-99, -258), 
    (-100, -266), (-101, -272), (-102, -281), (-103, -288), (-104, -297), 
    (-105, -307), (-106, -325), (-107, -337), (-108, -349), (-108, -363), 
    (249, -365), (248, -358), (244, -346), (239, -330), (238, -327), 
    (239, -317), (239, -307), (238, -303), (238, -300), (242, -297), 
    (245, -294), (245, -289), (244, -285), (244, -281), (243, -278), 
    (242, -272), (241, -267), (240, -263), (239, -259), (238, -256), 
    (237, -254), (238, -252), (241, -249), (244, -245), (244, -243), 
    (242, -239), (237, -230), (233, -224), (228, -216), (224, -210), 
    (219, -202), (214, -195), (210, -189), (204, -181), (201, -176), 
    (196, -170), (189, -160), (183, -151), (178, -145), (172, -137), 
    (168, -132), (161, -124), (151, -118), (140, -113), (133, -109), 
    (127, -106), (122, -104), (116, -103), (100, -103), (93, -104), 
    (90, -105), (83, -108), (77, -111), (70, -115), (59, -121), 
    (51, -126), (42, -132), (38, -135), (34, -138), (31, -139), 
    (28, -141), (25, -140), (24, -136), (23, -129), (22, -121), 
    (21, -112), (20, -104), (19, -96), (19, -92), (18, -90), 
    (11, -93), (2, -100), (-6, -104), (-12, -108), (-19, -113), 
    (-25, -117), (-29, -120), (-37, -126), (-42, -130), (-48, -135), 
    (-54, -140), (-58, -143), (-59, -151), (-59, -158), (-60, -167), 
    (-61, -174), (-62, -181), (-63, -187), (-64, -191), (-65, -194), 
    (-66, -196), (-69, -198), (-72, -200), (-78, -204), (-82, -207), 
    (-86, -210), (-90, -213), (-92, -214), 
    ]
plotPoly(points, True, pencolor=(0.15, 0.16, 0.18),
         fillcolor=(0.38, 0.45, 0.52), width=2)

# 
points = [
    (-74, -202), (-75, -222), (-75, -248), (-75, -285), (-75, -319), 
    (-74, -339), (-74, -346), (-72, -348), (-69, -348), (-65, -350), 
    (-62, -351), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.15), width=2)

# 右腿
points = [
    (-77, -363), (-72, -360), (-67, -357), (-63, -355), (-60, -354), 
    (-60, -352), (-61, -351), (-61, -349), (-61, -346), (-62, -345), 
    (-62, -344), (-56, -341), (-50, -338), (-43, -335), (-39, -333), 
    (-34, -331), (-32, -329), (-32, -324), (-33, -321), (-33, -316), 
    (-28, -314), (-24, -312), (-20, -311), (-14, -309), (-8, -307), 
    (-2, -305), (5, -303), (9, -302), (11, -302), (12, -301), 
    (12, -299), (11, -296), (10, -292), (9, -288), (16, -285), 
    (28, -281), (37, -278), (47, -275), (55, -272), (56, -281), 
    (56, -292), (56, -304), (55, -313), (54, -322), (53, -336), 
    (52, -346), (51, -354), (50, -361), (49, -364), 
    ]
plotPoly(points, True, pencolor=(0.11, 0.11, 0.11),
         fillcolor=(0.40, 0.35, 0.32), width=2)

# 左腿
points = [
    (89, -365), (85, -360), (81, -353), (76, -343), (71, -333), 
    (65, -322), (62, -315), (59, -309), (54, -299), (51, -290), 
    (48, -284), (46, -279), (45, -276), (55, -273), (60, -271), 
    (59, -266), (58, -263), (55, -256), (53, -256), (58, -255), 
    (68, -252), (79, -250), (90, -247), (102, -246), (113, -246), 
    (113, -241), (110, -235), (107, -230), (115, -229), (126, -227), 
    (137, -225), (150, -224), (160, -223), (166, -223), (166, -220), 
    (164, -214), (162, -212), (160, -212), (165, -211), (194, -211), 
    (197, -217), (200, -224), (203, -231), (207, -241), (210, -251), 
    (215, -263), (219, -274), (224, -285), (228, -295), (232, -307), 
    (235, -317), (238, -328), (241, -337), (244, -346), (247, -356), 
    (248, -361), (249, -365), 
    ]
plotPoly(points, True, pencolor=(0.19, 0.16, 0.16),
         fillcolor=(0.40, 0.35, 0.32), width=2)

# 裙子褶皱
points = [
    (-48, -135), (-48, -170), (-48, -193), (-47, -212), (-46, -229), 
    (-45, -244), (-44, -258), (-43, -269), (-42, -282), (-41, -294), 
    (-39, -310), (-38, -318), (-38, -319), (-35, -317), (-33, -316), 
    (-35, -317), (-38, -319), (-37, -321), (-36, -323), (-35, -325), 
    (-34, -326), (-32, -328), 
    ]
plotLine(points, pencolor=(0.11, 0.06, 0.06), width=2)

# 
points = [
    (-21, -114), (-20, -129), (-19, -140), (-18, -150), (-17, -159), 
    (-16, -167), (-15, -176), (-14, -185), (-13, -194), (-12, -202), 
    (-11, -211), (-10, -219), (-9, -226), (-8, -233), (-7, -240), 
    (-6, -247), (-5, -252), (-4, -258), (-3, -264), (-2, -270), 
    (-1, -277), (0, -282), (1, -287), (2, -290), (2, -291), 
    (5, -289), (10, -287), (5, -289), (2, -291), (3, -292), 
    (7, -296), (9, -298), (9, -299), 
    ]
plotLine(points, pencolor=(0.12, 0.11, 0.13), width=2)




# 3、头发、头部、脸部等

# 头发
points = [
    (-56, 358), (-65, 357), (-73, 355), (-81, 352), (-86, 350), 
    (-93, 347), (-98, 344), (-105, 340), (-111, 336), (-115, 333), 
    (-121, 328), (-125, 324), (-130, 317), (-133, 311), (-135, 307), 
    (-136, 304), (-138, 296), (-140, 288), (-141, 280), (-141, 265), 
    (-139, 257), (-137, 248), (-135, 241), (-132, 232), 
    (-130, 226), (-126, 218), (-124, 213), (-121, 206), (-119, 202), 
    (-118, 199), (-117, 193), (-116, 187), (-114, 179), 
    (-112, 171), (-110, 160), (-109, 152), (-109, 130), (-110, 121), 
    (-111, 114), (-112, 108), (-114, 100), (-115, 96), (-117, 89), 
    (-119, 83), (-121, 77), (-123, 70), (-127, 56), (-131, 44), 
    (-134, 33), (-137, 22), (-139, 15), (-140, 10), (-141, 7), 
    (-142, 2), (-137, 8), (-132, 14), (-128, 20), (-124, 25), 
    (-118, 33), (-113, 40), (-111, 43), (-109, 45), (-108, 50), 
    (-108, 58), (-107, 63), (-107, 68), (-103, 71), (-99, 75), 
    (-96, 78), (-93, 80), (-92, 85), (-91, 91), (-90, 97), 
    (-88, 102), (-86, 107), (-83, 111), (-81, 114), (-79, 116), 
    (-77, 118), (-76, 119), (-75, 119), (-74, 115), (-73, 109), 
    (-72, 102), (-71, 95), (-70, 88), (-69, 81), (-69, 74), 
    (-68, 67), (-68, 57), (-68, 52), (-67, 56), (-66, 61), 
    (-65, 68), (-64, 75), (-63, 86), (-63, 96), (-63, 103), 
    (-63, 113), (-63, 120), (-63, 126), (-61, 127), (-60, 128), 
    
    (-55, 131), (-47, 136), (-36, 144), (-32, 147), (-29, 151), 
    (-25, 154), (-27, 158), (-29, 162), (-31, 165), (-32, 166), 
    (-39, 167), (-46, 168), (-52, 169), (-59, 170), (-66, 172), 
    (-68, 173), (-72, 175), (-75, 177), (-78, 180), (-81, 183), 
    (-81, 184), (-77, 183), (-71, 184), (-77, 184), (-80, 185), 
    (-83, 186), 
    (-84, 186), (-87, 190), (-90, 194),
    (-91, 195), (-91, 196), (-89, 196), (-84, 196), (-87, 197), 
    (-90, 199), (-93, 202), (-96, 206), (-99, 210), (-101, 214), 
    (-103, 218), (-105, 222), (-105, 225), (-105, 227), (-103, 225), 
    (-100, 223), (-98, 222), (-100, 225), (-101, 227), (-103, 230), 
    (-104, 232), (-105, 234), (-106, 236), (-107, 239), 
    (-107, 241), 
    (-107, 256), (-107, 266), (-106, 276), (-106, 283), (-104, 274), 
    (-101, 266), (-97, 255), (-94, 248), (-90, 242), (-88, 237), 
    (-87, 235), (-76, 235), (-72, 236), (-68, 233), (-69, 236), 
    (-68, 237), (-67, 237), (-67, 239), (-64, 240), (-64, 243), 
    (-61, 243), (-61, 245), (-56, 245), (-50, 245), (-49, 246), 
    (-53, 248), (-57, 251), (-62, 254), (-66, 258), (-69, 261), 
    (-72, 265), (-75, 268), (-78, 273), (-82, 280), (-86, 287), 
    (-82, 280), (-78, 274), (-75, 271), (-70, 268), (-64, 263), 
    (-57, 259), (-53, 257), (-49, 256), (-47, 255), (-45, 255), 
    (-41, 258), (-36, 261), (-33, 264), (-30, 266), (-27, 268), 
    (-23, 268), (-17, 268), (-10, 268), (-6, 268), (-2, 262), 
    (-1, 256), (0, 251), (0, 246), (-1, 244), (-2, 241), 
    (-3, 238), (-1, 240), (2, 242), (4, 246), (6, 250), 
    (3, 244), (3, 239), (2, 235), (0, 231), (-1, 228), 
    (-2, 225), (-6, 221), (-1, 223), (2, 227), (5, 231), 
    (6, 232), (7, 228), (8, 219), (9, 212), (10, 204), 
    (11, 193), (12, 180), (13, 171), (15, 157), (17, 147), 
    (19, 139), (21, 132), (24, 125), (27, 118), (31, 112), 
    (34, 107), (38, 103), (35, 110), (32, 118), (30, 126), 
    (28, 136), (27, 144), (26, 155), (26, 164), (25, 178), 
    (25, 186), (28, 186), (31, 186), (35, 188), (39, 192), 
    (42, 194), (45, 196), (49, 199), (54, 202), (59, 205), 
    (58, 210), (56, 218), (54, 226), (52, 233), (49, 242), 
    (46, 251), (42, 262), (38, 273), (33, 285), (30, 293), 
    (26, 301), (21, 311), (16, 320), (12, 326), (8, 331), 
    (3, 336), (-2, 340), (-9, 344), (-16, 348), (-27, 353), 
    (-33, 355), (-37, 356), (-44, 357), (-52, 358), 
    ]
plotPoly(points, True, pencolor=(0.13, 0.13, 0.11),
         fillcolor=(0.28, 0.28, 0.31), width=2)


# 脸部轮廓
points = [
    (-105, 276), (-106, 275), (-107, 269), (-107, 240), (-106, 236), 
    (-104, 232), (-102, 228), (-97, 222), (-102, 224), (-105, 227), 
    (-105, 223), (-104, 220), (-103, 218), (-101, 214), (-99, 209), 
    (-95, 204), (-92, 201), (-88, 198), (-84, 196), (-91, 196), 
    (-90, 194), (-86, 190), (-83, 186), (-79, 185), (-69, 184), 
    (-76, 183), (-80, 183), (-77, 179), (-73, 176), (-69, 174), 
    (-65, 172), (-61, 171), (-56, 170), (-50, 169), (-43, 168), 
    (-36, 167), (-28, 166), (-20, 165), (-14, 165), (-10, 169), 
    (-5, 175), (-1, 180), (2, 185), (5, 189), (7, 193), 
    (10, 197), (10, 201), (9, 211), (8, 220), (7, 226), 
    (6, 232), (4, 229), (2, 226), (-1, 223), (-5, 220), 
    (-3, 224), (-1, 227), (1, 232), (2, 235), (3, 240), 
    (3, 244), (1, 241), (-3, 237), (-2, 240), (-1, 242), 
    (0, 246), (0, 252), (-1, 256), (-2, 260), (-3, 263), 
    (-4, 265), (-5, 267), (-6, 269), (-7, 268), (-11, 268), 
    (-22, 268), (-25, 268), (-28, 268), (-31, 265), (-35, 262), 
    (-39, 259), (-44, 255), (-47, 255), (-50, 256), (-53, 257), 
    (-57, 259), (-61, 261), (-66, 264), (-70, 267), (-74, 270), 
    (-77, 273), (-79, 275), (-76, 270), (-73, 266), (-69, 261), 
    (-65, 257), (-62, 254), (-58, 251), (-53, 248), (-50, 246), 
    (-50, 245), (-53, 245), (-57, 244), (-61, 244), (-64, 243), 
    (-65, 241), (-68, 240), (-68, 239), (-67, 237), (-69, 237), 
    (-68, 234), (-68, 233), (-70, 235), (-72, 236), (-75, 236), 
    (-78, 235), (-86, 235), (-89, 239), (-92, 245), (-95, 250), 
    (-98, 258), (-101, 266), (-102, 269), (-104, 275), 
    ]
plotPoly(points, True, pencolor=(0.09, 0.07, 0.05),
         fillcolor=(1.0, 0.93, 0.9), width=2)

# 红晕
points = [
    (-66, 201), (-71, 202), (-76, 202), (-79, 202), (-83, 201), 
    (-87, 201), (-88, 199), (-88, 195), (-85, 191), (-82, 189), 
    (-79, 187), (-75, 186), (-72, 185), (-70, 185), (-68, 187), 
    (-66, 190), (-65, 194), (-65, 197), 
    ]
plotPoly(points, True, pencolor=(1.0, 0.88, 0.85),
         fillcolor=(1.0, 0.88, 0.85), width=2)

# 红晕
points = [
    (-6, 241), (-11, 240), (-16, 238), (-20, 234), (-21, 231), 
    (-20, 227), (-18, 225), (-16, 223), (-14, 221), (-10, 220), 
    (-7, 221), (-5, 223), (-2, 227), (-1, 231), (-1, 234), 
    (-1, 236), (-4, 240), 
    ]
plotPoly(points, True, pencolor=(1.0, 0.88, 0.85),
         fillcolor=(1.0, 0.88, 0.85), width=2)

# 脖子
points = [
    (-32, 166), (-30, 163), (-28, 160), (-27, 157), (-26, 154), 
    (-25, 152), (-22, 151), (-20, 153), (-19, 155), (-19, 157), 
    (-18, 157), (-15, 159), (-11, 162), (-3, 167), (3, 172), 
    (8, 177), (11, 180), (11, 186), (11, 192), (10, 196), 
    (10, 198), (8, 194), (5, 189), (2, 186), (-1, 181), 
    (-3, 178), (-5, 175), (-9, 171), (-12, 167), (-14, 165), 
    (-22, 165), (-28, 166), 
    ]
plotPoly(points, True, pencolor=(0.04, 0.0, 0.0),
         fillcolor=(0.88, 0.73, 0.73), width=2)

# 头发
points = [
    (-156, -85), (-156, -103), (-155, -117), (-151, -135), (-148, -147), 
    (-144, -158), (-137, -172), (-133, -179), (-126, -188), (-121, -194), 
    (-117, -198), (-113, -201), (-109, -203), (-107, -204), (-113, -199), 
    (-117, -194), (-120, -189), (-123, -182), (-127, -175), (-130, -166), 
    (-133, -156), (-134, -152), (-136, -142), (-137, -134), (-138, -122), 
    (-138, -114), (-140, -111), (-144, -105), (-147, -99), (-150, -95), 
    (-152, -91), (-154, -88), 
    ]
plotPoly(points, True, pencolor=(0.13, 0.13, 0.11),
         fillcolor=(0.28, 0.28, 0.31), width=2)

# 头发
points = [
    (-128, -129), (-126, -136), (-123, -146), (-119, -157), (-115, -166), 
    (-110, -173), (-106, -180), (-101, -185), (-98, -188), (-96, -190), 
    (-95, -188), (-93, -185), (-96, -179), (-97, -171), (-98, -164), 
    (-98, -160), (-103, -159), (-104, -155), (-106, -152), (-110, -153), 
    (-111, -152), (-113, -150), (-117, -144), (-120, -141), (-123, -136), 
    (-126, -132), 
    ]
plotPoly(points, True, pencolor=(0.16, 0.13, 0.09),
         fillcolor=(0.28, 0.28, 0.31), width=2)



# 头发
points = [
    (-73, -43), (-72, -50), (-72, -86), (-73, -104), (-75, -102), 
    (-77, -101), (-77, -87), (-76, -72), (-75, -63), (-74, -53), 
    ]
plotPoly(points, True, pencolor=(0.13, 0.13, 0.13),
         fillcolor=(0.28, 0.28, 0.31), width=2)

# 
points = [
    (91, 73), (89, 65), (87, 57), (86, 51), (84, 42), 
    (82, 33), (81, 27), (81, 13), (82, 3), (84, -6), 
    (86, -14), (89, -23), (92, -30), (95, -36), (100, -42), 
    (104, -47), (109, -54), (108, -40), (106, -22), (104, -8), 
    (102, 6), (100, 18), (98, 31), (95, 49), (93, 61), 
    (92, 67), 
    ]
plotPoly(points, True, pencolor=(0.12, 0.12, 0.12),
         fillcolor=(0.28, 0.28, 0.31), width=2)

# 上一步是填充
points = [
    (-70, 184), (-78, 183), (-86, 184), (-93, 187), (-98, 189), 
    (-102, 192), (-105, 195), (-108, 197), (-111, 202), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 上一步是填充
points = [
    (-79, 185), (-85, 187), (-90, 191), (-95, 194), (-97, 196), 
    (-98, 198), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-86, 268), (-84, 262), (-82, 259), (-80, 256), (-77, 252), 
    (-75, 250), (-73, 248), (-70, 245), (-67, 243), (-66, 242), 
    (-66, 244), (-63, 244), (-62, 246), (-60, 246), (-63, 248), 
    (-67, 251), (-71, 254), (-73, 257), (-77, 260), (-80, 263), 
    (-83, 266), 
    ]
plotPoly(points, True, pencolor=(0.31, 0.3, 0.34),
         fillcolor=(0.31, 0.3, 0.34), width=1)

# 
points = [
    (-100, 273), (-97, 263), (-93, 254), (-88, 244), (-85, 238), 
    (-79, 238), (-75, 239), (-81, 246), (-87, 253), (-91, 260), 
    (-94, 265), (-97, 269), 
    ]
plotPoly(points, True, pencolor=(0.16, 0.18, 0.18),
         fillcolor=(1.0, 0.93, 0.9), width=2)

# 
points = [
    (-83, 263), (-77, 257), (-72, 252), (-69, 249), (-66, 247), 
    (-62, 245), (-59, 245), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-83, 292), (-78, 286), (-72, 278), (-65, 273), (-59, 268), 
    (-54, 264), (-50, 262), (-47, 260), (-44, 260), (-40, 262), 
    (-37, 265), (-33, 267), (-31, 269), (-34, 271), (-37, 272), 
    (-42, 274), (-48, 274), (-54, 275), (-59, 278), (-64, 280), 
    (-69, 283), (-73, 285), (-76, 288), 
    ]
plotPoly(points, True, pencolor=(0.13, 0.13, 0.11),
         fillcolor=(1.0, 0.92, 0.89), width=2)

# 
points = [
    (9, 268), (10, 262), (11, 251), (10, 244), (8, 238), 
    (6, 231), 
    ]
plotLine(points, pencolor=(0.09, 0.05, 0.07), width=2)

# 
points = [
    (-97, 312), (-95, 315), (-92, 317), (-85, 318), (-76, 317), 
    (-64, 316), (-55, 314), (-44, 309), (-37, 305), (-31, 300), 
    (-27, 296), (-21, 290), (-17, 285), (-13, 280), (-8, 273), 
    (-6, 268), (-4, 265), 
    ]
plotLine(points, pencolor=(0.18, 0.14, 0.15), width=2)

# 
points = [
    (-2, 318), (3, 313), (6, 308), (10, 302), (14, 293), 
    (17, 287), (22, 274), (26, 261), (29, 250), (31, 240), 
    (33, 228), (34, 220), (35, 212), (36, 203), (36, 196), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (39, 270), (41, 264), (43, 256), (46, 243), (47, 236), 
    (48, 229), (49, 220), (49, 205), (49, 200), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-109, 313), (-106, 314), (-104, 314), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-108, 316), (-103, 321), (-100, 322), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-112, 320), (-112, 327), (-111, 328), (-109, 332), (-106, 335), 
    (-105, 337), (-101, 340), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-117, 314), (-125, 314), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-119, 308), (-122, 306), (-125, 303), (-127, 300), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-105, 170), (-104, 160), (-104, 139), (-104, 123), (-105, 110), 
    (-106, 102), (-107, 95), (-109, 83), (-110, 77), (-112, 69), 
    (-115, 55), (-117, 48), (-119, 41), (-121, 35), (-122, 30), 
    (-123, 27), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-90, 133), (-90, 101), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-87, 122), (-87, 105), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-59, 170), (-57, 162), (-56, 155), (-55, 149), (-54, 142), 
    (-54, 134), (-54, 132), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-50, 169), (-49, 161), (-48, 151), (-48, 143), (-48, 137), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-87, 333), (-80, 336), (-74, 337), (-61, 337), (-55, 336), 
    (-48, 334), (-41, 332), (-34, 329), (-25, 324), (-19, 319), 
    (-10, 311), (-2, 303), (2, 299), (5, 293), (9, 286), 
    (12, 278), (15, 271), (18, 260), (21, 245), (23, 238), 
    (24, 226), (25, 218), (25, 187), (25, 179), (25, 163), 
    ]
plotLine(points, pencolor=(0.13, 0.13, 0.11), width=2)

# 
points = [
    (-117, 220), (-116, 216), (-113, 211), (-110, 208), (-105, 203), 
    (-102, 201), (-99, 198), (-94, 197), (-91, 196), 
    ]
plotLine(points, pencolor=(0.09, 0.09, 0.08), width=2)

# 
points = [
    (-120, 251), (-117, 245), (-115, 240), (-112, 235), (-110, 232), 
    (-106, 228), (-104, 226), 
    ]
plotLine(points, pencolor=(0.16, 0.11, 0.11), width=2)

# 
points = [
    (-112, 252), (-110, 246), (-108, 241), (-106, 237), 
    ]
plotLine(points, pencolor=(0.14, 0.13, 0.13), width=2)

步骤三

最后,我们可以绘制上面部分(头部、头发、脸部)

代码语言:javascript
复制
# 4、脸部器官部分

# 耳朵
points = [
    (16, 270), (18, 270), (19, 269), (21, 267), (22, 265), 
    (23, 263), (23, 261), (24, 257), (24, 247), (23, 244), 
    (22, 242), (21, 244), (21, 247), (20, 251), (19, 255), 
    (18, 260), (17, 263), (16, 266), 
    ]
plotPoly(points, True, pencolor=(0.13, 0.13, 0.11),
         fillcolor=(1.0, 0.93, 0.9), width=2)

# 右眉
points = [
    (-113, 230), (-110, 232), (-105, 234), (-100, 236), (-95, 237), 
    (-91, 239), (-86, 239), 
    ]
plotLine(points, pencolor=(0.07, 0.06, 0.09), width=2)

# 左眉
points = [
    (-52, 260), (-48, 264), (-43, 269), (-39, 273), (-33, 278), 
    (-28, 281), (-24, 284), 
    ]
plotLine(points, pencolor=(0.06, 0.04, 0.02), width=2)

# 右眼
points = [
    (-81, 226), (-85, 226), (-89, 224), (-93, 221), (-95, 218), 
    (-95, 212), (-93, 209), (-90, 207), (-87, 205), (-83, 204), 
    (-80, 204), (-75, 204), (-72, 206), (-69, 208), (-67, 209), 
    (-67, 212), (-69, 216), (-71, 219), (-73, 222), (-76, 224), 
    (-78, 226), 
    ]
plotPoly(points, True, pencolor=(1.0, 0.99, 1.0),
         fillcolor=(1.0, 0.99, 1.0), width=2)

points = [
    (-89, 206), (-93, 207), (-96, 208), (-97, 208), (-99, 209), 
    (-104, 208), (-99, 210), (-99, 212), (-99, 216), (-99, 219), 
    (-97, 222), (-95, 224), (-92, 226), (-90, 227), (-86, 228), 
    (-77, 228), (-75, 227), (-72, 226), (-76, 226), (-80, 226), 
    (-85, 226), (-89, 225), (-92, 222), (-94, 220), (-95, 218), 
    (-95, 212), (-94, 210), (-92, 208), 
    ]
plotPoly(points, True, pencolor=(0.03, 0.0, 0.0),
         fillcolor=(0.03, 0.0, 0.0), width=2)

# 
points = [
    (-86, 225), (-86, 221), (-86, 220), (-85, 217), (-84, 215), 
    (-83, 216), (-81, 216), (-80, 215), (-80, 212), (-81, 211), 
    (-80, 210), (-77, 207), (-75, 205), (-74, 205), (-70, 207), 
    (-69, 208), (-67, 209), (-67, 211), (-68, 214), (-70, 217), 
    (-71, 219), (-74, 222), (-75, 224), (-77, 225), (-79, 226), 
    (-83, 226), 
    ]
plotPoly(points, True, pencolor=(0.03, 0.05, 0.1),
         fillcolor=(0.69, 0.7, 0.83), width=2)

# 右眼瞳孔
points = [
    (-83, 225), (-81, 225), (-79, 225), (-84, 223), (-82, 223), 
    (-80, 223), (-78, 223), (-85, 221), (-83, 221), (-81, 221), 
    (-79, 221), (-77, 221), (-75, 221), (-84, 219), (-82, 219), 
    (-80, 219), (-78, 219), (-76, 219), (-74, 219), (-83, 218), 
    (-81, 218), (-79, 218), (-78, 218), (-77, 218), (-76, 218), 
    (-74, 218), (-72, 218), (-82, 217), (-80, 217), (-74, 217), 
    (-72, 217), (-79, 216), (-77, 216), (-75, 216), (-73, 216), 
    (-71, 216), (-78, 214), (-76, 214), (-74, 214), (-72, 214), 
    (-70, 214), (-79, 212), (-77, 212), (-75, 212), (-73, 212), 
    (-71, 212), (-69, 212), (-78, 210), (-76, 210), (-74, 210), 
    (-72, 210), (-70, 210), (-75, 208), (-73, 208), (-71, 208), 
    (-74, 207), (-72, 207), 
    ]
pencolors = [
    (0.21, 0.24, 0.31), (0.25, 0.28, 0.36), (0.12, 0.15, 0.21), (0.26, 0.29, 0.38), (0.24, 0.27, 0.39), 
    (0.20, 0.26, 0.38), (0.27, 0.32, 0.42), (0.09, 0.14, 0.22), (0.25, 0.29, 0.42), (0.25, 0.29, 0.45), 
    (0.22, 0.27, 0.43), (0.52, 0.55, 0.69), (0.38, 0.39, 0.49), (0.12, 0.15, 0.28), (0.28, 0.31, 0.48), 
    (0.26, 0.31, 0.50), (0.31, 0.36, 0.53), (0.31, 0.33, 0.47), (0.34, 0.34, 0.44), (0.31, 0.30, 0.36), 
    (0.31, 0.31, 0.38), (0.32, 0.31, 0.47), (0.33, 0.33, 0.48), (0.14, 0.15, 0.30), (0.06, 0.07, 0.21), 
    (0.41, 0.44, 0.54), (0.38, 0.38, 0.45), (0.33, 0.33, 0.39), (0.38, 0.38, 0.53), (0.48, 0.50, 0.62), 
    (0.53, 0.54, 0.61), (0.38, 0.38, 0.51), (0.34, 0.35, 0.49), (0.35, 0.37, 0.49), (0.56, 0.58, 0.69), 
    (0.56, 0.56, 0.63), (0.54, 0.54, 0.65), (0.55, 0.56, 0.69), (0.61, 0.62, 0.77), (0.69, 0.70, 0.83), 
    (0.55, 0.54, 0.62), (0.35, 0.36, 0.41), (0.60, 0.60, 0.69), (0.78, 0.79, 0.93), (0.84, 0.84, 1.00), 
    (0.87, 0.87, 1.00), (0.87, 0.87, 0.92), (0.45, 0.46, 0.50), (0.73, 0.73, 0.82), (0.84, 0.83, 0.96), 
    (0.86, 0.86, 0.99), (0.82, 0.80, 0.89), (0.82, 0.80, 0.88), (0.89, 0.86, 0.95), (0.90, 0.85, 0.93), 
    (0.83, 0.79, 0.85), (0.65, 0.60, 0.66), 
    ]
te.tracer(False)
for i in range(len(points)):
    te.up()
    te.goto(points[i])
    te.pencolor(pencolors[i])
    te.down()
    te.dot(3)
te.tracer(True)

# 左眼
points = [
    (-40, 245), (-39, 250), (-37, 255), (-34, 258), (-30, 261), 
    (-25, 262), (-20, 263), (-16, 263), (-13, 261), (-12, 259), 
    (-11, 254), (-11, 252), (-11, 248), (-11, 245), (-13, 241), 
    (-17, 239), (-20, 237), (-24, 236), (-28, 236), (-32, 236), 
    (-34, 238), (-37, 241), (-39, 244), 
    ]
plotPoly(points, True, pencolor=(1.0, 0.99, 1.0),
         fillcolor=(1.0, 0.99, 1.0), width=2)

points = [
    (-40, 244), (-39, 249), (-37, 255), (-34, 259), (-29, 262), 
    (-26, 263), (-20, 263), (-16, 263), (-13, 262), (-12, 260), 
    (-11, 258), (-10, 255), (-10, 253), (-9, 255), (-9, 258), 
    (-8, 261), (-8, 264), (-10, 265), (-13, 267), (-17, 267), 
    (-22, 267), (-24, 267), (-29, 266), (-32, 264), (-35, 262), 
    (-37, 260), (-39, 255), (-40, 252), (-41, 250), (-41, 248), 
    ]
plotPoly(points, True, pencolor=(0.02, 0.0, 0.0),
         fillcolor=(0.0, 0.0, 0.02), width=2)

# 
points = [
    (-30, 260), (-32, 259), (-33, 256), (-32, 252), (-31, 249), 
    (-29, 248), (-27, 248), (-27, 245), (-27, 244), (-28, 243), 
    (-26, 240), (-24, 238), (-23, 237), (-21, 237), (-19, 238), 
    (-17, 239), (-14, 241), (-13, 242), (-13, 245), (-14, 248), 
    (-16, 251), (-18, 254), (-20, 257), (-22, 259), (-24, 260), 
    (-26, 261), (-28, 261), 
    ]
plotPoly(points, True, pencolor=(0.05, 0.07, 0.05),
         fillcolor=(0.69, 0.7, 0.83), width=2)

# 左眼瞳孔
points = [
    (-29, 259), (-27, 259), (-25, 259), (-30, 257), (-28, 257), 
    (-26, 257), (-24, 257), (-22, 257), (-31, 255), (-29, 255), 
    (-27, 255), (-25, 255), (-23, 255), (-21, 255), (-30, 253), 
    (-28, 253), (-26, 253), (-24, 253), (-22, 253), (-20, 253), 
    (-29, 251), (-27, 251), (-25, 251), (-23, 251), (-21, 251), 
    (-19, 251), (-30, 250), (-28, 250), (-26, 250), (-24, 250), 
    (-23, 250), (-21, 250),  (-20, 250), (-19, 250), 
    (-17, 250), (-26, 248), (-24, 249), (-23, 248), (-21, 248), 
    (-19, 248), (-17, 248), (-25, 246), (-24, 246), (-22, 246), 
    (-20, 246), (-18, 246), (-16, 246), (-26, 244), (-24, 244), 
    (-22, 244), (-20, 244), (-18, 244), (-16, 244), (-25, 242), 
    (-23, 242), (-21, 242), (-19, 242), (-17, 242), (-24, 241), 
    (-22, 241), (-20, 241), (-18, 241), (-16, 241), (-23, 240), 
    (-21, 240), (-18, 240), (-22, 239), (-20, 239), 
    ]
pencolors = [
    (0.16, 0.18, 0.24), (0.20, 0.22, 0.30), (0.14, 0.16, 0.25), (0.24, 0.25, 0.41), (0.22, 0.23, 0.40), 
    (0.23, 0.25, 0.43), (0.23, 0.25, 0.41), (0.25, 0.27, 0.37), (0.20, 0.21, 0.38), (0.26, 0.27, 0.47), 
    (0.23, 0.25, 0.47), (0.24, 0.27, 0.49), (0.50, 0.51, 0.70), (0.28, 0.28, 0.40), (0.25, 0.27, 0.38), 
    (0.27, 0.30, 0.47), (0.27, 0.31, 0.51), (0.28, 0.31, 0.52), (0.30, 0.32, 0.49), (0.32, 0.32, 0.44), 
    (0.31, 0.35, 0.43), (0.30, 0.35, 0.50), (0.29, 0.34, 0.54), (0.29, 0.32, 0.53), (0.33, 0.34, 0.51), 
    (0.38, 0.36, 0.48), (0.22, 0.25, 0.32), (0.28, 0.31, 0.44), (0.38, 0.42, 0.58), (0.24, 0.27, 0.46), 
    (0.07, 0.10, 0.28), (0.49, 0.51, 0.67), (0.49, 0.51, 0.66), (0.54, 0.55, 0.70), 
    (0.45, 0.46, 0.58), (0.33, 0.35, 0.48), (0.22, 0.25, 0.42), (0.39, 0.40, 0.56), (0.44, 0.45, 0.60), 
    (0.53, 0.53, 0.67), (0.60, 0.60, 0.72), (0.59, 0.58, 0.71), (0.60, 0.60, 0.73), (0.56, 0.56, 0.69), 
    (0.71, 0.70, 0.83), (0.72, 0.71, 0.82), (0.74, 0.76, 0.82), (0.53, 0.53, 0.60), (0.63, 0.63, 0.74), 
    (0.76, 0.76, 0.88), (0.82, 0.81, 0.94), (0.88, 0.87, 0.99), (0.85, 0.86, 0.92), (0.47, 0.49, 0.57), 
    (0.73, 0.75, 0.85), (0.84, 0.85, 0.97), (0.80, 0.80, 0.92), (0.80, 0.81, 0.93), (0.53, 0.55, 0.64), 
    (0.83, 0.84, 0.95), (0.82, 0.82, 0.93), (0.85, 0.86, 0.96), (0.71, 0.67, 0.71), (0.72, 0.74, 0.82), 
    (0.80, 0.81, 0.89), (0.73, 0.72, 0.80), (0.71, 0.71, 0.76), (0.75, 0.73, 0.79), 
    ]
te.tracer(False)
for i in range(len(points)):
    te.up()
    te.goto(points[i])
    te.pencolor(pencolors[i])
    te.down()
    te.dot(3)
te.tracer(True)

# 鼻子
points = [
    (-48, 210), (-45, 209), 
    ]
plotLine(points, pencolor=(0.34, 0.26, 0.24), width=2)

# 
points = [
    (-51, 214), (-51, 211), (-50, 209), (-50, 211), (-50, 213), 
    (-50, 214), (-49, 214), (-49, 212), (-49, 211), (-49, 209), 
    ]
plotLine(points, pencolor=(0.88, 0.78, 0.76), width=1)

# 嘴巴
points = [
    (-26, 182), (-29, 182), (-32, 183), (-34, 185), (-35, 189), 
    (-34, 191), (-32, 193), (-29, 195), (-26, 196), (-22, 196), 
    (-19, 195), (-17, 194), (-15, 191), (-15, 189), (-16, 187), 
    (-18, 185), (-20, 184), (-23, 182), 
    ]
plotPoly(points, True, pencolor=(1.0, 0.76, 0.74),
         fillcolor=(1.0, 0.76, 0.74), width=2)

# 
points = [
    (-27, 182), (-30, 182), (-32, 183), (-34, 186), (-35, 189), 
    (-34, 191), (-31, 194), (-29, 195), (-26, 196), (-21, 196), 
    (-19, 195), (-17, 194), (-16, 193), (-15, 191), (-15, 189), 
    ]
plotLine(points, pencolor=(0.28, 0.18, 0.16), width=2)

# 
points = [
    (-47, 250), (-46, 253), (-44, 256), 
    ]
plotLine(points, pencolor=(0.2, 0.18, 0.17), width=2)

示例代码

下面是整个绘制过程的所有代码,可以粘贴到文件中运行。完整的示例代码请参考链接:

示例代码1:https://cloud.tencent.com/developer/article/2404817

示例代码2:https://cloud.tencent.com/developer/article/2404818

如果需要执行,请将示例代码1和示例代码2中的代码放在一起执行,我们可以得到下面的二次元图。

总结

通过本文的学习和实践,我们掌握了使用Python的turtle模块来创作二次元少女的技巧,这个过程中,我们深入了解了turtle模块的基本命令和递归等编程概念,这些都是构建更复杂项目的重要基础。也希望读者能够将这些知识应用到自己的项目中。turtle模块是一个功能强大且易于使用的绘图工具,无论是绘制其他自然景物还是创造抽象艺术作品,无论是初学者还是经验丰富的Python开发者,都可以借助turtle模块来实现,从中受益。

[引用]

1、百度百科:https://baike.baidu.com/item/turtle/50354923?fr=ge_ala

2、官网:https://pythonturtle.org/

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 准备工作
  • 关于turtle模块
  • 绘制说明
  • 绘制步骤
    • 步骤一
      • 步骤二
        • 步骤三
        • 示例代码
        • 总结
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档