# 彼岸花(曼珠沙华)Python代码 ```python import turtle import math def draw_flower(): # 设置画布和画笔 screen = turtle.Screen() screen.bgcolor("black") screen.title("彼岸花") pen = turtle.Turtle() pen.speed(0) pen.hideturtle() # 彼岸花参数 petals = 6 # 花瓣数量 petal_length = 100 # 花瓣长度 petal_width = 30 # 花瓣宽度 center_radius = 20 # 花心半径 # 绘制花蕊 pen.penup() pen.goto(0, -center_radius) pen.pendown() pen.color("yellow") pen.begin_fill() pen.circle(center_radius) pen.end_fill() # 绘制花瓣 pen.color("red") for i in range(petals): # 移动到花瓣起始位置 angle = i * (360 / petals) x = center_radius * math.cos(math.radians(angle)) y = center_radius * math.sin(math.radians(angle)) pen.penup() pen.goto(x, y) pen.pendown() # 绘制单个花瓣 pen.setheading(angle) pen.begin_fill() pen.forward(petal_length) pen.left(90) pen.circle(petal_width, 180) pen.left(90) pen.forward(petal_length) pen.end_fill() # 绘制花茎 pen.penup() pen.goto(0, -center_radius) pen.pendown() pen.color("green") pen.pensize(5) pen.setheading(270) pen.forward(200) turtle.done() # 调用函数绘制彼岸花 draw_flower() ``` 这段代码使用Python的turtle模块绘制了一朵红色的彼岸花(曼珠沙华),包含以下特征: - 6片红色花瓣 - 黄色花蕊 - 绿色花茎 - 黑色 运行代码后会显示一个图形窗口展示绘制结果。 需要注意的逻辑点: 1. 花瓣数量、长度和宽度可以通过修改petals、petal_length和petal_width变量调整 2. 花蕊大小由center_radius控制,颜色在begin_fill()和end_fill()之间设置 3. turtle的坐标系以屏幕中心为原点(0,0),向上为Y轴正方向 [2025-04-23 23:14:41 | AI写代码神器 | 567点数解答]