Hookes Law
Overview
Force Law - Spring
function setup() {
createCanvas(900, 400);
background(220);
(async function(){
let la = await import('/lib/linear-algebra/v1.0.0/linear-algebra.mjs');
let cd = await import('/lib/linear-algebra/v1.0.0/coordinates.mjs');
$global.la = la;
$global.vector = [[5],[0],[0]];
let k = 30;
let damp = 0;
let dt = 0.0001;
let matrix = [[0,-1*damp,-1*k],[dt,1,0],[0,dt,1]];
let multiply = la.copy(matrix);
let numberOfSteps = 100;
for(let i=1;i<numberOfSteps;i++){
multiply = la.multiply(matrix, multiply);
}
$global.multiply = multiply;
})();
}
function draw() {
if($global.la === undefined) return;
clear();
background(220);
let la = $global.la;
let vector = $global.vector;
vector = la.multiply($global.multiply, vector)
let x = (vector[0][0]*25000 +200);
$global.vector = vector;
ellipse(100,Math.round(x),80,80);
}
copy