https://editor.p5js.org/oae233/sketches/PY1m1F8nQ
Concept / Idea
Originally, I wanted to use invisible attractors with a minimum distance between the attractor & the movers to create the shape of a human skeleton. I would then have this object as a class and have different skeletons attract and repel each other at various points. After I implemented the minimum distance function, I realised that I quite liked the effect it creates with movers, especially when connected to some user input, like the mouse position, it felt like catching the movers in a net and then you’re able to fling them back into an orbit. The lines drawn from the movers to the attractor and the trail effect add interesting visual details.
Functions
So I only added two functions from the ones that were in the original example.
distCheck():
this function continuously checks if the ditsance between a mover and the attractor is less than that movers minimum distance (defined as distLimit), and if it is, it sets the velocity and acceleration of that mover to 0, causing it to stop
wind():
this function calls the applyForce function to apply wind with a random direction & magnitude (between certain specified values) only when the mouse is pressed. The purpose of this function is to “shake things up a bit” when the user wants to. Because of the randomness of the wind, the movers stuck to the attractor break free while going at different directions, which makes them more likely to go into interesting orbits instead of just uniformly moving away from the attractor. Other movers lose thier orbit and stick to the attractor instead.
Some code I want to highlight:
I thought I’d highlight the two functions I mentioned above just to show how they would work.
// "that" , opposed to this, is the attractor, it is passed through to this function in the sketch.js file draw() function distCheck(that) { let dist = p5.Vector.dist(this.pos, that.pos); if ( dist < this.distLimit){ this.vel.set(0); this.acc.set(0); } } wind(){ if (mouseIsPressed){ let windy = createVector(random(-10,20),random(-10,5)); this.applyForce(windy); } } }
Future work:
I think it would be really interesting to implement my initial idea and create a skeleton using attractors with distance limits between them and their movers and watch how such a structure might react under different forces acting upon it. I also think more could be done in this example to make it look more visually developed or complex, maybe making the shapes of the movers more dynamic instead of a static circle.