var a=y=100,b=r=0,d=Math,e=d.cos,f=d.sin,g=d.random,h=d.round,j=e(r),k=f(r),l=d.PI,m=document.getElementById("c"),n=m.getContext("2d"),o=m.width=innerWidth,p=m.height=innerHeight,q=0.15,s="beginPath",t,u=["ADAA63","B87C4B","A14747","454545","2C8A79"];function v(c){n.strokeStyle="#"+u[h(b/40)%5];n[s]();n.moveTo(a,y);n.lineTo(a=h(a+c*j),y=h(y+c*k));n.stroke()}function w(c){j=e(r+=c/180*l);k=f(r)}for(var x="fx",z={x:"x+yf",y:"fx-y"};x.length<2500;){t="";for(i=0;i<x.length;i++)t+=z[x[i]]||x[i];x=t}
n.globalAlpha=q;n.font="40px serif";n.fillText("monster under my bed",40,p/2);n.translate(o/2,100);function A(c,B,C,D){n[s]();n.arc(c,B,C,D,l*2,false);n.fill()}
setInterval(function(){if(b<150){n.globalAlpha=0.02;n.fillStyle="#fff";A(100,100,8,0);A(200,100,8,0);n.fillStyle="#000";A(100,100,2,0);A(200,100,2,0);A(150,150,10,l);n.globalAlpha=q/=1.003;n.save();n.scale(1+b/90,1+b/90);b++;y=a=90;for(i=r=0;i<x.length;i++){if(x[i]=="f"){v(g()*6);j=e(r-=0.17);k=f(r)}if(x[i]=="+"){w(90);v(5)}x[i]=="-"&&w(90)}n.restore()}},50);
/**
* I was always inspired by things hidden under my bed.
* Yesterday I did a research and here is the result.
*/
var x = y = 100,
sc = r = 0,
M = Math,
cos = M.cos,
sin = M.sin,
rnd = M.random,
ro = M.round,
dx = cos(r),
dy = sin(r),
PI = M.PI,
canvas = document.getElementById('c'),
ctx = canvas.getContext('2d'),
w = canvas.width = innerWidth,
h = canvas.height = innerHeight,
as = 0.15,
GA = "globalAlpha",
BP = "beginPath",
dt,
result,
colors = ['ADAA63','B87C4B','A14747','454545','2C8A79']; // palette
function forward(units) {
// a color from the palette
ctx.strokeStyle = "#" + colors[ro(sc/40)%5];
ctx[BP]();
ctx.moveTo(x, y);
ctx.lineTo(x = ro(x + units * dx), y = ro(y + units * dy));
ctx.stroke();
}
function left(degree) {
dx = cos(r += degree / 180 * PI),
dy = sin(r);
}
// rules for the fractal generation
var iter = 'fx',
rules = {
'x': 'x+yf',
'y': 'fx-y'
};
// based on the rules we create the DNA of the monster
while (iter.length < 2500) {
result = "";
for (i = 0; i < iter.length; i++) result += rules[iter[i]] || iter[i];
iter = result;
}
// here comes the message
ctx[GA] = as;
ctx.font = '40px serif';
ctx.fillText('monster under my bed', 40, h/2);
ctx.translate(w/2, 100);
// eyes and mouth
function drawShape(x,y,r,b) {
ctx[BP]();
ctx.arc(x, y, r, b, PI * 2, false);
ctx.fill();
}
dt = setInterval( function draw() {
if (sc < 150) {
ctx[GA]= 0.02;
ctx.fillStyle = '#fff';
drawShape(100, 100, 8, 0);
drawShape(200, 100, 8, 0);
ctx.fillStyle = '#000';
drawShape(100, 100, 2, 0);
drawShape(200, 100, 2, 0);
drawShape(150, 150, 10, PI);
ctx[GA] = as /= 1.003;
ctx.save();
ctx.scale(1 + sc/90,1 + sc/90);
sc++;
x = 90;
y = 90;
r = 0;
for (i = 0; i < iter.length; i++) {
// based on the DNA we move differently
if (iter[i] == 'f') {
forward(rnd() * 6);
dx = cos(r -= 0.17),
dy = sin(r);
}
if (iter[i] == '+') {
left(90);
forward(5);
}
if (iter[i] == '-') left(90);
}
ctx.restore();
}
}, 50);