So for my assignment this week, I really wanted to recreate either a Mexican wave or newton cradle but ended up kind of mixing the two together.
Trying to perfect the Newton Cradle was much harder than I thought so I started off with the following. It was a simple repetitive Mexican wave kind of motion that did not slow down.
After that example, I wanted there to be some periods so I added the following code so that the i variable would be a dependable factor and I achieved the following. I particularly like the look of when it regroups again and looks like it is starting fresh.
let period = 0.01 + i / 100;
I then wanted it to slow down after some time and add some colour, I liked the look of the HSB colour grid I used in my first assignment so I decided to add that again to achieve the following.
The slowing down effect took a lot more time then expected and I had to add a few Boolean variables and a few conditional statements.
if ( this.period.x < 0.005 && this.period.y < 0.005 && this.pos.x === this.origin.x && this.pos.y === this.origin.y ) { this.period.set(0, 0); // Reset the period to its original value this.ampl_x = 0; this.ampl_y = 0; slowingDown = true; // Set the flag to stop updating particles } else { this.pos.x = x + this.origin.x; this.angle.add(this.period); // Update the movement } }
https://editor.p5js.org/kk4827/full/llEuwJDBz
Improvements
I would love to try to implement the Newton cradle, maybe for my midterm and have the visuals look very compelling to real life and possible have some music or notes associated as each ball is hit upon.