Skip to content

Instantly share code, notes, and snippets.

@boustrophedon
Last active March 7, 2019 21:11
Show Gist options
  • Save boustrophedon/db8bc42053b37018d39803c0d65843dc to your computer and use it in GitHub Desktop.
Save boustrophedon/db8bc42053b37018d39803c0d65843dc to your computer and use it in GitHub Desktop.
animated quadratic
import 'dart:html';
main() async {
CanvasElement canvas = querySelector("canvas");
canvas.width = 500;
canvas.height = 500;
var ctx = canvas.context2D;
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 500, 500);
ctx.strokeStyle = 'black';
ctx.lineWidth = 10;
ctx.lineCap = 'square';
var start = [0, 250];
var end = [500, 250];
var midy = 0;
var dir = 1;
while (true) {
ctx.fillRect(0, 0, 500, 500);
var path = Path2D();
path.moveTo(start[0], start[1]);
path.quadraticCurveTo(250, midy, end[0], end[1]);
ctx.stroke(path);
await window.animationFrame;
midy += dir;
if (midy > 500) {
midy = 500;
dir = -1;
}
else if (midy < 0) {
midy = 0;
dir = 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment