xxxxxxxxxx
170
// Functions from https://easings.net/
// Repurposed for random number generation with different distributions
var numResults = 3000;
var easingFunctions = [];
var resultsDim = 190;
var resultsGap = 30;
var cols = 4;
var rows = 3;
function setup() {
createCanvas(910, 930);
noStroke();
fill(0,0,0);
totalDim = resultsDim + resultsGap;
easingFunctions = [
standard, easeInSine, easeInQuad, easeInCubic, easeInQuart, easeInQuint, easeInExpo, easeInCirc,
easeInOutSine, easeInOutCubic, easeInOutQuart,
easeInOutCirc, easeOutInSine, easeOutInCubic, gaussian]
}
function draw() {
push();
fill(255);
stroke(0);
rect(0,0,width,height);
pop();
let j = 0;
for (let easing of easingFunctions){
let col = j % cols;
let row = int(j / cols);
let minX = col * totalDim + resultsGap;
let maxX = minX + resultsDim;
let minY = row * totalDim + resultsGap;
let maxY = minY + resultsDim;
push();
noFill();
stroke(200);
rect(minX, minY, resultsDim);
pop();
for (let i = 0; i < numResults; i++){
let x = map(easing(random()), 0, 1, minX, maxX);
let y = map(random(), 0, 1, minY, maxY);
ellipse(x, y, 1);
}
text(easing.name, minX, maxY + 15);
j++;
}
noLoop();
}
function standard(x) {
return x;
}
function easeInSine(x){
let ans = 1 - cos((x * PI) / 2);
return ans;
}
function easeInQuad(x){
return x * x;
}
function easeInQuart(x) {
return x * x * x * x;
}
function easeInCubic(x) {
return x * x * x;
}
function easeInQuint(x){
return x * x * x * x * x;
}
function easeInExpo(x){
return x === 0 ? 0 : pow(2, 10 * x - 10);
}
function easeInCirc(x){
return 1 - sqrt(1 - pow(x, 2));
}
function easeInBack(x){
const c1 = 1.70158;
const c3 = c1 + 1;
return map(c3 * x * x * x - c1 * x * x, -0.1, 1, 0, 1);
}
function easeInOutSine(x) {
return -(cos(PI * x) - 1) / 2;
}
function easeInOutCubic(x) {
return x < 0.5 ? 4 * x * x * x : 1 - pow(-2 * x + 2, 3) / 2;
}
function easeInOutQuart(x){
return x < 0.5 ? 8 * x * x * x * x : 1 - pow(-2 * x + 2, 4) / 2;
}
function easeInOutCirc(x){
return x < 0.5
? (1 - sqrt(1 - pow(2 * x, 2))) / 2
: (sqrt(1 - pow(-2 * x + 2, 2)) + 1) / 2;
}
function gaussian(x){
return randomGaussian(0.5, 0.1);
}
function easeOutInCubic(x){
if (x < 0.5){
x = map(x, 0, 0.5, 0, 1);
return map(1 - pow(1 - x, 3), 0, 1, 0, 0.5)
}
else{
x = map(x, 0.5, 1, 0, 1);
return map(x * x * x, 0, 1, 0.5, 1)
}
}
function easeOutInSine(x){
if (x < 0.5){
x = map(x, 0, 0.5, 0, 1);
return map(sin((x * PI) / 2), 0, 1, 0, 0.5) // out
}
else{
x = map(x, 0.5, 1, 0, 1);
return map(1 - cos((x * PI) / 2), 0, 1, 0.5, 1) // in
}
}
function easeOutBounce(x) {
const n1 = 7.5625;
const d1 = 2.75;
if (x < 1 / d1) {
return n1 * x * x;
} else if (x < 2 / d1) {
return n1 * (x -= 1.5 / d1) * x + 0.75;
} else if (x < 2.5 / d1) {
return n1 * (x -= 2.25 / d1) * x + 0.9375;
} else {
return n1 * (x -= 2.625 / d1) * x + 0.984375;
}
}
function easeOutSine(x) {
return sin((x * PI) / 2);
}