Last active
September 12, 2016 01:26
-
-
Save ynaoto/51bc44426c8b00b2d22c6f3ec27cd5c4 to your computer and use it in GitHub Desktop.
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
var h = 575; // x vertex, half of total bounce duration | |
var k = 160; // y vertex, total bounce height | |
var a = -4 * k / Math.pow(h * 2, 2); // coefficient: -.000483932 | |
var ypos, start, time; | |
function setup() { | |
createCanvas(66, 226); | |
fill('#EC245E'); | |
noStroke(); | |
} | |
function draw() { | |
var timestamp = millis(); | |
if (!start) { start = timestamp }; | |
time = timestamp - start; | |
// Position as a function of time, using the vertex form | |
// of the quadratic formula: f(x) = a(x - h)^2 + k, | |
// (where [h, k] is the vertex). See it graphically at: | |
// https://www.desmos.com/calculator/i6yunccp7v | |
ypos = a * Math.pow(((time + h) % (h * 2) - h), 2) + k; | |
clear(); | |
ellipse(30, 200 - ypos, 30, 30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment