如何用python画20个颜色、大小、位置随机的五角星?!,、
3条回答 默认 最新
叶灼hua 2023-12-03 23:34关注import turtle import random # 创建窗口 wn = turtle.Screen() wn.setup(width=600, height=600) # 定义五角星函数 def draw_pentagram(x, y, color, size): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.color(color) turtle.begin_fill() for i in range(5): turtle.forward(size) turtle.right(144) turtle.end_fill() # 绘制二十个五角星 for i in range(20): # 随机位置和颜色和大小 rand_x = random.randint(-250, 250) rand_y = random.randint(-250, 250) rand_color = random.choice(['red', 'orange', 'yellow', 'green', 'blue', 'purple']) size = random.randrange(-200, 200) draw_pentagram(rand_x, rand_y, rand_color, size) # 隐藏画笔 turtle.hideturtle() turtle.done()解决 无用评论 打赏 举报