
centerx=250;
centery=250;
canw=window.innerWidth;
canh=window.innerHeight;
frameticker=0;
nmax=10;
maxstrings=9;
maxlength=50;
frametick=100;
framemax=100;
lastx=0;
entityarray=new Array();
//
setup(6);
//
//
//

//
logodiv=creatediv("logodiv", "#000000", "#000000", "<img src='kaologo.jpg'></img>");
logodiv.style.position='absolute';
logodiv.style.top=0;
logodiv.style.left=0;
//
//
maindiv=creatediv("maindiv", "#000000", "#000000", "<canvas id=\"maincanvas\" width=\""+window.innerWidth+"\" height=\""+window.innerHeight+"\"></canvas>");
maindiv.style.background='transparent';
maindiv.style.position='absolute';
maindiv.style.top=0;
maindiv.style.left=0;
//

//

//
canv=document.getElementById('maincanvas');
rawcanv=document.getElementById('maincanvas').getContext('2d');
rawcanv.strokeStyle="#ffffff";
rawcanv.lineWidth=4;
img = new Image();
img.src = 'ucpat.jpg';
img.onload = function(){
	ptrn = rawcanv.createPattern(img,'repeat');
	rawcanv.fillStyle = ptrn;
}
setInterval(enterframe,70);

function setup(numtoadd){
	for(a=0;a<numtoadd;a++){
		newpart=new Array(Math.round(Math.random()*canw), Math.round(Math.random()*canh));
		entityarray.push(newpart);
	}
}


function enterframe(){
	rawcanv.clearRect(0,0,canw, canh);
	rawcanv.beginPath();
	for(a=0;a<entityarray.length;a++){
		if(lastx!=0){
			rawcanv.lineTo(lastx, entityarray[a][3]);
		}
		for(b=2;b<entityarray[a].length;b+=2){
			rawcanv.lineTo(entityarray[a][b], entityarray[a][b+1]);
			lastx=entityarray[a][b];
		}
		orx=entityarray[a][entityarray[a].length-2];
		ory=entityarray[a][entityarray[a].length-1];
		nstep=Math.floor(Math.random()*nmax);
		dirchoice=Math.floor(Math.random()*4);
		if(dirchoice==0){
			entityarray[a].push(orx+nstep);
			entityarray[a].push(ory-nstep);
		}
		if(dirchoice==1){
			entityarray[a].push(orx+nstep);
			entityarray[a].push(ory+nstep);
		}
		if(dirchoice==2){
			entityarray[a].push(orx-nstep);
			entityarray[a].push(ory+nstep);
		}
		if(dirchoice==3){
			entityarray[a].push(orx-nstep);
			entityarray[a].push(ory-nstep);
		}
		if(entityarray[a].length>=maxlength){
			entityarray[a]=entityarray[a].slice(2);
		}
	}
	rawcanv.closePath();
	rawcanv.fill();
	rawcanv.stroke();
}

function creatediv(id, colour, background, ihtml, ofh){
	ndiv = document.createElement('div');
	ndiv.setAttribute('id', id);
	ndiv.innerHTML=ihtml;
	ndiv.style.color=colour;
	ndiv.style.background=background;
	if(ofh){
		ndiv.style.overflow='hidden';
	}
	document.body.appendChild(ndiv);
	return ndiv;
}

