1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| import turtle
def init_canvas(): turtle.title("Turtle绘图实验") turtle.speed(0) turtle.hideturtle() turtle.tracer(0)
def nested_stars(layers=5, start_size=200): colors = ['#FF0000', '#FFD700', '#4169E1', '#32CD32', '#9370DB'] init_canvas()
for i in range(layers): turtle.penup() turtle.goto(22*i, -5*i) turtle.setheading(0) turtle.pendown()
size = start_size * (0.7 ** i) color = colors[i % len(colors)]
turtle.color(color) turtle.begin_fill() for _ in range(5): turtle.forward(size) turtle.right(144) turtle.end_fill()
turtle.update()
def draw_polygon(sides=6, color='#FF69B4', size=100): init_canvas() turtle.penup() turtle.goto(-size / 2, -size / 2) turtle.setheading(0) turtle.pendown()
turtle.color(color) turtle.begin_fill()
angle = 360 / sides for _ in range(sides): turtle.forward(size) turtle.left(angle)
turtle.end_fill() turtle.update()
def rotating_flower(petals=24, size=80): init_canvas() colors = ['#FF1493', '#FF4500', '#FFD700', '#7FFF00', '#00BFFF']
for i in range(petals): turtle.color(colors[i % len(colors)]) angle = 360 / petals * i
turtle.penup() turtle.home() turtle.setheading(angle) turtle.forward(size / 3) turtle.pendown()
turtle.begin_fill() turtle.circle(size, 60) turtle.left(120) turtle.circle(size, 60) turtle.end_fill()
turtle.update()
if __name__ == "__main__": nested_stars() turtle.clearscreen()
draw_polygon(6, '#FF69B4', 150) turtle.clearscreen()
rotating_flower() turtle.done()
|