xxxxxxxxxx
58
function setup() {
}
function expoCalc(startTC, endTC, t) {
const maxY = (1-Math.pow(Math.E, (-endTC))); //scaling factor
if (endTC > startTC) return (1-Math.pow(Math.E, (t*-endTC)))/maxY;
return (Math.pow(Math.E, (t*-startTC)));
}
function draw() {
const screen_width = 800;
createCanvas(screen_width, 600);
background(220);
//let a = exp(mouseX /screen_width)/200 -.005;
let a = 0.01;
//if (mouseX <= 0) a =.01;
console.log(a);
//let d = 0.01;
let d = exp(mouseX /screen_width)/200 -.005;
let s = 0.75;
let s_count = 0; //time to sustain;
let r = 0.0025;
let stage = 0;
let y = 0.0;
let lastY = 0;
for (i = 0; i < screen_width; i++) {
let expo = y;
if(stage == 0) {
y += a;
if (y >= 1) {
stage = 1;
y= 1;
}
expo = expoCalc(0, 2.5, y);
} else if (stage == 1) {
y -= d;
expo = (expoCalc(6, 0, 1-y) * (1-s)) + s;
if (expo - s < .0001) stage = 2;
} else if (stage == 2) {
y = s;
expo = s;
if (s_count++ >= 10) stage = 3;
} else if (stage == 3) {
y -= r;
if (y < .0001) stage = 4;
expo = expoCalc(6, 0, 1-y/s)*s;
}
//point(i, ((1.1-y)*500));
//stroke(0,0,0);
//point(i, ((1.1-expo)*500));
line (i-1, (1.1-lastY)*500, i, (1.1-expo)*500);
lastY = expo;
}
}