xxxxxxxxxx
31
//Author: Idan Alter
//My blog: https://idan-alter.github.io/
//This code is part of my blog post:
//"How Did They Calculate Square Roots in 1700 BCE?"
let a = 1;
let b = 2;
let scl = 120;
let shift = 5;
function setup() {
createCanvas(650, 250);
background(220);
rect(shift, 5, a * scl, b * scl);
frameRate(2);
}
function draw() {
shift += a * scl;
let new_side = (a + b) / 2;
let new_side2 = 2 / new_side;
a = min(new_side, new_side2);
b = max(new_side, new_side2);
console.log({ a: a, b: b });
if (shift + a * scl > width) {
shift = 5;
background(220);
}
rect(shift, 5, a * scl, b * scl);
}