懒羊羊代码 (python)

import turtle

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)


# 脸
def face():
    points = [
        (-131, 76), (-121, 85), (-112, 94), (-105, 105),
        (-113, 109), (-105, 106), (-97, 106), (-89, 106), (-83, 110),
        (-77, 115), (-69, 120), (-60, 118), (-53, 117), (-44, 117),
        (-35, 120), (-26, 126), (-17, 122), (-10, 117), (-3, 114),
        (6, 111), (16, 110), (26, 112), (32, 115), (36, 117),
        (42, 112), (47, 107), (53, 102), (61, 98), (71, 96),
        (80, 96), (89, 97), (98, 99), (104, 92), (108, 86),
        (114, 78), (121, 71), (128, 66), (139, 62), (138, 53),
        (138, 42), (139, 32), (143, 25), (149, 17), (154, 9),
        (157, 6), (154, 2), (152, -1), (147, -5), (143, -12),
        (140, -20), (138, -28), (137, -38), (139, -46), (139, -52),
        (132, -57), (124, -63), (120, -70), (115, -76), (113, -86),
        (109, -96), (100, -103), (94, -111), (90, -119), (89, -125),
        (90, -131), (94, -137), (97, -142),
        (93, -149), (87, -150), (71, -153), (55, -156), (42, -156),
        (28, -157), (12, -157), (-2, -155), (-16, -153), (-27, -151),
        (-37, -147), (-50, -144), (-61, -140), (-71, -137), (-82, -133),
        (-91, -126), (-102, -119), (-112, -111), (-120, -102), (-127, -94),
        (-131, -89), (-136, -79), (-139, -71), (-141, -60), (-143, -49),
        (-141, -38), (-140, -27), (-138, -17), (-135, -8), (-132, 1),
        (-131, 11), (-132, 22), (-130, 33), (-129, 44), (-126, 55),
        (-123, 67), (-121, 76), (-121, 85)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             width=2, fillcolor=(1, 0.82, 0.71))
# 手
def hands():
    # 左手
    points = [
        (93, -147), (97, -143), (102, -138), (111, -134), (119, -131),
        (130, -128), (143, -126), (149, -120), (158, -117), (166, -113),
        (175, -110), (177, -103), (182, -95), (191, -89), (199, -87),
        (204, -85), (210, -86), (214, -88), (217, -93), (221, -96),
        (224, -100), (224, -104), (223, -108), (225, -112), (226, -118),
        (224, -124), (219, -128), (215, -129), (210, -127), (205, -123),
        (208, -118), (203, -114), (203, -110), (209, -109), (213, -105),
        (214, -130),
        (206, -135), (202, -137), (197, -135), (192, -132), (187, -129),
        (186, -132), (180, -136), (170, -140), (162, -144), (151, -149),
        (139, -155), (128, -159), (118, -161), (110, -162), (104, -163),
        (99, -160), (94, -156), (93, -150), (95, -147)
    ]
    plotPoly(points, True, pencolor=(1, 0.82, 0.71),
             fillcolor=(1, 0.82, 0.71), width=2)
    plotLine(points[:35], pencolor=(0.67, 0.5, 0.22), width=2)
    plotLine(points[36:], pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (197, -119), (202, -116), (202, -111), (202, -106), (202, -102),
        (207, -105), (214, -104), (217, -101), (218, -99), (217, -96),
        (216, -93), (212, -91), (207, -88), (201, -86)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (223, -111), (219, -114), (215, -117), (210, -117), (205, -117),
        (203, -114)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)

    # 右手
    points = [
        (-126, -98), (-133, -94), (-141, -90), (-146, -88), (-151, -85),
        (-154, -78), (-157, -72), (-162, -68), (-168, -64), (-179, -61),
        (-184, -59), (-189, -61), (-192, -64), (-196, -69), (-199, -73),
        (-201, -78), (-199, -85), (-201, -93), (-200, -98), (-196, -102),
        (-190, -102), (-188, -106), (-184, -108), (-179, -110), (-171, -108),
        (-163, -103), (-165, -106), (-157, -111), (-149, -116), (-140, -120),
        (-131, -125), (-118, -133), (-110, -136), (-99, -139), (-97, -136),
        (-97, -133), (-95, -126), (-98, -123), (-104, -118), (-111, -112),
        (-119, -103)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(1, 0.82, 0.71), width=2)
    points = [
        (-178, -62), (-185, -63), (-193, -67), (-194, -74), (-191, -79),
        (-186, -79), (-180, -78), (-179, -85), (-179, -88), (-178, -91),
        (-175, -93)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (-192, -79), (-189, -83), (-185, -85), (-180, -83), (-179, -89),
        (-183, -93), (-187, -91), (-192, -90), (-198, -86)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (-185, -94), (-181, -97), (-187, -102)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)

