c=document.body.children[0];c.width=400;c.height=400;w=c.width;h=c.height;d=c.getContext("2d");pI=parseInt;pi=Math.PI;mC=Math.cos;mS=Math.sin;mR=Math.random;od=d.createImageData(w,h);function
g(a,e,b,f,l){ix=(e+b*w)*4;a.data[ix+0]=(f&16711680)>>16;a.data[ix+1]=(f&65280)>>8;a.data[ix+2]=f&255;a.data[ix+3]=l}var j=[];function k(a,e,b){j.length>200||j.push({x:a||pI(mR()*c.width),y:e||pI(mR()*c.height),a:b||mR()*pi*3,d:pI(mR()*16777215),c:0,b:50})}for(i=15;i--;)k();
setInterval(function(){id=d.getImageData(0,0,w,h);j.forEach(function(a){if(!a.c){if(!a.b)if(id.data[(a.x+a.y*w)*4]==0&&id.data[(a.x+a.y*w)*4+3]==255||a.x<0||a.y<0||a.x>w||a.y>h){s=a.x+pI(100*mC(-a.a));t=a.y+pI(100*mS(-a.a));u=a.a*pi/2*5;k(s,t,u*mR());k(s,t,u*mR());a.c=1;return}a.b=a.b<0?0:a.b-1;g(od,a.x,a.y,0,255);for(var e=20+mR()*20,b=2;b<=30;b++){px=a.x+pI(b*mC(a.a+pi/2));py=a.y+pI(b*mS(a.a+pi/2));id.data[(px+py*w)*4+3]>0||g(od,px,py,a.d,25*(e/2-b))}a.x+=pI(2*mC(a.a));a.y+=pI(2*mS(a.a))}});d.putImageData(od,
0,0);id=0},100);
/***********************************************************
* (c) 2010 Nikhil Marathe <nsm.nikhil@gmail.com>
* A rough implementation of Substrate
* http://complexification.net/gallery/machines/substrate/
***********************************************************/
c = document.body.children[0];
c.width = 400;
c.height = 400;
w = c.width;
h = c.height;
d = c.getContext('2d');
pI = parseInt;
pi = Math.PI;
mC=Math.cos;
mS=Math.sin;
mR = Math.random;
od = d.createImageData(w, h);
function pix( x, y) {
return (x+y*w)*4;
}
// since our image data's are always the size of the
// canvas
// we can use canvas size and save some bytes
function setPixel(iD, x, y, c,a) {
ix = (x + y * w) * 4;
iD.data[ix+0] = (c&0xff0000)>>16;
iD.data[ix+1] = (c&65280)>>8;
iD.data[ix+2] = c&255;
iD.data[ix+3] = a
}
var cracks = []
function createCrack(x,y,a) {
if( cracks.length > 200 ) return;
cracks.push( {
x: x||pI(mR() * c.width),
y: y||pI(mR()*c.height),
a: a||(mR()*pi*3),
c:pI(mR()*0xffffff),
d:0,
imm:50
});
}
function update() {
id = d.getImageData(0, 0, w, h)
cracks.forEach(function(i) {
if(i.d) return;
if(i.imm);
else if((id.data[pix( i.x,i.y)]==0 &&
id.data[pix( i.x,i.y)+3]==255 ) ||
i.x < 0 || i.y < 0 || i.x > w || i.y > h ) {
s=i.x+pI(100*mC(-i.a)), t=i.y+pI(100*mS(-i.a)), u=i.a*pi/2*5;
createCrack(s, t, u*mR());
createCrack(s, t, u*mR());
i.d = 1;
return;
}
i.imm = i.imm<0?0:i.imm-1;
setPixel(od, i.x, i.y, 0, 255);
var upTo = 20 + mR()*20;
for(var j=2; j <= 30; j++) {
px = i.x+pI(j*mC(i.a+pi/2));
py = i.y+pI(j*mS(i.a+pi/2));
if( id.data[pix( px, py)+3] > 0 )
continue;
setPixel(od, px, py, i.c, 25*(upTo/2-j));
}
i.x += pI(2*mC(i.a));
i.y += pI(2*mS(i.a));
});
d.putImageData(od, 0, 0);
id = 0;
}
i=15;
while(i--)
createCrack();
setInterval( update, 100 );