Concept
For this week’s assignment I wanted to recreate one of the most beautiful motions in nature, shooting stars. My idea was to have the stars fall from the top but be affected by the planets gravity which changes their direction. I also decided to add a path (line) behind the shooting starts which slowly filles up the screen and creates this beautiful drawing of all the paths the stars took. The users can also click on the screen to move the planets around and thus create completely unique paths every time.
Process
First order of business was to create the star filled background and to add planets. This is also when I added the click to add planets function so I wouldn’t have to deal with it later.
After this was done it was time to get started on adding shooting stars. I decided to also give them a trail so they would actually look nicer while “falling” and wouldn’t just be a ball passing by.
This is done by first saving the last position of the star as the first one in the array:
// save tail this.tail.unshift(this.pos.copy()); if (this.tail.length > this.tailMax) this.tail.pop();
After which we draw the tail on the last position of the star with this:
draw() {
// Tail
for (let i = 0; i < this.tail.length - 1; i++) {
let a = map(i, 0, this.tail.length - 1, 220, 0);
let w = map(i, 0, this.tail.length - 1, 10, 1);
stroke(255, 255, 255, a);
strokeWeight(w);
line(this.tail[i].x, this.tail[i].y, this.tail[i + 1].x, this.tail[i + 1].y);
}
And now we have a tail following the star. I also added the “this.tail.pop()” to make sure the last position in the array (not the starts last position, technically the “first” ones) is deleted to keep the array shorter. And now we had shooting stars in the sketch.
But I felt like something was missing so I added the lines that are left behind the start so add a nice trail like drawing to the experience. To do this I decided to use createGraphics to keep it cleaner and more organized and to make sure the paths will always be visible. Using createGraphics also allowed the trail drawing to persist independently of the main animation loop, which clears each frame. This separation made it possible to accumulate motion into a lasting visual pattern.
pathLayer = createGraphics(width, height); pathLayer.clear(); // transparent at the start let prev = s.pos.copy(); s.update(); // draw path pathLayer.stroke(255, 35); pathLayer.strokeWeight(1.2); pathLayer.line(prev.x, prev.y, s.pos.x, s.pos.y); s.draw();
The prev stores where the star was before updating and the update moves the star. Then we use .line to create the path which when run every frame creates the path that we see in the final product.
Code Highlight
Even though my proudest part of code is the path layer one where I create a path behind the shooting stars, since I went over that part of the code I will explain my second proudest.
function solarWind(x, y) {
let a = noise(x * 0.01, y * 0.01, frameCount * 0.01) * TWO_PI * 2;
return p5.Vector.fromAngle(a).mult(WIND);
}
This, even though simple code I believe adds a nice touch to the overall feel and vibe of the sketch. Rather than applying random turbulence, I used Perlin noise to generate a smooth directional field across space. The noise value is converted into an angle and then into a vector, producing gentle, continuous variations in star motion. This force adds complexity without visual chaos, allowing trajectories to subtly diverge while still being primarily governed by planetary gravity.
Future Improvements
I am incredibly proud of how the final code turned out, but if I was to change anything in the future I would probably play with the color of the path that follows the shooting stars and or maybe it’s thickness. I would also explore the possibility of adding more planet options or maybe even planet star collision system.