# 肚子
def body():
    points = [
        (-95, -127), (-97, -135), (-96, -142), (-104, -147), (-109, -152),
        (-112, -156), (-116, -165), (-119, -173), (-121, -182), (-120, -188),
        (-117, -198), (-114, -208), (-118, -211), (-122, -218), (-123, -228),
        (-122, -238), (-109, -261), (-103, -266), (-103, -275), (-97, -281),
        (-91, -289), (-83, -292), (-74, -297), (-64, -299), (-55, -298),
        (-46, -295), (-40, -301), (-35, -306), (-27, -310), (-16, -312),
        (-8, -311), (2, -307), (6, -303), (13, -300), (20, -304),
        (26, -309), (34, -314), (45, -315), (55, -314), (62, -310),
        (70, -305), (77, -296), (89, -295), (96, -291), (103, -286),
        (111, -277), (113, -269), (116, -258), (116, -251), (113, -242),
        (119, -238), (122, -231), (125, -221), (125, -208), (123, -197),
        (116, -187), (116, -177), (117, -168), (117, -163), (111, -162),
        (102, -163), (95, -157), (93, -149), (87, -150), (78, -150),
        (72, -154), (60, -154), (56, -156), (54, -165), (56, -175),
        (54, -184), (56, -196), (53, -211), (55, -223), (54, -231),
        (51, -239), (44, -243), (37, -245), (34, -246), (20, -246),
        (5, -246), (-33, -241), (-56, -237), (-80, -233), (-90, -230),
        (-94, -227), (-96, -219), (-98, -210), (-95, -201), (-95, -194),
        (-91, -181), (-88, -163), (-82, -147), (-77, -134), (-86, -131)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(1, 1, 1), width=2)

# 衣服
def cloth():
    points = [
        (56, -156), (54, -165), (56, -175),
        (54, -184), (56, -196), (53, -211), (55, -223), (54, -231),
        (51, -239), (44, -243), (37, -245), (34, -246), (20, -246),
        (5, -246), (-33, -241), (-56, -237), (-80, -233), (-90, -230),
        (-94, -227), (-96, -219), (-98, -210), (-95, -201), (-95, -194),
        (-91, -181), (-88, -163), (-82, -147), (-77, -134),
        (-71, -138), (-61, -141), (-51, -145), (-40, -147), (-31, -150),
        (-20, -152), (-9, -155), (1, -156), (12, -157), (22, -157),
        (34, -158), (46, -156)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(0.97, 0.81, 0.31), width=2)
    points = [(-96, -212), (52, -227), (52, -234), (-95, -220)]
    plotPoly(points, True, pencolor=(1, 1, 1),
             fillcolor=(1, 1, 1), width=1)
    points = [(-91, -228), (45, -240)]
    plotLine(points, pencolor=(1, 1, 1), width=2)

