Created
April 14, 2017 02:54
-
-
Save animatedlew/b79d122baaa9064cd06f8ed77255dfec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let canvas = document.createElement("canvas"); | |
canvas.width = 400; | |
canvas.height = 400; | |
let ctx = canvas.getContext("2d"); | |
document.body.appendChild(canvas); | |
function lerp(a, b, t) { | |
return a * (1-t) + b * t; | |
} | |
function h2(t) { | |
let sq = t * t; | |
let cb = sq * t; | |
return (-2 * cb + 3 * sq); | |
} | |
const MAX = canvas.width - 1; | |
for(let i = 0, x = 0; i < MAX; i++, x++) { | |
let t = i/MAX; | |
let t2 = h2(t); | |
ctx.fillStyle = "steelblue"; | |
ctx.fillRect(canvas.height - x, | |
lerp(0, MAX, t), 2, 2); | |
ctx.fillStyle = "orange"; | |
ctx.fillRect(canvas.height - x, | |
lerp(0, MAX, t2), 2, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment