昆虫变态发育模拟

import turtle
import time

# 初始化环境:ml-citation{ref="4" data="citationList"}
screen = turtle.Screen()
screen.title("完全变态发育模拟")
screen.setup(800, 600)
screen.bgcolor("#1a1a1a")  # 暗色背景增强对比:ml-citation{ref="6" data="citationList"}
screen.tracer(0)

artist = turtle.Turtle()
artist.hideturtle()
artist.speed(0)
artist.pensize(2)

# 生物特征参数:ml-citation{ref="1" data="citationList"}
COLORS = {
    "larva_body": ("#87C735", "#5A8F29"),  # 幼虫体色
    "larva_head": "#3D6420",  # 幼虫头部
    "pupa": ("#8B7355", "#634B32"),  # 蛹体颜色
    "adult_body": ("#D4AF37", "#B8860B"),  # 成虫金属光泽:ml-citation{ref="6" data="citationList"}
    "wing": ("#F0E68C", "#FFFACD")  # 翅膀渐变色
}


def draw_segment(pos, width, colors):
    """绘制体节结构:ml-citation{ref="1" data="citationList"}"""
    artist.penup()
    artist.goto(pos[0], pos[1] - width // 2)
    artist.pendown()
    artist.color(colors[0], colors[1])
    artist.begin_fill()
    artist.setheading(0)
    artist.forward(40)
    artist.left(90)
    artist.forward(width)
    artist.left(90)
    artist.forward(40)
    artist.left(90)
    artist.forward(width)
    artist.end_fill()


def draw_larva(progress):
    """幼虫生长动画:ml-citation{ref="1,7" data="citationList"}"""
    artist.clear()

    # 头部:ml-citation{ref="1" data="citationList"}
    artist.penup()
    artist.goto(-15, 30)
    artist.color(COLORS["larva_head"])
    artist.begin_fill()
    artist.circle(12)
    artist.end_fill()

    # 分节身体:ml-citation{ref="7" data="citationList"}
    segments = int(6 * progress)
    for i in range(segments):
        y_offset = -i * 25
        draw_segment((-20, y_offset), 25 - i * 2, COLORS["larva_body"])

    # 伪足运动:ml-citation{ref="1" data="citationList"}
    artist.color("#5A8F29")
    for side in [-1, 1]:
        artist.penup()
        artist.goto(side * 15, -segments * 25 + 10)
        artist.pendown()
        artist.setheading(side * 45 * (1 - progress))
        artist.forward(20 * progress)


def draw_pupa(progress):
    """蛹态转化动画:ml-citation{ref="1,7" data="citationList"}"""
    artist.clear()

    # 蛹体膨胀:ml-citation{ref="7" data="citationList"}
    artist.penup()
    artist.goto(0, -150 * (1 - progress))
    artist.pendown()
    artist.color(COLORS["pupa"][0], COLORS["pupa"][1])
    artist.begin_fill()
    artist.setheading(0)
    artist.circle(80 * progress, 360)
    artist.end_fill()

    # 表面纹理:ml-citation{ref="1" data="citationList"}
    artist.color("#634B32")
    for angle in range(0, 360, 30):
        artist.penup()
        artist.goto(0, 0)
        artist.setheading(angle)
        artist.forward(60 * progress)
        artist.pendown()
        artist.forward(20 * progress)


def draw_adult(progress):
    """成虫羽化动画:ml-citation{ref="1,6" data="citationList"}"""
    artist.clear()

    # 身体主体:ml-citation{ref="6" data="citationList"}
    artist.penup()
    artist.goto(-40, -100 + 80 * progress)
    artist.pendown()
    artist.color(COLORS["adult_body"][0], COLORS["adult_body"][1])
    artist.begin_fill()
    artist.setheading(0)
    artist.forward(80)
    artist.left(90)
    artist.forward(120)
    artist.left(90)
    artist.forward(80)
    artist.left(90)
    artist.forward(120)
    artist.end_fill()

    # 翅膀展开动画:ml-citation{ref="6" data="citationList"}
    wing_angle = 180 * progress
    for side in [-1, 1]:
        artist.penup()
        artist.goto(side * 50, 60)
        artist.pendown()
        artist.color(COLORS["wing"][0], COLORS["wing"][1])
        artist.begin_fill()
        artist.setheading(90 + side * wing_angle)
        artist.forward(100)
        artist.left(120 * progress)
        artist.forward(150 * progress)
        artist.left(60 * progress)
        artist.forward(100)
        artist.end_fill()

    # 触角运动:ml-citation{ref="1" data="citationList"}
    artist.color("black")
    for side in [-1, 1]:
        artist.penup()
        artist.goto(side * 10, 120)
        artist.pendown()
        artist.setheading(80 * progress + side * 30)
        artist.forward(40)


def animate_phase(phase_func, duration=3):
    """通用动画控制器:ml-citation{ref="2,5" data="citationList"}"""
    for frame in range(1, 31):
        progress = frame / 30
        phase_func(progress)
        screen.update()
        time.sleep(duration / 30)


# 执行完整生命周期:ml-citation{ref="7" data="citationList"}
phases = [
    (draw_larva, "幼虫阶段"),
    (draw_pupa, "蛹态阶段"),
    (draw_adult, "成虫阶段")
]

for phase_func, label in phases:
    screen.title(f"完全变态发育模拟 - {label}")
    animate_phase(phase_func)

turtle.done()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值