/* * ---------------------------------------------------------------------------- * "the beer-ware license" (revision 42): * wrote this file. as long as you retain this notice, * you can do whatever you want with this stuff. if we meet some day, and you * think this stuff is worth it, you can buy me a beer in return. * ---------------------------------------------------------------------------- */ (function($){$.fn.polygonizr=function(options){var defaults={restnodemovements:1,duration:3,nodemovementdistance:100,numberofnodes:25,nodedotsize:2.5,nodeease:"easeout",nodefancyentrance:!1,randomizepolygonmeshnetworkformation:!0,specifypolygonmeshnetworkformation:function(i){var foreachnode={x:this.canvaswidth-((this.canvaswidth/2)+(this.canvasheight/2)*math.cos(i*(2*math.pi/this.numberofnodes)))*math.random(),y:this.canvasheight-(this.canvasheight*(i/this.numberofnodes))};return foreachnode},noderelations:3,animationfps:30,nodedotcolor:"240, 255, 250",nodelinecolor:"240, 255, 250",nodefillcolor:"240, 255, 250",nodefillalpha:0.2,nodelinealpha:0.3,nodedotalpha:0.3,nodefillsapce:!0,nodeglowing:!1,canvaswidth:$(this).width(),canvasheight:$(this).height(),canvasposition:"absolute"};var settings=$.extend({},defaults,options);return this.each(function(){var m_this=$(this);var canvaselement=document.createelement('canvas');canvaselement.width=settings.canvaswidth;canvaselement.height=settings.canvasheight;canvaselement.style.position=settings.canvasposition;m_this.append(canvaselement);var ctx=canvaselement.getcontext('2d');var nodes=[];setupclusternodes();startnodeanimations();function setupclusternodes(){for(var i=0;i=(m_duration+m_delay)){m_lastframeupdate=timestamp;m_newtargetpossition=!0;m_entrancesingleton=!1}} m_requestid=m_requestanimationframe(step)} this.isrunning=!1;this.start=function(){if(!this.isrunning){this.isrunning=!0;m_duration=duration*1000;m_delay=delay*1000;m_requestid=m_requestanimationframe(step)}};this.pause=function(){if(this.isrunning){m_cancleanimationframe(m_requestid);this.isrunning=!1;m_starttime=null;m_framecount=-1}};var m_requestanimationframe=window.requestanimationframe||window.mozrequestanimationframe||window.webkitrequestanimationframe||window.orequestanimationframe||window.msrequestanimationframe;var m_cancleanimationframe=window.cancelanimationframe||window.mozcancelrequestanimationframe||window.webkitcancelrequestanimationframe||window.ocancelrequestanimationframe||window.mscancelrequestanimationframe;var m_starttime=null;var m_framecount=-1 var m_requestid=null;var m_lastframeupdate=null;var m_newtargetpossition=!0;var m_entrancesingleton=!0;var m_duration;var m_delay} function geteasing(easing,currenttime,startpossition,targetpossition,endtime){switch(easing){case constants.animation.easing_linear:return(targetpossition-startpossition)*(currenttime/endtime)+startpossition;break;case constants.animation.easing_easein:currenttime/=endtime;return(targetpossition-startpossition)*math.pow(currenttime,2)+startpossition;case constants.animation.easing_easeout:currenttime/=endtime;return-(targetpossition-startpossition)*currenttime*(currenttime-2)+startpossition;case constants.animation.easing_easeinout:currenttime/=(endtime/2);if(currenttime<1)return(targetpossition-startpossition)/2*math.pow(currenttime,2)+startpossition;return-(targetpossition-startpossition)/2*((currenttime-1)*((currenttime-1)-2)-1)+startpossition;break;case constants.animation.easing_accelerate:currenttime/=(endtime/2);if(currenttime<1)return(targetpossition-startpossition)/2*math.pow(currenttime,3)+startpossition;return(targetpossition-startpossition)/2*(math.pow(currenttime-2,3)+2)+startpossition;break;case constants.animation.easing_descending:currenttime/=(endtime/2);if(currenttime<1)return(targetpossition-startpossition)/math.pow(currenttime,3)+startpossition;return(targetpossition-startpossition)/(math.pow(currenttime-2,3)+2)+startpossition;break;default:return geteasing(constants.animation.easing_linear,currenttime,startpossition,targetpossition,endtime)}} function setnewnodepossition(easing,currenttime,endtime){for(var i in nodes){nodes[i].currentx=geteasing(easing,currenttime,nodes[i].startx,nodes[i].targetx,endtime);nodes[i].currenty=geteasing(easing,currenttime,nodes[i].starty,nodes[i].targety,endtime)}} function setnewtargetpossition(){for(var i in nodes){nodes[i].targetx=nodes[i].originx+(math.random()<0.5?-math.random():math.random())*settings.nodemovementdistance;nodes[i].targety=nodes[i].originy+(math.random()<0.5?-math.random():math.random())*settings.nodemovementdistance;nodes[i].startx=nodes[i].currentx;nodes[i].starty=nodes[i].currenty}} function setalphalevel(node){var screendistance=math.sqrt(math.pow(settings.canvaswidth,2)+math.pow(settings.canvasheight,2));var nodedistance=getdistance(node,node.closest[0]);for(var i in node.closest){nodedistance+=getdistance(node.closest[i],node.closest[(i+1)%node.closest.length])} var generalalpha=1-(nodedistance/screendistance);node.linealpha=generalalpha*settings.nodelinealpha;node.dotalpha=generalalpha*settings.nodedotalpha;if(generalalpha>0.85){node.fillalpha=generalalpha*settings.nodefillalpha;node.linealpha=settings.nodelinealpha;node.dotalpha=settings.nodedotalpha}else if(generalalpha<0.8&&generalalpha>0.7){node.fillalpha=0.5*generalalpha*settings.nodefillalpha;node.linealpha=settings.nodelinealpha;node.dotalpha=settings.nodedotalpha}else if(generalalpha<0.7&&generalalpha>0.4){node.fillalpha=0.2*generalalpha*settings.nodefillalpha}else{node.fillalpha=0}} function draw(){ctx.clearrect(0,0,settings.canvaswidth,settings.canvasheight);for(var i in nodes){drawlines(nodes[i]);drawcircle(nodes[i])}} function drawlines(node){if(!node.linealpha>0&&!node.fillalpha>0)return;for(var i in node.closest){if(node.linealpha>0){ctx.beginpath();ctx.moveto(node.currentx,node.currenty);ctx.lineto(node.closest[i].currentx,node.closest[i].currenty);ctx.strokestyle='rgba('+settings.nodelinecolor+','+node.linealpha+')';ctx.stroke()} if(settings.nodefillsapce&&node.fillalpha>0){ctx.beginpath();ctx.moveto(node.currentx,node.currenty);ctx.lineto(node.closest[i].currentx,node.closest[i].currenty);ctx.lineto(node.closest[(i+1)%node.closest.length].currentx,node.closest[(i+1)%node.closest.length].currenty);ctx.fillstyle='rgba('+settings.nodefillcolor+','+node.fillalpha+')';ctx.fill()}}} function drawcircle(node){if(!node.dotalpha>0)return;ctx.beginpath();ctx.arc(node.currentx,node.currenty,settings.nodedotsize,0,math.pi*2,!1);ctx.fillstyle='rgba('+settings.nodedotcolor+', '+node.dotalpha+')';if(settings.nodeglowing){ctx.shadowblur=10;ctx.shadowcolor='rgba('+settings.nodedotcolor+', '+node.dotalpha+')'} ctx.fill()} function getdistance(firstnode,secondnode){return math.sqrt(math.pow(firstnode.currentx-secondnode.currentx,2)+math.pow(firstnode.currenty-secondnode.currenty,2))}})}}(jquery))