# Starry Night

After a visit to the Griffith Observatory, I decided to attempt the creation of an applet that would procedurally create an artificial version of the pictures taken by telescopes like Hubble. And here’s what I came up with.

Basically, I defined two types of space objects: stars and galaxies. The stars are composed of two sub objects: A simple ellipse and what I called a “streak,” which is just two triangles that share one side and are mirror images of each other. Every star has between 3 and 5 of these “streaks,” in order to make them look like they are very bright. The galaxies are a bit more mathy. They use a couple of trigonometric functions. First I started with mathematically creating a circle of points. Then, I changed the circle a bit in order to have the radius of it go from 0 to some other number, which resulted in a spiral shape. After that, I made the points’ positions slightly random to create a cloud-like look. All that work amounted to a single “arm” of a galaxy. To make more “arms”, I just had to duplicate the first “arm” and rotate it.

The next step was to create thousands of these stars and galaxies and position them randomly on the screen. Using the “random()” function in Processing resulted in an unnatural distribution of the stars and galaxies. What I did instead was a little more complex but much better visually. I used the “noise()” function to decide how many stars and galaxies should be made in each part of the screen. This way, the stars and galaxies appear to be formed into clumps, with some areas denser than others.

Finally, here is the applet:

Starry Night

Note: Each new image takes about 10 to 30 seconds to create. To make a new image, tap any key.