Skip to content

Instantly share code, notes, and snippets.

@charlenopires
Created November 28, 2014 02:23
Show Gist options
  • Save charlenopires/8065bbd72fa20bf26e36 to your computer and use it in GitHub Desktop.
Save charlenopires/8065bbd72fa20bf26e36 to your computer and use it in GitHub Desktop.
hello world.
<canvas id="main"></canvas>
(function(win, doc) {
"use strict";
var main = doc.getElementById("main"),
mainCtx = main.getContext("2d"),
sub = doc.createElement("canvas"),
subCtx = sub.getContext("2d"),
i = 0,
WIDTH = 250,
HEIGHT = 50,
SIZE = 5,
INTERVAL = 5;
main.width = sub.width = WIDTH;
main.height = sub.height = HEIGHT;
build(0);
setInterval(function() {
main.width = WIDTH;
mainCtx.font = "30px AvenirNext-Heavy";
mainCtx.fillText("HELLO WORLD.", 0, 30);
mainCtx.globalCompositeOperation = "destination-in";
mainCtx.drawImage(sub, 0, 0);
}, 1000 / 24);
function build(i) {
var height = HEIGHT / SIZE,
max = (i + 1 < height) ? (i + 1) : height;
(function setRect(j) {
if (j < max) {
subCtx.rect((i -j) * SIZE, j * SIZE, SIZE, SIZE);
subCtx.fill();
setTimeout(function() {
setRect(++j);
}, INTERVAL);
} else {
if ((i - HEIGHT / SIZE) * SIZE < win.innerWidth) {
build(++i);
}
}
})(0);
}
})(this, document);
@import "compass/css3";
body {
background: #e3e3e3;
}
#main {
position: absolute;
top: 50%; left: 50%;
margin: -15px -125px;
width: 250px; height: 50px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment