Created
March 7, 2022 14:44
-
-
Save andrusenn/8d27d87fab09781cc676733d30a25ea3 to your computer and use it in GitHub Desktop.
Harmonograph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Harmonograph { | |
constructor() { | |
this.theta = 0.0; | |
this.phi = 0.0; | |
this.vel_theta = 0; | |
this.vel_phi = 0; | |
this.alpha = 0.0; | |
this.radio_x1; | |
this.vel_alpha = 0; | |
this.friction = 0; | |
this.multr = 1; | |
this.x = 0.0; | |
this.y = 0.0; | |
this.minfricc = 0; | |
// Centro del plano / Center of plane | |
this.cx = 0.0; | |
this.cy = 0.0; | |
this.icx = 0.0; | |
this.icy = 0.0; | |
this.movx = 0.0; | |
this.movy = 0.0; | |
this.initrx2 = 0; | |
this.initry2 = 0; | |
this.noise_size = 0.001; | |
this.noise_size2x = 0; | |
this.noise_size2y = 0; | |
this.n; | |
this.n2; | |
this.fr = true; | |
} | |
setVelPendulum1() {} | |
update() { | |
this.n = noise(this.x * this.noise_size, this.y * this.noise_size); | |
this.n2 = noise(this.x * this.noise_size2x, this.y * this.noise_size2y); | |
this.noise_size = map(this.n2, 0, 1, 0.002, 0.008); | |
let rx1 = map(this.n, 0, 1, 2160 * 0.06, 2160 * 0.1) * this.multr; | |
let ry1 = map(this.n, 0, 1, 2160 * 0.1, 2160 * 0.06) * this.multr; | |
let rx2 = map(this.n, 0, 1, 2160 * 0.25, 2160 * 0.4) * this.multr; | |
let ry2 = map(this.n, 0, 1, 2160 * 0.25, 2160 * 0.4) * this.multr; | |
// Pendulum 1 | |
this.cx = this.icx + this.movx + cos(-this.theta) * rx1; | |
this.cy = this.icy + this.movy + sin(this.phi) * ry1; | |
// Pendulum 2 | |
this.x = this.cx + sin(this.alpha) * rx2; | |
this.y = this.cy + cos(this.alpha) * ry2; | |
this.theta += this.vel_theta; | |
this.phi += this.vel_phi; | |
if (this.multr < this.minfricc && this.fr) { | |
this.fr = false; | |
} | |
if (this.multr > 0.99 && !this.fr) { | |
this.fr = true; | |
} | |
if (this.fr) { | |
this.multr *= this.friction; | |
} else { | |
this.multr /= this.friction; | |
} | |
this.alpha += this.vel_alpha; | |
// add center movement | |
this.movx -= 0; | |
this.movy -= 0.0022; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment