颜色随机的五角星的python代码
以下是一个随机生成五角星并随机填充颜色的 Python 代码:
import turtle
import random
turtle.speed(0)
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
for i in range(10):
x = random.randint(-200, 200)
y = random.randint(-200, 200)
size = random.randint(50, 100)
color = random.choice(colors)
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
for j in range(5):
turtle.forward(size)
turtle.right(144)
turtle.end_fill()
turtle.done()
运行代码后,屏幕上将出现 10 个随机生成的五角星,每个五角星的大小、位置和填充颜色都是随机的。
原文地址: https://www.cveoy.top/t/topic/b1WO 著作权归作者所有。请勿转载和采集!