var CanvasParticle=(function(){function getElementByTag(name){return document.getElementsByTagName(name);} function getELementById(id){return document.getElementById(id);} function canvasInit(canvasConfig){canvasConfig=canvasConfig||{};var html=getElementByTag("html")[0];var body=document.getElementById("mydiv");var canvasObj=document.createElement("canvas");var canvas={element:canvasObj,points:[],config:{vx:canvasConfig.vx||4,vy:canvasConfig.vy||4,height:canvasConfig.height||2,width:canvasConfig.width||2,count:canvasConfig.count||100,color:canvasConfig.color||"121, 162, 185",stroke:canvasConfig.stroke||"130,255,255",dist:canvasConfig.dist||6000,e_dist:canvasConfig.e_dist||20000,max_conn:10}};if(canvas.element.getContext("2d")){canvas.context=canvas.element.getContext("2d");}else{return null;} body.style.padding="0";body.style.margin="0";body.appendChild(canvas.element);canvas.element.style="position: inherit; top: 0; left: 0; z-index: -1;";canvasSize(canvas.element);window.onresize=function(){canvasSize(canvas.element);} body.onmousemove=function(e){var event=e||window.event;canvas.mouse={x:event.clientX,y:event.clientY}} document.onmouseleave=function(){canvas.mouse=undefined;} setInterval(function(){drawPoint(canvas);},40);} function canvasSize(canvas){var width=document.getElementById("mydiv").style.width;var height=document.getElementById("mydiv").style.height;width=parseInt(width);height=parseInt(height);canvas.width=width||window.innerWeight||document.documentElement.clientWidth||document.body.clientWidth;canvas.height=height||window.innerWeight||document.documentElement.clientHeight||document.body.clientHeight;} function drawPoint(canvas){var context=canvas.context,point,dist;context.clearRect(0,0,canvas.element.width,canvas.element.height);context.beginPath();context.fillStyle="rgb("+canvas.config.color+")";for(var i=0,len=canvas.config.count;i=canvas.element.width){p.vx=-p.vx;p.x+=p.vx;}else if(point.y<=0||point.y>=canvas.element.height){p.vy=-p.vy;p.y+=p.vy;}else{p={x:p.x+p.vx,y:p.y+p.vy,vx:p.vx,vy:p.vy}} return p;} function drawLine(context,canvas,mouse){context=context||canvas.context;for(var i=0,len=canvas.config.count;icanvas.config.dist&&dist<=canvas.config.e_dist){canvas.points[i].x=canvas.points[i].x+(mouse.x-canvas.points[i].x)/20;canvas.points[i].y=canvas.points[i].y+(mouse.y-canvas.points[i].y)/20;} if(dist<=canvas.config.e_dist){context.lineWidth=1;context.strokeStyle="rgba("+canvas.config.stroke+","+(1-dist/canvas.config.e_dist)+")";context.beginPath();context.moveTo(canvas.points[i].x,canvas.points[i].y);context.lineTo(mouse.x,mouse.y);context.stroke();}}}} return canvasInit;})();