|
|
|
@ -36,15 +36,15 @@ var dx=Math.cos(angle)*this.options.flySpeed,dy=Math.sin(angle)*this.options.fly
|
|
|
|
|
if((currentTop<landingPosition.top&&dy<0)||(currentTop>landingPosition.top&&dy>0)){dy=-1*dy;if(Math.abs(diffy)<Math.abs(dy)){dy=dy/4;}}
|
|
|
|
|
this.moveBug((currentLeft+dx),(currentTop+dy));},flyRand:function(){this.stop();var landingPosition={};landingPosition.top=this.random(this.options.edge_resistance,document.documentElement.clientHeight-this.options.edge_resistance);landingPosition.left=this.random(this.options.edge_resistance,document.documentElement.clientWidth-this.options.edge_resistance);this.startFlying(landingPosition);},startFlying:function(landingPosition){var currentTop=this.bug.top,currentLeft=this.bug.left,diffx=(landingPosition.left-currentLeft),diffy=(landingPosition.top-currentTop);this.bug.left=landingPosition.left;this.bug.top=landingPosition.top;this.angle_rad=Math.atan(diffy/diffx);this.angle_deg=this.rad2deg(this.angle_rad);if(diffx>0){this.angle_deg=90+this.angle_deg;}else{this.angle_deg=270+this.angle_deg;}
|
|
|
|
|
this.moveBug(currentLeft,currentTop,this.angle_deg);var that=this;this.flyperiodical=setInterval(function(){that.fly(landingPosition);},10);},flyIn:function(){if(!this.bug){this.makeBug();}
|
|
|
|
|
if(!this.bug)return;this.stop();var side=Math.round(Math.random()*4-0.5),d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],windowX=window.innerWidth||e.clientWidth||g.clientWidth,windowY=window.innerHeight||e.clientHeight||g.clientHeight;if(side>3)side=3;if(side<0)side=0;var style={},s;if(side===0){style.top=(-2*this.options.bugHeight);style.left=Math.random()*windowX;}else if(side===1){style.top=Math.random()*windowY;style.left=windowX+(2*this.options.bugWidth);}else if(side===2){style.top=windowY+(2*this.options.bugHeight);style.left=Math.random()*windowX;}else{style.top=Math.random()*windowY;style.left=(-3*this.options.bugWidth);}
|
|
|
|
|
if(!this.bug)return;this.stop();var side=Math.round(Math.random()*4-0.5),d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],windowX=innerWidth||e.clientWidth||g.clientWidth,windowY=innerHeight||e.clientHeight||g.clientHeight;if(side>3)side=3;if(side<0)side=0;var style={},s;if(side===0){style.top=(-2*this.options.bugHeight);style.left=Math.random()*windowX;}else if(side===1){style.top=Math.random()*windowY;style.left=windowX+(2*this.options.bugWidth);}else if(side===2){style.top=windowY+(2*this.options.bugHeight);style.left=Math.random()*windowX;}else{style.top=Math.random()*windowY;style.left=(-3*this.options.bugWidth);}
|
|
|
|
|
var row=(this.wingsOpen)?'0':'-'+this.options.bugHeight+'px';this.bug.style.backgroundPosition=(-3*this.options.bugWidth)+'px '+row;this.bug.top=style.top
|
|
|
|
|
this.bug.left=style.left
|
|
|
|
|
this.drawBug();var landingPosition={};landingPosition.top=this.random(this.options.edge_resistance,document.documentElement.clientHeight-this.options.edge_resistance);landingPosition.left=this.random(this.options.edge_resistance,document.documentElement.clientWidth-this.options.edge_resistance);this.startFlying(landingPosition);},walkIn:function(){if(!this.bug){this.makeBug();}
|
|
|
|
|
if(!this.bug)return;this.stop();var side=Math.round(Math.random()*4-0.5),d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],windowX=window.innerWidth||e.clientWidth||g.clientWidth,windowY=window.innerHeight||e.clientHeight||g.clientHeight;if(side>3)side=3;if(side<0)side=0;var style={},s;if(side===0){style.top=(-1.3*this.options.bugHeight);style.left=Math.random()*windowX;}else if(side===1){style.top=Math.random()*windowY;style.left=windowX+(0.3*this.options.bugWidth);}else if(side===2){style.top=windowY+(0.3*this.options.bugHeight);style.left=Math.random()*windowX;}else{style.top=Math.random()*windowY;style.left=(-1.3*this.options.bugWidth);}
|
|
|
|
|
if(!this.bug)return;this.stop();var side=Math.round(Math.random()*4-0.5),d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],windowX=innerWidth||e.clientWidth||g.clientWidth,windowY=innerHeight||e.clientHeight||g.clientHeight;if(side>3)side=3;if(side<0)side=0;var style={},s;if(side===0){style.top=(-1.3*this.options.bugHeight);style.left=Math.random()*windowX;}else if(side===1){style.top=Math.random()*windowY;style.left=windowX+(0.3*this.options.bugWidth);}else if(side===2){style.top=windowY+(0.3*this.options.bugHeight);style.left=Math.random()*windowX;}else{style.top=Math.random()*windowY;style.left=(-1.3*this.options.bugWidth);}
|
|
|
|
|
var row=(this.wingsOpen)?'0':'-'+this.options.bugHeight+'px';this.bug.style.backgroundPosition=(-3*this.options.bugWidth)+'px '+row;this.bug.top=style.top
|
|
|
|
|
this.bug.left=style.left
|
|
|
|
|
this.drawBug();this.go();},flyOff:function(){this.stop();var side=this.random(0,3),style={},d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],windowX=window.innerWidth||e.clientWidth||g.clientWidth,windowY=window.innerHeight||e.clientHeight||g.clientHeight;if(side===0){style.top=-200;style.left=Math.random()*windowX;}else if(side===1){style.top=Math.random()*windowY;style.left=windowX+200;}else if(side===2){style.top=windowY+200;style.left=Math.random()*windowX;}else{style.top=Math.random()*windowY;style.left=-200;}
|
|
|
|
|
this.startFlying(style);},die:function(){this.stop();var deathType=this.random(0,this.options.numDeathTypes-1);this.alive=false;this.drop(deathType);},drop:function(deathType){var startPos=this.bug.top,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],finalPos=window.innerHeight||e.clientHeight||g.clientHeight,finalPos=finalPos-this.options.bugHeight,rotationRate=this.random(0,20,true),startTime=Date.now(),that=this;this.bug.classList.add('bug-dead');this.dropTimer=requestAnimFrame(function(t){that._lastTimestamp=t;that.dropping(t,startPos,finalPos,rotationRate,deathType);});},dropping:function(t,startPos,finalPos,rotationRate,deathType){var elapsedTime=t-this._lastTimestamp,deltaPos=(0.002*(elapsedTime*elapsedTime)),newPos=startPos+deltaPos;var that=this;if(newPos>=finalPos){newPos=finalPos;clearTimeout(this.dropTimer);this.angle_deg=0;this.angle_rad=this.deg2rad(this.angle_deg);this.transform("rotate("+(90-this.angle_deg)+"deg) scale("+this.zoom+")");this.bug.style.top=null;var rotationOffset=((this.options.bugWidth*this.zoom)-(this.options.bugHeight*this.zoom))/2;var zoomOffset=((this.options.bugHeight)/2)*(1-this.zoom);this.bug.style.bottom=Math.ceil((rotationOffset-zoomOffset))+'px';this.bug.style.left=this.bug.left+'px';this.bug.style.backgroundPosition='-'+((deathType*2)*this.options.bugWidth)+'px 100%';this.twitch(deathType);return;}
|
|
|
|
|
this.drawBug();this.go();},flyOff:function(){this.stop();var side=this.random(0,3),style={},d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],windowX=innerWidth||e.clientWidth||g.clientWidth,windowY=innerHeight||e.clientHeight||g.clientHeight;if(side===0){style.top=-200;style.left=Math.random()*windowX;}else if(side===1){style.top=Math.random()*windowY;style.left=windowX+200;}else if(side===2){style.top=windowY+200;style.left=Math.random()*windowX;}else{style.top=Math.random()*windowY;style.left=-200;}
|
|
|
|
|
this.startFlying(style);},die:function(){this.stop();var deathType=this.random(0,this.options.numDeathTypes-1);this.alive=false;this.drop(deathType);},drop:function(deathType){var startPos=this.bug.top,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],finalPos=innerHeight||e.clientHeight||g.clientHeight,finalPos=finalPos-this.options.bugHeight,rotationRate=this.random(0,20,true),startTime=Date.now(),that=this;this.bug.classList.add('bug-dead');this.dropTimer=requestAnimFrame(function(t){that._lastTimestamp=t;that.dropping(t,startPos,finalPos,rotationRate,deathType);});},dropping:function(t,startPos,finalPos,rotationRate,deathType){var elapsedTime=t-this._lastTimestamp,deltaPos=(0.002*(elapsedTime*elapsedTime)),newPos=startPos+deltaPos;var that=this;if(newPos>=finalPos){newPos=finalPos;clearTimeout(this.dropTimer);this.angle_deg=0;this.angle_rad=this.deg2rad(this.angle_deg);this.transform("rotate("+(90-this.angle_deg)+"deg) scale("+this.zoom+")");this.bug.style.top=null;var rotationOffset=((this.options.bugWidth*this.zoom)-(this.options.bugHeight*this.zoom))/2;var zoomOffset=((this.options.bugHeight)/2)*(1-this.zoom);this.bug.style.bottom=Math.ceil((rotationOffset-zoomOffset))+'px';this.bug.style.left=this.bug.left+'px';this.bug.style.backgroundPosition='-'+((deathType*2)*this.options.bugWidth)+'px 100%';this.twitch(deathType);return;}
|
|
|
|
|
this.dropTimer=requestAnimFrame(function(t){that.dropping(t,startPos,finalPos,rotationRate,deathType);});if(elapsedTime<20)return;this.angle_deg=((this.angle_deg+rotationRate)%360);this.angle_rad=this.deg2rad(this.angle_deg);this.moveBug(this.bug.left,newPos,this.angle_deg);},twitch:function(deathType,legPos){if(!legPos)legPos=0;var that=this;if(deathType===0||deathType===1){that.twitchTimer=setTimeout(function(){that.bug.style.backgroundPosition='-'+((deathType*2+(legPos%2))*that.options.bugWidth)+'px 100%';that.twitchTimer=setTimeout(function(){legPos++;that.bug.style.backgroundPosition='-'+((deathType*2+(legPos%2))*that.options.bugWidth)+'px 100%';that.twitch(deathType,++legPos);},that.random(300,800));},this.random(1000,10000));}},rad2deg:function(rad){return rad*this.rad2deg_k;},deg2rad:function(deg){return deg*this.deg2rad_k;},random:function(min,max,plusminus){if(min==max)return min;var result=Math.round(min-0.5+(Math.random()*(max-min+1)));if(plusminus)return Math.random()>0.5?result:-result;return result;},next_small_turn:function(){this.small_turn_counter=Math.round(Math.random()*10);},next_large_turn:function(){this.large_turn_counter=Math.round(Math.random()*40);},next_stationary:function(){this.toggle_stationary_counter=this.random(50,300);},bug_near_window_edge:function(){this.near_edge=0;if(this.bug.top<this.options.edge_resistance)
|
|
|
|
|
this.near_edge|=this.NEAR_TOP_EDGE;else if(this.bug.top>document.documentElement.clientHeight-this.options.edge_resistance)
|
|
|
|
|
this.near_edge|=this.NEAR_BOTTOM_EDGE;if(this.bug.left<this.options.edge_resistance)
|
|
|
|
|