# 腿
def legs():
    # 右腿
    points = [
        (-107, -234), (-106, -237), (-110, -239), (-114, -238), (-120, -238),
        (-123, -237), (-128, -239), (-134, -240), (-142, -245), (-142, -235),
        (-144, -231), (-147, -224), (-148, -220), (-151, -215), (-157, -209),
        (-164, -204), (-171, -204), (-177, -204), (-183, -205), (-188, -206),
        (-191, -209), (-195, -215), (-198, -219), (-199, -224), (-199, -231),
        (-199, -237), (-198, -244), (-198, -249), (-195, -257), (-193, -262),
        (-190, -267), (-186, -274), (-181, -281), (-176, -284), (-172, -285),
        (-163, -286), (-157, -282), (-152, -278), (-149, -273), (-146, -268),
        (-139, -264), (-129, -261), (-123, -261), (-111, -259), (-101, -260),
        (-98, -265), (-98, -260), (-101, -258), (-101, -255), (-102, -254),
        (-103, -249), (-100, -245), (-104, -241)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(1, 0.82, 0.71), width=2)
    points = [
        (-188, -224), (-187, -219), (-186, -215), (-185, -212), (-182, -206)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (-142, -244), (-142, -249), (-143, -256), (-144, -262), (-145, -267)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)

    # 左腿
    points = [
        (115, -264), (123, -266), (130, -268), (135, -262), (142, -256),
        (151, -255), (160, -255), (165, -259), (170, -263), (175, -270),
        (177, -280), (180, -289), (181, -295), (180, -301), (179, -309),
        (175, -315), (168, -320), (162, -323), (155, -323), (147, -323),
        (139, -319), (135, -311), (130, -304), (129, -296), (128, -287),
        (132, -287), (123, -287), (115, -285), (107, -284)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(1, 0.82, 0.71), width=2)
    points = [
        (153, -302), (154, -309), (155, -315), (158, -320), (159, -323)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)

# 头
def head():
    points = [
        (-139, -80), (-147, -76), (-151, -73), (-156, -68), (-158, -64),
        (-161, -59), (-164, -53), (-164, -49), (-165, -41), (-165, -36),
        (-169, -30), (-172, -27), (-176, -17), (-177, -12), (-178, -5),
        (-179, -1), (-179, 7), (-177, 16), (-175, 25), (-174, 29),
        (-177, 34), (-179, 41), (-181, 47), (-182, 51), (-183, 59),
        (-183, 64), (-181, 76), (-180, 81), (-178, 88), (-174, 94),
        (-169, 100), (-167, 106), (-167, 114), (-167, 123), (-165, 131),
        (-162, 139), (-161, 144), (-154, 151), (-150, 156), (-147, 160),
        (-141, 164), (-135, 168), (-132, 170), (-130, 178), (-125, 189),
        (-122, 195), (-117, 200), (-114, 203), (-103, 212), (-95, 215),
        (-81, 218), (-72, 218), (-67, 223), (-63, 226), (-55, 234),
        (-51, 238), (-43, 243), (-36, 246), (-27, 248), (-22, 254),
        (-20, 261), (-15, 265), (-9, 267), (-1, 270), (5, 276),
        (13, 283), (22, 284), (29, 288), (37, 288), (43, 287),
        (50, 291), (50, 293), (59, 297), (67, 299), (76, 302),
        (83, 306), (90, 312), (92, 318), (100, 314), (103, 311),
        (109, 307), (115, 300), (120, 293), (123, 283), (123, 278),
        (131, 274), (140, 271), (148, 264), (152, 256), (153, 247),
        (152, 242), (160, 240), (165, 233), (171, 224), (182, 217),
        (187, 213), (192, 207), (195, 202), (199, 195), (200, 189),
        (207, 187), (216, 183), (224, 179), (264, 118), (271, 112),
        (277, 103), (280, 93), (280, 85), (282, 77), (282, 68),
        (279, 60), (279, 54), (279, 44), (284, 36), (286, 27),
        (286, 13), (289, 3), (286, -8), (283, -15), (279, -23),
        (275, -30), (269, -36), (271, -42), (272, -50), (269, -57),
        (268, -65), (267, -69), (265, -75), (263, -80), (258, -85),
        (254, -91), (249, -94), (242, -102), (235, -106), (223, -111)
    ]
    
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (-27, 248), (-24, 242), (-21, 237), (-18, 232), (-13, 229),
        (-9, 227), (-2, 224)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (1, 269), (6, 265), (11, 258), (16, 253), (24, 249),
        (30, 248), (37, 245), (47, 245)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (45, 286), (46, 280), (48, 275), (53, 271), (62, 267)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (123, 276), (121, 273), (115, 270), (112, 268), (105, 266),
        (98, 266)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (152, 244), (146, 239), (138, 235), (128, 236), (117, 236),
        (104, 237)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
    points = [
        (168, 223), (168, 217), (163, 210), (159, 205), (154, 203),
        (143, 202), (137, 201), (131, 201)
    ]
    plotLine(points, pencolor=(0.67, 0.5, 0.22), width=2)
