xxxxxxxxxx
50
// Drag Force
// Insprired by: The Nature of Code
// The Coding Train / Daniel Shiffman
// https://youtu.be/DxFDgOYEoy8
//
// Here I have made modifications to The Coding Train's Code which he made in The Nature of Code #2.4
// The balls with different masses fall through 3 different liquids with random Coefficient of Drags, these liquids have their opacity based on their densities/Drag Coefficient.
let movers = [];
let liqs = [];
let mu = 0.1;
function setup() {
createCanvas(400, 600);
for (let i = 0; i < 10; i++) {
movers[i] = new Mover(random(width), 10, random(0.8, 10));
}
liqs.push(new liquid(0, 100, width, 50));
liqs.push(new liquid(0, 250, width, 50));
liqs.push(new liquid(0, 400, width, 50));
}
function draw() {
background(0);
fill(255, 125);
noStroke();
for (let mover of movers) {
if (mouseIsPressed) {
let wind = createVector(0.1, 0);
mover.applyForce(wind);
}
let gravity = createVector(0, 0.2);
let weight = p5.Vector.mult(gravity, mover.mass);
mover.applyForce(weight);
for(let l of liqs){
if(l.intersecting(mover.pos.x, mover.pos.y)){
mover.drag(l.c);
}
}
mover.update();
mover.edges();
mover.show();
}
for(let l of liqs){
l.show();
}
}