我想编写一个函数,该函数将在这张图片(http://tinypic.com/r/34il9hu/6)的天空中创建一个随机数(在 m 和 n 之间,包括在内)星星。我希望星星应该由单个白色像素或由 4 个相邻白色像素组成的正方形随机组成。我也不想在树枝、月亮或鸟上放置一个“星星”(1 个像素)尽管
我将如何在 python 中做到这一点?任何人都可以帮忙吗?谢谢!
到目前为止我有这个:
到目前为止,我已经开始并提出了这一点,我不知道其中是否正确,或者即使我走在正确的轨道上:
def randomStars(small, large):
import random
file = pickAFile()
pic = makePicture(myPic)
#x = random.randrange(getWidth(pic))
#y = random.randrange(getHeight(pic))
for pixel in pic.getAllPixels():
if random.random() < 0.25:
pixel.red = random.randint(256)
pixel.green = random.randint(256)
pixel.blue = random.randint(256)
show(pic)
Run Code Online (Sandbox Code Playgroud)
我不知道我在做什么:(