Starfield visualization in JavaScript

󰃭 2024-08-31

This is a simple, straightforward implementation of a visualization reminiscent of the classic Windows 95 starfield screensaver.

It is also interactive: you can touch the screen or use the accelerometer to influence the direction of the movement.

This is how it works:

  • Create a bunch of particles (100), each in a random position.
  • Every frame, move each particle further away from the center*. The further the particle is from the center, the more visible it will become. This gives the illusion that the particles are moving closer to the viewer, or that the viewer is going further into space.
  • The center is not really the center of the screen, but a variable point which can be influenced by the user by moving their cursor or tilting their device.
  • When the particles go outside of the view, put them near the center again, this keeps the visualization going on in perpetuity.

In this blog post, I want to share the heavily-commented source code to demonstrate how simple it is to create visually appealing animations with a few lines of code and basic math knowledge.

The visualization is embedded in an iframe below, but you can also click here to see it in its own page.

The code is available in this Gist:



More posts like this

Generating partner.jar for Salesforce API Integration

󰃭 2014-11-12 | #java #tutorials

I ran into a small issue recently when setting up a Java project to use the Salesforce APIs. Basically, you need to download a WSDL file from Salesforce, then use a tool made by them to generate a jar that you then include in your Java program. They instruct you to download force-wsc.jar and then run it, but when you run it you realize they didn’t pack the dependencies within the jar!

Continue reading 


Starry Sky in HTML5 Canvas - Part 2

󰃭 2019-04-13 | #canvas #javascript #programming-projects #tutorials

This is part of a series! Please make sure you have read Part 1 first! IMPORTANT – you can try out the result of this tutorial by visiting this CodeSandbox. However, I encourage you to read the blog post and try to follow along to understand how and why it works. Last time we left off with a very nice starry sky, but it’s a bit dead. We need to add some animation to it!

Continue reading 