// Gravitational Attraction // The Nature of Code // The Coding Train / Daniel Shiffman // https://youtu.be/EpgB3cNhKPM // https://thecodingtrain.com/learning/nature-of-code/2.5-gravitational-attraction.html // https://editor.p5js.org/codingtrain/sketches/MkLraatd let movers = []; let attractor; var canvas; function windowResized(){ resizeCanvas(windowWidth, windowHeight); } function setup() { canvas = createCanvas(windowWidth, windowHeight); canvas.position(0, 0); canvas.style("z-index", "-1") movers[0] = new Mover(width/4, height, 5, -5, 55); movers[0].col = color('red'); movers[1] = new Mover(3*width/4, height, -5, -5, 50); movers[1].col = color('white'); movers[2] = new Mover(2*width/4, height, -5, -5, 45); movers[2].col = color('blue'); background(0); } function draw() { background(0, 75); for (let mover of movers) { for (let other of movers) { if (mover !== other) { mover.attract(other); } } } for (let mover of movers) { mover.update(); mover.edges(); mover.show(); } }