# 羊角
def horns():
    # 羊角(左)
    points = [
        (194, 169), (201, 165), (209, 171), (216, 176), (224, 181),
        (231, 184), (244, 188), (258, 192), (271, 194), (281, 194),
        (288, 192), (296, 191), (301, 189), (306, 188), (311, 185),
        (316, 182), (318, 177), (319, 172), (317, 168), (313, 163),
        (311, 160), (310, 158), (306, 153), (300, 151), (293, 148),
        (291, 145), (285, 141), (281, 139), (278, 136), (275, 132),
        (272, 127), (268, 123), (265, 118), (257, 113), (251, 105),
        (254, 102), (257, 96), (254, 102), (251, 106), (245, 109),
        (238, 105), (237, 110), (236, 118), (233, 124), (229, 129),
        (225, 131), (219, 132), (216, 132), (215, 135), (215, 139),
        (216, 148), (215, 150), (214, 154), (209, 160), (205, 162)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(0.51, 0.37, 0.28), width=2)
    # 羊角(右)
    points = [
        (-119, 201), (-122, 205), (-124, 211), (-128, 216), (-135, 223),
        (-139, 232), (-140, 240), (-141, 249), (-137, 254), (-129, 256),
        (-119, 257), (-110, 256), (-98, 253), (-90, 250), (-81, 246),
        (-74, 242), (-66, 237), (-59, 230), (-62, 225), (-71, 217),
        (-82, 217), (-94, 215), (-104, 211), (-111, 204)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(0.51, 0.37, 0.28), width=2)

# 耳朵
def ears():
    # 耳朵(左)
    points = [
        (229, 68), (233, 70), (242, 70), (250, 69), (257, 65),
        (263, 58), (269, 51), (274, 44), (278, 38), (282, 31),
        (288, 25), (294, 20), (296, 19), (293, 16), (285, 12),
        (281, 9), (274, 7), (267, 6), (262, 6), (252, 6),
        (241, 9), (234, 12), (228, 18), (221, 29), (217, 40),
        (218, 52), (220, 60), (225, 64)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(1, 0.82, 0.72), width=2)

    # 耳朵(右)
    points = [
        (-165, 112), (-174, 109), (-179, 106), (-187, 103), (-188, 101),
        (-185, 97), (-182, 91), (-178, 88), (-176, 90), (-174, 92),
        (-167, 99), (-165, 102), (-165, 108)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(1, 0.82, 0.72), width=2)

# 眼睛
def eyes():
    # 眼睛(右)
    t.color((0.67, 0.5, 0.22), (1, 1, 1))
    t.width(2)
    t.up()
    t.goto(-71, 8)
    t.down()
    t.begin_fill()
    t.circle(30)
    t.end_fill()

    t.pencolor((0.1, 0.1, 0.1))
    t.up()
    t.goto(-71, 37)
    t.down()
    t.dot(25)

    t.pencolor((1, 1, 1))
    t.up()
    t.goto((-74, 41))
    t.down()
    t.dot(9)

    # 眼睛(左)
    t.color((0.67, 0.5, 0.22), (1, 1, 1))
    t.up()
    t.goto(36, -12)
    t.down()
    t.begin_fill()
    t.circle(30)
    t.end_fill()

    t.pencolor((0.1, 0.1, 0.1))
    t.up()
    t.goto(39, 18)
    t.down()
    t.dot(25)

    t.pencolor((1, 1, 1))
    t.up()
    t.goto((34, 22))
    t.down()
    t.dot(9)

# 眉毛
def eyebrows():
    # 眉毛(左)
    points = [
        (-82, 89), (-78, 92), (-74, 95), (-67, 97), (-60, 97),
        (-54, 95), (-48, 93), (-45, 91), (-41, 89), (-38, 86),
        (-35, 83)
    ]
    plotLine(points, (0.67, 0.5, 0.22), width=2)

    # 眉毛(右)
    points = [
        (22, 74), (26, 77), (31, 80), (40, 82), (48, 82),
        (55, 80), (63, 78), (70, 74), (75, 70), (79, 65)
    ]
    plotLine(points, (0.67, 0.5, 0.22), width=2)


