import turtle

# 窗口设置
screen = turtle.Screen()
screen.title("扶老奶奶过马路")
screen.setup(1280, 960)
screen.tracer(0)  # 关闭自动刷新，消除重影
screen.bgcolor("#87CEEB")

pen = turtle.Turtle()
pen.hideturtle()
pen.speed(0)

# 画马路
def draw_road():
    pen.penup()
    pen.goto(-640, -180)
    pen.color("#333333")
    pen.begin_fill()
    pen.goto(640, -180)
    pen.goto(640, 180)
    pen.goto(-640, 180)
    pen.end_fill()

# 竖向斑马线
def draw_zebra():
    pen.color("white")
    strip_width = 70
    start_x = -550
    for i in range(10):
        pen.penup()
        pen.goto(start_x + i * 110, -180)
        pen.begin_fill()
        pen.goto(start_x + i * 110 + strip_width, -180)
        pen.goto(start_x + i * 110 + strip_width, 180)
        pen.goto(start_x + i * 110, 180)
        pen.end_fill()

# 精致小朋友
def draw_kid(x, y):
    t = turtle.Turtle()
    t.hideturtle()
    t.penup()

    # 头
    t.goto(x, y)
    t.color("peachpuff")
    t.begin_fill()
    t.circle(22)
    t.end_fill()

    # 头发
    t.color("#4a3728")
    t.penup()
    t.goto(x - 18, y + 18)
    t.pendown()
    t.goto(x - 12, y + 24)
    t.goto(x, y + 28)
    t.goto(x + 12, y + 24)
    t.goto(x + 18, y + 18)
    t.end_fill()

    # 眼睛
    t.penup()
    t.goto(x - 8, y + 5)
    t.color("black")
    t.begin_fill()
    t.circle(3)
    t.end_fill()
    t.penup()
    t.goto(x + 8, y + 5)
    t.begin_fill()
    t.circle(3)
    t.end_fill()

    # 微笑
    t.penup()
    t.goto(x - 6, y - 5)
    t.setheading(-10)
    t.pendown()
    t.color("red")
    t.circle(6, 120)
    t.setheading(0)

    # 上衣
    t.penup()
    t.goto(x, y - 30)
    t.color("#0033cc")
    t.begin_fill()
    t.pendown()
    t.goto(x - 18, y - 70)
    t.goto(x + 18, y - 70)
    t.goto(x, y - 30)
    t.end_fill()

    # 裤子
    t.color("#6699cc")
    t.penup()
    t.goto(x - 15, y - 70)
    t.pendown()
    t.goto(x - 18, y - 95)
    t.penup()
    t.goto(x + 15, y - 70)
    t.pendown()
    t.goto(x + 18, y - 95)

    # 鞋子
    t.color("white")
    t.penup()
    t.goto(x - 22, y - 95)
    t.begin_fill()
    t.goto(x - 8, y - 95)
    t.goto(x - 8, y - 105)
    t.goto(x - 22, y - 105)
    t.end_fill()
    t.penup()
    t.goto(x + 8, y - 95)
    t.begin_fill()
    t.goto(x + 22, y - 95)
    t.goto(x + 22, y - 105)
    t.goto(x + 8, y - 105)
    t.end_fill()

    # 搀扶的手
    t.color("peachpuff")
    t.penup()
    t.goto(x + 18, y - 40)
    t.pendown()
    t.goto(x + 45, y - 36)

    return t

# 精致老奶奶
def draw_grandma(x, y):
    t = turtle.Turtle()
    t.hideturtle()
    t.penup()

    # 白发
    t.goto(x, y)
    t.color("white")
    t.begin_fill()
    t.circle(26)
    t.end_fill()

    # 银发细节
    t.color("#dddddd")
    t.penup()
    t.goto(x - 20, y + 20)
    t.pendown()
    t.goto(x - 14, y + 26)
    t.goto(x, y + 30)
    t.goto(x + 14, y + 26)
    t.goto(x + 20, y + 20)
    t.end_fill()

    # 脸
    t.penup()
    t.goto(x, y)
    t.color("peachpuff")
    t.begin_fill()
    t.circle(19)
    t.end_fill()

    # 眼镜
    t.penup()
    t.goto(x - 10, y + 8)
    t.color("black")
    t.pendown()
    t.circle(5)
    t.penup()
    t.goto(x + 10, y + 8)
    t.pendown()
    t.circle(5)
    t.penup()
    t.goto(x - 5, y + 8)
    t.pendown()
    t.goto(x + 5, y + 8)
    t.penup()

    # 眼睛
    t.color("black")
    t.begin_fill()
    t.goto(x - 12, y + 9)
    t.circle(2)
    t.end_fill()
    t.begin_fill()
    t.goto(x + 8, y + 9)
    t.circle(2)
    t.end_fill()

    # 微笑
    t.penup()
    t.goto(x - 6, y - 6)
    t.setheading(-10)
    t.color("red")
    t.pendown()
    t.circle(7, 120)
    t.setheading(0)

    # 衣服
    t.penup()
    t.goto(x, y - 35)
    t.color("#704214")
    t.begin_fill()
    t.pendown()
    t.goto(x - 22, y - 75)
    t.goto(x + 22, y - 75)
    t.goto(x, y - 35)
    t.end_fill()

    # 拐杖
    t.color("#654321")
    t.penup()
    t.goto(x - 22, y - 45)
    t.pendown()
    t.goto(x - 38, y - 95)
    t.penup()
    t.goto(x - 42, y - 95)
    t.color("silver")
    t.pendown()
    t.circle(4)

    return t

# 绘制静态背景
draw_road()
draw_zebra()

# 初始位置
kid_x = 420
grandma_x = 470

kid = draw_kid(kid_x, 0)
grandma = draw_grandma(grandma_x, 0)

# 慢速过马路
while kid_x > -500:
    kid.clear()
    grandma.clear()

    kid_x -= 1
    grandma_x -= 1

    kid = draw_kid(kid_x, 0)
    grandma = draw_grandma(grandma_x, 0)

    screen.update()

# 文字
pen.penup()
pen.goto(0, 380)
pen.color("red")
pen.write("尊老爱幼，搀扶老人安全过马路", font=("微软雅黑", 28, "bold"), align="center")
screen.update()

turtle.done()