生成漂亮的星空图案
我正在尝试使用 C++ 和 SDL 为游戏生成滚动星空。我使用的是一种简单、幼稚的算法,它只是在黑色背景上创建大量白色像素。然而,这个“星空”看起来太不自然了——可能是因为随机数生成器的质量很差(我使用 rand() 函数)。
是否有任何特殊的算法来生成看起来或多或少真实的星场?
谢谢。
I'm trying to generate a scrolling starfield for a game with C++ and SDL. I'm using a simple, naive algorithm that just creates a lot of white pixels on black backround. However, this "starfield" looks too unnatural - probably because of the random number generator's poor quality (I use the rand() function).
Are there any special algorithms for generating starfields that look more or less realistic?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
总是有这个 经典。亮点:
There's always this classic. Highlights:
不久前,我发现了这个有用的教程,关于创建一个“现实”的星场。它不是 C++,但一旦你明白了它的想法,它应该很容易适应。
I found this useful tutorial a while ago on creating a 'realistic' star field. It's not C++, but it should be easily adaptable once you get the idea.
您可以使用劳埃德算法来放松随机点并使它们成为半随机的。我在地图生成器 但它可能也可以用来创建一个最终分布式的星域。
You could use Lloyd's algorithm to relax the random points and make them semi-random. I read this idea in a map generator but it probably can be used do create an eventually distributed star field too.
您可能不希望它是真正随机的。当您确实希望各个像素分散在周围时,最终会在某些地方出现像素斑点。你最好的选择可能是编写一个较小的部分,然后一遍又一遍地重复它以获得完整的星空外观。
You probably don't want it to be truly random. You will end up with blobs of pixels in some places when you really want individual pixels scattered around. Your best bet would probably be to code a smaller section and then just repeat it over and over to get the full starfield look.