https://editor.p5js.org/ap6178/sketches/TCSSRFgfS
In this assignment, I wanted to experiment with mostly three kinds of phenomenons: gravitational attraction, turbulence and repulsion. To perform these experiments, I decided on auto-generating movers one at a time until it reaches a maximum threshold (then repeating this step), and placing a few attractors in place.
These attractors have a certain maximum displacement that they can move around with. This is to imitate how attractors in the universe also move by themselves. Movers are attracted to these attractors in place, which change the positions of each mover. But it is also important to remember that there is, in fact, a competition between these attractors. Movers move towards the one that can attract with more force.
When movers are near to each other, they are joined through a line. This resembles a communication channel between two movers in the universe. When they are very near to the attractors, they are sucked in.
This imitation of phenomenons creates a unique generative pattern as seen in the sketch.
Here are a few snippets that I’m particularly happy with:
Attractor.attract()
// gravitational attraction force to a mover attract(mover) { let force = p5.Vector.sub(this.position, mover.position); let distance = force.mag(); distance = constrain(distance, 5, 25); // constrain the distance let strength = 50 / (distance * distance); // attraction strength based on distance force.setMag(strength); mover.applyForce(force); }
Turbulence and Repulsion
// apply forces to movers and display them for (let mover of movers) { for (let attractor of attractors) { attractor.attract(mover); } // turbulence and repulsion forces let turbulence = createVector(random(-0.1, 0.1), random(-0.1, 0.1)); mover.applyForce(turbulence); for (let otherMover of movers) { if (mover !== otherMover) { let repulsion = p5.Vector.sub(mover.position, otherMover.position); let distance = repulsion.mag(); distance = constrain(distance, 5, 25); repulsion.setMag(-1 / (distance * distance)); mover.applyForce(repulsion); } } mover.update(); mover.display(); }
Future Improvements
I would love to add the drag force to imitate the asteroid belt. More like how certain things may hinder the movements in the universe.