import turtle
import time

screen = turtle.Screen()
screen.title("水的三态变化 + 云的形成 + 水循环")
screen.setup(1000, 600)
screen.bgcolor("#c6e2ff")
screen.tracer(0)

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

# ==================================================
# 左侧：水的三态变化
# ==================================================
pen.penup()
pen.goto(-440, 220)
pen.color("#1a3b5d")
pen.write("水的三态变化", font=("SimHei", 14, "bold"))

# 冰
pen.penup()
pen.goto(-420, 120)
pen.color("#ffffff")
pen.begin_fill()
for _ in range(6):
    pen.forward(40)
    pen.left(60)
pen.end_fill()
pen.color("#222")
pen.goto(-420, 90)
pen.write("冰（固态）", align="center", font=("SimHei", 12))

# 水
pen.penup()
pen.goto(-300, -10)
pen.color("#348ade")
pen.begin_fill()
pen.circle(30)
pen.end_fill()
pen.color("#222")
pen.goto(-300, -45)
pen.write("水（液态）", align="center", font=("SimHei", 12))

# 水蒸气
pen.penup()
pen.goto(-180, 120)
pen.color("#d6ecff")
pen.begin_fill()
pen.circle(25)
pen.end_fill()
pen.color("#222")
pen.goto(-180, 90)
pen.write("水蒸气（气态）", align="center", font=("SimHei", 12))

def arrow(x1, y1, x2, y2, label, lx, ly):
    pen.penup()
    pen.goto(x1, y1)
    pen.pendown()
    pen.goto(x2, y2)
    pen.stamp()
    pen.penup()
    pen.goto(lx, ly)
    pen.write(label, font=("SimHei", 11))

arrow(-390, 90, -330, 10, "熔化", -370, 50)
arrow(-330, 10, -390, 80, "凝固", -370, 20)
arrow(-270, 10, -210, 90, "汽化", -250, 50)
arrow(-210, 90, -270, 10, "液化", -250, 20)
arrow(-380, 110, -200, 110, "升华", -290, 130)
arrow(-200, 110, -380, 110, "凝华", -290, 95)

# ==================================================
# 中间：云的形成过程
# ==================================================
pen.penup()
pen.goto(-60, 220)
pen.color("#1a3b5d")
pen.write("云的形成", font=("SimHei", 14, "bold"))

# 底部小水珠区域
pen.penup()
pen.goto(0, 40)
pen.color("#73a6d6")
pen.begin_fill()
pen.circle(12)
pen.end_fill()
pen.penup()
pen.goto(-25, 50)
pen.color("#73a6d6")
pen.begin_fill()
pen.circle(8)
pen.end_fill()
pen.penup()
pen.goto(28, 55)
pen.color("#73a6d6")
pen.begin_fill()
pen.circle(9)
pen.end_fill()
pen.penup()
pen.goto(0, 20)
pen.color("#222")
pen.write("底部小水珠", align="center", font=("SimHei", 11))

# 上升箭头
pen.penup()
pen.goto(0, 60)
pen.pendown()
pen.goto(0, 140)
pen.stamp()
pen.penup()
pen.goto(12, 95)
pen.write("上升凝结", font=("SimHei", 11))

# 云底到云顶：颜色由浅蓝逐渐变白
cloud_color_levels = [
    ("#b9d7f2", 140),
    ("#d2e6f7", 150),
    ("#e6f1fb", 160),
    ("#f4f8fd", 170),
    ("#ffffff", 180)
]

for color, y in cloud_color_levels:
    pen.penup()
    pen.goto(-35, y)
    pen.color(color)
    pen.begin_fill()
    pen.circle(18)
    pen.goto(-15, y + 8)
    pen.circle(22)
    pen.goto(12, y)
    pen.circle(18)
    pen.goto(-15, y - 8)
    pen.circle(16)
    pen.end_fill()

pen.penup()
pen.goto(0, 200)
pen.color("#222")
pen.write("大云朵（白色）", align="center", font=("SimHei", 11))

# 云形成说明
pen.penup()
pen.goto(0, -10)
pen.color("#333")
pen.write("小水珠上升、聚集、凝结，云体变大，颜色变白",
          align="center", font=("SimHei", 10))

# ==================================================
# 右侧：水循环
# ==================================================
pen.penup()
pen.goto(300, 220)
pen.color("#1a3b5d")
pen.write("水循环", font=("SimHei", 14, "bold"))

# 海洋
pen.penup()
pen.goto(220, -180)
pen.pendown()
pen.color("#2060c0")
pen.begin_fill()
pen.goto(470, -180)
pen.goto(470, -250)
pen.goto(220, -250)
pen.goto(220, -180)
pen.end_fill()
pen.penup()
pen.goto(345, -210)
pen.color("white")
pen.write("海洋", align="center", font=("SimHei", 14, "bold"))
pen.color("black")

# 云
def draw_cloud(x, y):
    c = turtle.Turtle()
    c.hideturtle()
    c.speed(0)
    c.penup()
    c.goto(x, y)
    c.color("white")
    c.begin_fill()
    c.circle(20)
    c.goto(x + 20, y + 10)
    c.circle(25)
    c.goto(x + 45, y)
    c.circle(20)
    c.goto(x + 20, y - 10)
    c.circle(18)
    c.end_fill()
    return c

cloud = draw_cloud(320, 120)
pen.penup()
pen.goto(340, 150)
pen.write("云", font=("SimHei", 14, "bold"))

# 水循环箭头
pen.penup()
pen.goto(280, -170)
pen.pendown()
pen.goto(280, 110)
pen.stamp()
pen.penup()
pen.goto(255, -20)
pen.write("蒸发", font=("SimHei", 13))

pen.penup()
pen.goto(410, 110)
pen.pendown()
pen.goto(410, -170)
pen.stamp()
pen.penup()
pen.goto(430, -20)
pen.write("降雨", font=("SimHei", 13))

# ==================================================
# 动画：水汽上升 + 云变白 + 下雨
# ==================================================
def vapor_up():
    for _ in range(3):
        vapor = turtle.Turtle(shape="circle")
        vapor.shapesize(0.35)
        vapor.color("#cce7ff")
        vapor.penup()
        start_x = 275 + _ * 5
        vapor.goto(start_x, -170)
        for __ in range(70):
            vapor.sety(vapor.ycor() + 2)
            screen.update()
            time.sleep(0.015)
        vapor.hideturtle()

def cloud_white_gradually():
    pen.penup()
    for i in range(6):
        color = [
            "#b9d7f2",
            "#c7e0f6",
            "#d9ecfa",
            "#eaf4fc",
            "#f6faff",
            "#ffffff"
        ][i]
        y = 120 + i * 4
        pen.goto(290, y)
        pen.color(color)
        pen.begin_fill()
        pen.circle(18)
        pen.goto(310, y + 8)
        pen.circle(22)
        pen.goto(335, y)
        pen.circle(18)
        pen.goto(310, y - 8)
        pen.circle(16)
        pen.end_fill()
        screen.update()
        time.sleep(0.25)

def rain_down():
    for _ in range(5):
        drop = turtle.Turtle(shape="circle")
        drop.shapesize(0.25)
        drop.color("#2060c0")
        drop.penup()
        start_x = 395 + _ * 4
        drop.goto(start_x, 110)
        for __ in range(90):
            drop.sety(drop.ycor() - 3)
            screen.update()
            time.sleep(0.02)
        drop.hideturtle()

while True:
    vapor_up()
    time.sleep(0.2)
    cloud_white_gradually()
    time.sleep(0.3)
    rain_down()
    time.sleep(0.5)

turtle.done()