# 鼻子
def nose():
    points = [
        (-39, 2), (-46, 0), (-52, -2), (-55, -6), (-56, -10),
        (-56, -14), (-55, -17), (-52, -20), (-48, -23), (-44, -25),
        (-40, -26), (-35, -27), (-30, -28), (-24, -27), (-21, -26),
        (-17, -23), (-15, -21), (-14, -17), (-14, -12), (-15, -9),
        (-20, -4), (-22, -3), (-26, -1), (-30, 0), (-33, 1)
    ]
    plotPoly(points, True, pencolor=(0.2, 0.14, 0.11),
             fillcolor=(0.2, 0.14, 0.11), width=2)
    t.pencolor((1, 1, 1))
    t.up()
    t.goto((-22, -12))
    t.down()
    t.dot(10)

# 嘴巴
def mouth():
    points = [
        (-71, -44), (-69, -48), (-63, -53), (-64, -56), (-66, -66),
        (-65, -78), (-65, -87), (-62, -92), (-59, -99), (-56, -103),
        (-50, -106), (-47, -109), (-39, -111), (-29, -111), (-23, -110),
        (-18, -108), (-13, -105), (-10, -102), (-6, -97), (-1, -90),
        (2, -83), (5, -75), (6, -69), (6, -60), (11, -65),
        (7, -61), (5, -58), (3, -53), (5, -58), (2, -58),
        (-5, -60), (-9, -60), (-14, -62), (-20, -62), (-25, -60),
        (-34, -60), (-43, -59), (-52, -57), (-58, -55), (-62, -54),
        (-67, -49)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(0.89, 0.48, 0.43), width=2)
    points = [
        (-62, -54), (-60, -55), (-57, -55), (-54, -57), (-49, -58),
        (-47, -60), (-50, -61), (-55, -63), (-59, -67), (-64, -72),
        (-65, -75), (-66, -69), (-65, -60)
    ]
    plotPoly(points, True, pencolor=(0.67, 0.5, 0.22),
             fillcolor=(0.63, 0.24, 0.25), width=0)

if __name__ == "__main__":
    turtle.setup(1.0, 1.0)
    turtle.title("懒羊羊")
    t = turtle.Turtle()
    t.screen.delay(0)
    t.hideturtle()
    face()
    hands()
    body()
    cloth()
    legs()
    head()
    horns()
    ears()
    eyes()
    eyebrows()
    nose()
    mouth()
    turtle.mainloop()

懒羊羊是一个受欢迎的卡通形象,通常与轻松、懒惰和幽默联系在一起。虽然没有官方的"懒羊羊Python代码",我们可以创建一个简单的Python程序来模拟懒羊羊的行为或特征。以下是一个示例Python代码,模拟懒羊羊的一天: ```python import time import random class LazySheep: def __init__(self, name): self.name = name def sleep(self, hours): print(f"{self.name}正在睡觉...zzz") time.sleep(hours * 3600) # 模拟睡眠时间 def eat(self): print(f"{self.name}正在吃草...") time.sleep(random.randint(1, 3)) # 模拟进食时间 def play(self): print(f"{self.name}正在玩耍...偶尔跳一下") time.sleep(random.randint(1, 2)) def day_in_life(self): print(f"{self.name}的一天开始了!") self.sleep(8) # 睡8小时 print("起床了!") self.eat() print("吃完早饭,继续小憩一下...") self.sleep(1) print("午后时光,开始玩耍...") self.play() print("玩累了,再吃一顿...") self.eat() print("晚上到了,继续睡觉...") self.sleep(8) print(f"{self.name}的一天结束了,晚安!") # 创建懒羊羊实例 lazy_sheep = LazySheep("懒羊羊") # 模拟懒羊羊的一天 lazy_sheep.day_in_life() ``` 这段代码创建了一个`LazySheep`类,模拟懒羊羊的一天生活。它包括睡觉、吃饭和玩耍等行为,使用`time.sleep()`函数来模拟时间流逝。`day_in_life`方法展示了懒羊羊一天的活动流程。 运行这段代码,你会看到懒羊羊的一天是如何度过的,主要是在睡觉和吃东西,偶尔玩耍一下。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值