4

我昨天刚刚了解了 Logo。我是九十年代出生的,以前从来没有遇到过。所以我开始使用 Joshua Bell 编写的在线Logo Interpreter,并决定编写一个circle制作同心圆的函数。这是我写的:

cs

to circle
penup forward :radius right 90
pendown repeat 360 [forward 3.14 * :radius / 180 right 1]
penup left 90 back :radius pendown
end

make "radius 30

repeat 160 [circle make "radius :radius + 30]

有趣的是,绘图画布是一个环形阵列。因此,圆圈最终重叠。通过以 30 的倍数绘制半径增加的 160 个同心圆,我最终得到了这样的图像:

由 160 个同心圆生成的徽标星域,半径以 30 的倍数递增。

这真是令人惊讶。乍一看,它看起来像是一张真实的夜空图片,这让我开始思考——有没有一种通用的算法来绘制星空?

顺便说一句,如果您仔细观察,您会看到一个30 x 30像素正方形网格。边界是黑色的,所以有点难以注意到。

4

2 回答 2

6

进行星空的常规方法是在 x/y 平面中随机选择点,在伪代码中类似于:

fill image with black
for (however many stars you want)
   x = random() * width
   y = random() * height
   plot star at position x,y 
loop 

如果你想变得花哨,你也可以绘制随机亮度的星星。还要记住星星会轻微闪烁,因此如果您正在制作动画,则每帧稍微改变亮度可以使它们看起来更逼真。

于 2013-05-12T14:01:31.957 回答
5

As an avid player of Dwarf Fortress, I would go for a fractal formula to generate the stars. Computer random is just not good enough, in my opinion. Borrowing from DF game again, I would add various steps to enhance the starfield such as randomizing the shape, color, size, glow, cluster (intentionally adding a clump of stars together).

If you wanna go with realism, also simulate gas background. Space is not white dots on a solid black background.

Finally, I would suggest you get some space images (from our old friend Hubble telescope) and try to copy it as faithfully as possible. Then play with the parameters to get to your liking (perhaps you want to make a game out of this).

PS:我没有指定任何编码语言,因为我认为这不是关于代码的问题(它非常基本),而是一个设计问题。相信我,在 Flash/ Actionscript中你会比在 Java 中更容易做到这一点。

于 2013-05-14T12:03:19.387 回答