├── fonts ├── icomoon.eot ├── icomoon.ttf ├── icomoon.woff └── icomoon.svg ├── 3d ├── fonts │ ├── icomoon.eot │ ├── icomoon.ttf │ ├── icomoon.woff │ └── icomoon.svg ├── img │ ├── photo-1445810694374-0a94739e4a03.jpg │ ├── photo-1486334803289-1623f249dd1e.jpg │ ├── photo-1488190211105-8b0e65b80b4e.jpg │ ├── photo-1506045412240-22980140a405.jpg │ ├── photo-1514041181368-bca62cceffcd.jpg │ └── photo-1515260268569-9271009adfdb.jpg └── css │ ├── normalize.css │ ├── style.css │ └── htmleaf-demo.css ├── img └── Alien_logo.png ├── game ├── fonts │ ├── icomoon.eot │ ├── icomoon.ttf │ ├── icomoon.woff │ └── icomoon.svg ├── css │ ├── normalize.css │ └── default.css └── js │ └── BlockBlaster.js ├── sky ├── fonts │ ├── icomoon.eot │ ├── icomoon.ttf │ ├── icomoon.woff │ └── icomoon.svg ├── css │ ├── normalize.css │ └── htmleaf-demo.css ├── sky.html └── js │ ├── jquery.warpdrive.min.js │ └── jquery.warpdrive.js ├── game.html ├── css ├── normalize.css └── htmleaf-demo.css ├── 3d.html ├── sky.html ├── js ├── jquery.warpdrive.min.js └── jquery.warpdrive.js └── index.html /fonts/icomoon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/fonts/icomoon.eot -------------------------------------------------------------------------------- /fonts/icomoon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/fonts/icomoon.ttf -------------------------------------------------------------------------------- /3d/fonts/icomoon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/fonts/icomoon.eot -------------------------------------------------------------------------------- /3d/fonts/icomoon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/fonts/icomoon.ttf -------------------------------------------------------------------------------- /fonts/icomoon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/fonts/icomoon.woff -------------------------------------------------------------------------------- /img/Alien_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/img/Alien_logo.png -------------------------------------------------------------------------------- /3d/fonts/icomoon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/fonts/icomoon.woff -------------------------------------------------------------------------------- /game/fonts/icomoon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/game/fonts/icomoon.eot -------------------------------------------------------------------------------- /game/fonts/icomoon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/game/fonts/icomoon.ttf -------------------------------------------------------------------------------- /sky/fonts/icomoon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/sky/fonts/icomoon.eot -------------------------------------------------------------------------------- /sky/fonts/icomoon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/sky/fonts/icomoon.ttf -------------------------------------------------------------------------------- /sky/fonts/icomoon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/sky/fonts/icomoon.woff -------------------------------------------------------------------------------- /game/fonts/icomoon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/game/fonts/icomoon.woff -------------------------------------------------------------------------------- /3d/img/photo-1445810694374-0a94739e4a03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/img/photo-1445810694374-0a94739e4a03.jpg -------------------------------------------------------------------------------- /3d/img/photo-1486334803289-1623f249dd1e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/img/photo-1486334803289-1623f249dd1e.jpg -------------------------------------------------------------------------------- /3d/img/photo-1488190211105-8b0e65b80b4e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/img/photo-1488190211105-8b0e65b80b4e.jpg -------------------------------------------------------------------------------- /3d/img/photo-1506045412240-22980140a405.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/img/photo-1506045412240-22980140a405.jpg -------------------------------------------------------------------------------- /3d/img/photo-1514041181368-bca62cceffcd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/img/photo-1514041181368-bca62cceffcd.jpg -------------------------------------------------------------------------------- /3d/img/photo-1515260268569-9271009adfdb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallAntcxq/animations/HEAD/3d/img/photo-1515260268569-9271009adfdb.jpg -------------------------------------------------------------------------------- /game.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | R&&(j.z=Q,j.distance=j.distanceTotal)),j.color=j.colorLookupTable[Math.floor(j.distance/j.distanceTotal*100)],k=x/(x+j.z),j.x2d=j.x*k+$.x,j.y2d=j.y*k+$.y,s===t)j.x2d>-1&&j.x2d-1&&j.y2d -1&&n -1&&o c.autoResizeMaxWidth&&(g=c.autoResizeMaxWidth),c.autoResizeMinHeight&&h c.autoResizeMaxHeight&&(h=c.autoResizeMaxHeight),W.setAttribute("width",g),W.setAttribute("height",h),$={x:W.width/2,y:W.height/2},Y=X.getImageData(0,0,g,h),Z=Y.data}function ta(a){ba=ya(W,a)}function ua(a){_=!0}function va(a){_=!1,aa=!1}function wa(a){aa=!0}function xa(a){aa=!1}function ya(a,b){var c=a.getBoundingClientRect();return{x:b.clientX-c.left,y:b.clientY-c.top}}function za(a){a.preventDefault(),aa=!0,_=!0}function Aa(a){a.preventDefault(),aa=!1,_=!1}function Ba(a){a.preventDefault(),ba=Da(W,a)}function Ca(a){aa=!1,_=!1}function Da(a,b){var c=a.getBoundingClientRect();return{x:b.touches[0].clientX-c.left,y:b.touches[0].clientY-c.top}}var c={};if(c.width=480,c.height=480,c.autoResize=!1,c.autoResizeMinWidth=null,c.autoResizeMaxWidth=null,c.autoResizeMinHeight=null,c.autoResizeMaxHeight=null,c.addMouseControls=!0,c.addTouchControls=!0,c.hideContextMenu=!0,c.starCount=6666,c.starBgCount=2222,c.starBgColor={r:255,g:255,b:255},c.starBgColorRangeMin=10,c.starBgColorRangeMax=40,c.starColor={r:255,g:255,b:255},c.starColorRangeMin=10,c.starColorRangeMax=100,c.starfieldBackgroundColor={r:0,g:0,b:0},c.starDirection=1,c.starSpeed=20,c.starSpeedMax=200,c.starSpeedAnimationDuration=2,c.starFov=300,c.starFovMin=200,c.starFovAnimationDuration=2,c.starRotationPermission=!0,c.starRotationDirection=1,c.starRotationSpeed=0,c.starRotationSpeedMax=1,c.starRotationAnimationDuration=2,c.starWarpLineLength=2,c.starWarpTunnelDiameter=100,c.starFollowMouseSensitivity=.025,c.starFollowMouseXAxis=!0,c.starFollowMouseYAxis=!0,void 0!==b)for(var d in b)b.hasOwnProperty(d)&&c.hasOwnProperty(d)&&(c[d]=b[d]);for(var d in c)c.hasOwnProperty(d)&&d.indexOf("Duration")>-1&&(c[d]=60*c[d]);if("string"==typeof c.starBgColor&&c.starBgColor.indexOf("#")>-1?c.starBgColor=fa(c.starBgColor):"string"==typeof c.starBgColor&&c.starBgColor.indexOf("rgb")>-1&&(c.starBgColor=ha(c.starBgColor)),"string"==typeof c.starColor&&c.starColor.indexOf("#")>-1?c.starColor=fa(c.starColor):"string"==typeof c.starColor&&c.starColor.indexOf("rgb")>-1&&(c.starColor=ha(c.starColor)),"string"==typeof c.starfieldBackgroundColor&&c.starfieldBackgroundColor.indexOf("#")>-1?c.starfieldBackgroundColor=fa(c.starfieldBackgroundColor):"string"==typeof c.starfieldBackgroundColor&&c.starfieldBackgroundColor.indexOf("rgb")>-1&&(c.starfieldBackgroundColor=ha(c.starfieldBackgroundColor)),!a)throw Error("\nNo div element found");var S,T,U,V,W,X,Y,Z,$,_,aa,ba,e=Math.PI/180,g=(Math.PI,c.width),h=c.height,i=c.starCount,j=c.starBgCount,k=c.starBgColor,l=c.starBgColorRangeMin,m=c.starBgColorRangeMax,n=c.starColor,o=c.starColorRangeMin,p=c.starColorRangeMax,q=c.starfieldBackgroundColor,r=c.starDirection,s=c.starSpeed,t=s,u=c.starSpeedMax,v=c.starFovAnimationDuration,w=0,x=c.starFov,y=c.starFovMin,z=x,A=c.starFovAnimationDuration,B=A,C=0,D=c.starRotationPermission,E=c.starRotationDirection,F=c.starRotationSpeed,G=F,H=c.starRotationSpeedMax,I=c.starRotationAnimationDuration,J=0,K=c.starWarpLineLength,L=c.starWarpTunnelDiameter,M=c.starFollowMouseSensitivity,N=c.starFollowMouseXAxis,O=c.starFollowMouseYAxis,P=8e3,Q=1-y,R=P,ca=!1;Math.easeInQuad=function(a,b,c,d){return c*a*a/(d*d)+b},Math.easeOutQuad=function(a,b,c,d){return-c*a*a/(d*d)+2*c*a/d+b},window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}(),this.pause=function(){ca=!0},this.unpause=function(){ca=!1},da()}window.WarpDrive=a}(),"undefined"!=typeof jQuery&&function(a){a.fn.warpDrive=function(b){var c=arguments;return this.each(function(){if(a.data(this,"plugin_WarpDrive")){var d=a.data(this,"plugin_WarpDrive");d[b]?d[b].apply(this,Array.prototype.slice.call(c,1)):a.error("Method "+b+" does not exist on jQuery.warpDrive")}else a.data(this,"plugin_WarpDrive",new WarpDrive(this,b))})}}(jQuery); -------------------------------------------------------------------------------- /sky/js/jquery.warpdrive.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | Warp Drive jQuery plugin 3 | Version: 1.0.0 4 | 5 | Written by Niklas Knaack 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | !function(){function a(a,b){function da(){W=document.createElement("canvas"),W.style.backgroundColor=ga(q.r,q.g,q.b),W.setAttribute("width",g),W.setAttribute("height",h),c.addMouseControls&&(W.addEventListener("mousemove",ta,!1),W.addEventListener("mousedown",wa,!1),W.addEventListener("mouseup",xa,!1),W.addEventListener("mouseenter",ua,!1),W.addEventListener("mouseleave",va,!1)),c.addTouchControls&&(W.addEventListener("touchstart",za,!1),W.addEventListener("touchend",Aa,!1),W.addEventListener("touchmove",Ba,!1),W.addEventListener("touchcancel",Ca,!1)),c.hideContextMenu&&(W.oncontextmenu=function(a){a.preventDefault()}),a.appendChild(W),X=W.getContext("2d"),Y=X.getImageData(0,0,g,h),Z=Y.data,$={x:W.width/2,y:W.height/2},_=!1,aa=!1,ba={x:$.x,y:$.y},U=[],V=[],S=[],T=[],la(U,o,p,q,n),la(V,l,m,q,k),oa(),pa(),c.autoResize&&(window.addEventListener("resize",ra),sa())}function ea(a,b,c){var d=a<0?-1*a:a,e=Math.round,f=parseInt,g=f(b.slice(1),16),h=f((c||(a<0?"#000000":"#FFFFFF")).slice(1),16),i=g>>16,j=g>>8&255,k=255&g;return"#"+(16777216+65536*(e(((h>>16)-i)*d)+i)+256*(e(((h>>8&255)-j)*d)+j)+(e(((255&h)-k)*d)+k)).toString(16).slice(1)}function fa(a){var b=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;a=a.replace(b,function(a,b,c,d){return b+b+c+c+d+d});var c=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);return c?{r:parseInt(c[1],16),g:parseInt(c[2],16),b:parseInt(c[3],16)}:null}function ga(a,b,c){return"#"+(16777216+(c|b<<8|a<<16)).toString(16).slice(1)}function ha(a){a=a.replace(/\s+/g,"");var b=a.split("(")[1].split(")")[0].split(",");return{r:b[0],g:b[1],b:b[2]}}function ia(){for(var a=0,b=Z.length;a-1&&p -1&&q -k&&(o-=l,p+=m),r 0)for(;Math.sqrt(c*c+d*d)I&&(J=I):(J-=1)<0&&(J=0),F=Math.easeOutQuad(J,G,H,I),C-=F*E),_?(w+=1,w>v&&(w=v),B-=1,B<0&&(B=0),N&&($.x+=(ba.x-$.x)*M),O&&($.y+=(ba.y-$.y)*M)):(w-=1,w<0&&(w=0),B+=1,B>A&&(B=A),N&&($.x+=(W.width/2-$.x)*M),O&&($.y+=(W.height/2-$.y)*M)),s=Math.easeOutQuad(w,0,u-t,v)+t,x=Math.easeInQuad(B,0,z-y,A)+y,Q=1-x;var l=s*(s/(u/K));for(a=0,c=T.length;a -1&&j.x2d -1&&j.y2d =0?(j.z-=s,j.distance+=s,j.z R&&(j.z=Q,j.distance=j.distanceTotal)),j.color=j.colorLookupTable[Math.floor(j.distance/j.distanceTotal*100)],k=x/(x+j.z),j.x2d=j.x*k+$.x,j.y2d=j.y*k+$.y,s===t)j.x2d>-1&&j.x2d-1&&j.y2d -1&&n -1&&o c.autoResizeMaxWidth&&(g=c.autoResizeMaxWidth),c.autoResizeMinHeight&&h c.autoResizeMaxHeight&&(h=c.autoResizeMaxHeight),W.setAttribute("width",g),W.setAttribute("height",h),$={x:W.width/2,y:W.height/2},Y=X.getImageData(0,0,g,h),Z=Y.data}function ta(a){ba=ya(W,a)}function ua(a){_=!0}function va(a){_=!1,aa=!1}function wa(a){aa=!0}function xa(a){aa=!1}function ya(a,b){var c=a.getBoundingClientRect();return{x:b.clientX-c.left,y:b.clientY-c.top}}function za(a){a.preventDefault(),aa=!0,_=!0}function Aa(a){a.preventDefault(),aa=!1,_=!1}function Ba(a){a.preventDefault(),ba=Da(W,a)}function Ca(a){aa=!1,_=!1}function Da(a,b){var c=a.getBoundingClientRect();return{x:b.touches[0].clientX-c.left,y:b.touches[0].clientY-c.top}}var c={};if(c.width=480,c.height=480,c.autoResize=!1,c.autoResizeMinWidth=null,c.autoResizeMaxWidth=null,c.autoResizeMinHeight=null,c.autoResizeMaxHeight=null,c.addMouseControls=!0,c.addTouchControls=!0,c.hideContextMenu=!0,c.starCount=6666,c.starBgCount=2222,c.starBgColor={r:255,g:255,b:255},c.starBgColorRangeMin=10,c.starBgColorRangeMax=40,c.starColor={r:255,g:255,b:255},c.starColorRangeMin=10,c.starColorRangeMax=100,c.starfieldBackgroundColor={r:0,g:0,b:0},c.starDirection=1,c.starSpeed=20,c.starSpeedMax=200,c.starSpeedAnimationDuration=2,c.starFov=300,c.starFovMin=200,c.starFovAnimationDuration=2,c.starRotationPermission=!0,c.starRotationDirection=1,c.starRotationSpeed=0,c.starRotationSpeedMax=1,c.starRotationAnimationDuration=2,c.starWarpLineLength=2,c.starWarpTunnelDiameter=100,c.starFollowMouseSensitivity=.025,c.starFollowMouseXAxis=!0,c.starFollowMouseYAxis=!0,void 0!==b)for(var d in b)b.hasOwnProperty(d)&&c.hasOwnProperty(d)&&(c[d]=b[d]);for(var d in c)c.hasOwnProperty(d)&&d.indexOf("Duration")>-1&&(c[d]=60*c[d]);if("string"==typeof c.starBgColor&&c.starBgColor.indexOf("#")>-1?c.starBgColor=fa(c.starBgColor):"string"==typeof c.starBgColor&&c.starBgColor.indexOf("rgb")>-1&&(c.starBgColor=ha(c.starBgColor)),"string"==typeof c.starColor&&c.starColor.indexOf("#")>-1?c.starColor=fa(c.starColor):"string"==typeof c.starColor&&c.starColor.indexOf("rgb")>-1&&(c.starColor=ha(c.starColor)),"string"==typeof c.starfieldBackgroundColor&&c.starfieldBackgroundColor.indexOf("#")>-1?c.starfieldBackgroundColor=fa(c.starfieldBackgroundColor):"string"==typeof c.starfieldBackgroundColor&&c.starfieldBackgroundColor.indexOf("rgb")>-1&&(c.starfieldBackgroundColor=ha(c.starfieldBackgroundColor)),!a)throw Error("\nNo div element found");var S,T,U,V,W,X,Y,Z,$,_,aa,ba,e=Math.PI/180,g=(Math.PI,c.width),h=c.height,i=c.starCount,j=c.starBgCount,k=c.starBgColor,l=c.starBgColorRangeMin,m=c.starBgColorRangeMax,n=c.starColor,o=c.starColorRangeMin,p=c.starColorRangeMax,q=c.starfieldBackgroundColor,r=c.starDirection,s=c.starSpeed,t=s,u=c.starSpeedMax,v=c.starFovAnimationDuration,w=0,x=c.starFov,y=c.starFovMin,z=x,A=c.starFovAnimationDuration,B=A,C=0,D=c.starRotationPermission,E=c.starRotationDirection,F=c.starRotationSpeed,G=F,H=c.starRotationSpeedMax,I=c.starRotationAnimationDuration,J=0,K=c.starWarpLineLength,L=c.starWarpTunnelDiameter,M=c.starFollowMouseSensitivity,N=c.starFollowMouseXAxis,O=c.starFollowMouseYAxis,P=8e3,Q=1-y,R=P,ca=!1;Math.easeInQuad=function(a,b,c,d){return c*a*a/(d*d)+b},Math.easeOutQuad=function(a,b,c,d){return-c*a*a/(d*d)+2*c*a/d+b},window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}(),this.pause=function(){ca=!0},this.unpause=function(){ca=!1},da()}window.WarpDrive=a}(),"undefined"!=typeof jQuery&&function(a){a.fn.warpDrive=function(b){var c=arguments;return this.each(function(){if(a.data(this,"plugin_WarpDrive")){var d=a.data(this,"plugin_WarpDrive");d[b]?d[b].apply(this,Array.prototype.slice.call(c,1)):a.error("Method "+b+" does not exist on jQuery.warpDrive")}else a.data(this,"plugin_WarpDrive",new WarpDrive(this,b))})}}(jQuery); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 纯CSS3杂志翻页动画特效|DEMO_jQuery之家-自由分享jQuery、html5、css3的插件库 8 | 9 | 10 | 11 | 12 | 13 | 14 |15 |275 | 276 | 277 | -------------------------------------------------------------------------------- /game/js/BlockBlaster.js: -------------------------------------------------------------------------------- 1 | 2 | //Create canvas 3 | //document.body.innerHTML += ''; 4 | 5 | //Globals Variables 6 | //----------------- 7 | var fps = 30; 8 | var canvas = document.getElementById('canvas'); 9 | var ctx = canvas.getContext("2d"); 10 | var bgColor = "rgb(40,40,40)" 11 | var ready; 12 | var enemyScore; 13 | var renderTimer = setInterval(render,1/fps*100); 14 | var difficultyTimer; 15 | var spawnTimer; 16 | var spawntime; 17 | var gameTime; 18 | var difficulty; 19 | var score; 20 | var highScore=0; 21 | var gameOver; 22 | var entities = []; 23 | var player; 24 | var fader; 25 | 26 | 27 | //Global Functions 28 | //---------------- 29 | 30 | //Reset app back to 'Ready?' Screen 31 | function reset(){ 32 | if (score > highScore) highScore = score; 33 | ready = true; 34 | enemyScore = 0; 35 | gameTime = 0; 36 | difficulty = 1; 37 | score = 0; 38 | spawntime = 1500; 39 | gameOver = false; 40 | fader = 0; 41 | entities = []; 42 | player = null; 43 | clearTimers() 44 | } 45 | 46 | //Clear all timers 47 | function clearTimers(){ 48 | clearInterval(difficultyTimer); 49 | clearInterval(spawnTimer); 50 | } 51 | 52 | //Initialize all timers 53 | function initializeTimers(){ 54 | difficultyTimer = setInterval(increaseDifficulty,2000); 55 | spawnTimer = setInterval(spawnEnemy,spawntime); 56 | } 57 | 58 | //Initialize / Start game 59 | function init(){ 60 | ready = false; 61 | clearTimers(); 62 | initializeTimers(); 63 | 64 | //Spawn player 65 | player = new Player(); 66 | player.position.set(canvas.width/2,canvas.height-player.size); 67 | player.render(); 68 | entities.push(player); 69 | 70 | } 71 | 72 | //Update Entities 73 | function updateEntities(){ 74 | entities.forEach(function(e){ 75 | if (e.position.y > canvas.height + 20){ 76 | if (e.name == "Enemy"){ 77 | enemyScore += 1; 78 | } 79 | removeEntity(e); 80 | } 81 | e.update(1/fps); 82 | }) 83 | } 84 | 85 | //Draw background 86 | function drawBG(){ 87 | ctx.fillStyle = bgColor; 88 | ctx.fillRect(0,0,canvas.width,canvas.height); 89 | } 90 | 91 | //Draw Score / HUD 92 | function drawScore(){ 93 | ctx.fillStyle = "#CCFF99"; 94 | ctx.font = "24px sans-serif"; 95 | ctx.fillText("Score: " + score,10,24); 96 | ctx.font = "16px sans-serif"; 97 | ctx.fillText("High Score: " + highScore,10,48); 98 | var enemyScoreString = ""; 99 | for (var i = 0; i < enemyScore; i++){ 100 | enemyScoreString += "X"; 101 | } 102 | ctx.font = "24px sans-serif"; 103 | ctx.fillStyle = "#FF6666"; 104 | ctx.fillText(enemyScoreString,canvas.width - 75,24); 105 | ctx.font = "16px sans-serif"; 106 | ctx.fillText("Difficulty: " + difficulty,canvas.width/2 - 50,24); 107 | } 108 | 109 | //Draws some static. 110 | //@param alpha transparency 111 | function drawStatic(alpha){ 112 | var s = 15 ; 113 | for (var x = 0; x < canvas.width; x+=s){ 114 | for (var y = 0; y < canvas.width; y+=s){ 115 | var n = Math.floor(Math.random() * 60); 116 | ctx.fillStyle = "rgba(" + n + "," + n + "," + n + "," + (Math.random() * alpha) + ")"; 117 | ctx.fillRect(x,y,s,s); 118 | } 119 | } 120 | } 121 | 122 | //Draws 'Ready?' screen 123 | function drawReadyScreen(){ 124 | drawBG(); 125 | //drawStatic(.25); 126 | drawScore(); 127 | fader += .1 * 1/fps; 128 | ctx.fillStyle = "rgba(255,255,255," + fader + ")"; 129 | ctx.font = "72px sans-serif"; 130 | ctx.fillText("READY?",canvas.width/2 - 140,canvas.height/2); 131 | drawScore(); 132 | } 133 | 134 | //Draw all entities 135 | function drawEntities(){ 136 | entities.forEach(function(e){e.render();}); 137 | } 138 | 139 | //Draw 'Game Over' screen 140 | function drawGameOver(){ 141 | ctx.fillStyle = "rgba(0,0,0,"+fader +")"; 142 | ctx.fillRect(0,0,canvas.width,canvas.height); 143 | drawStatic(fader/2); 144 | drawScore(); 145 | fader += .1 * 1/fps 146 | ctx.fillStyle = "rgba(255,255,255," + fader + ")"; 147 | ctx.font = "72px sans-serif"; 148 | ctx.fillText("GAME OVER",canvas.width/2 - 220,canvas.height/2); 149 | } 150 | 151 | //Render everything 152 | function render(){ 153 | drawBG(); 154 | drawEntities(); 155 | drawScore(); 156 | if (gameOver){drawGameOver(); return;} 157 | else if (ready){drawReadyScreen(); return;} 158 | updateEntities(); 159 | gameTime += 1/fps; 160 | if (enemyScore >= 3) { 161 | clearTimers(); 162 | gameOver = true; 163 | fader = 0; 164 | } 165 | } 166 | 167 | //Return mouse position relative to canvas 168 | function getMousePos(canvas, evt) { 169 | var rect = canvas.getBoundingClientRect(); 170 | return new Vector2(evt.clientX - rect.left, 171 | evt.clientY - rect.top) 172 | } 173 | 174 | //Click Event 175 | function canvasClick(){ 176 | if (gameOver){ if (fader > .5) reset();return;} 177 | if (ready) {init(); return;} 178 | var bullet = new Bullet(); 179 | bullet.position.set(player.position.x + player.size / 2 - bullet.size/2,player.position.y - player.size/2 - bullet.size /2); 180 | bullet.velocity.y = -30; 181 | entities.push(bullet); 182 | if (score > 0) score -= 1; 183 | } 184 | 185 | //Increment difficulty 186 | function increaseDifficulty(){ 187 | difficulty += 1; 188 | if (spawntime > 20) spawntime -= 20; 189 | clearInterval(spawnTimer); 190 | spawnTimer = setInterval(spawnEnemy,spawntime); 191 | } 192 | 193 | //Change alpha of color 194 | function setAlpha(color,alpha){ 195 | if (color.indexOf('a') == -1){ 196 | return color.replace(")",","+alpha+")").replace("rgb","rgba"); 197 | } 198 | } 199 | 200 | //Entity death 201 | function death(entity){ 202 | if (entity.name == "Enemy") { 203 | var particleCount = Math.floor((Math.random() * 6) + 3); 204 | for (var i = 0; i < particleCount; i++){ 205 | var p = new Particle(); 206 | p.color = entity.color; 207 | p.size = Math.floor((Math.random() * entity.size/2) + 5); 208 | p.position.set(entity.position.x+entity.size/2,entity.position.y+entity.size/2); 209 | entities.push(p); 210 | } 211 | score += 25; 212 | } 213 | removeEntity(entity); 214 | } 215 | 216 | //Remove Entity 217 | function removeEntity(entity){ 218 | var idx = entities.indexOf(entity); 219 | if (idx > -1) entities.splice(idx,1); 220 | } 221 | 222 | //Check if two entities overlap 223 | function overlaps(entityA,entityB){ 224 | var sa = entityA.size; 225 | var x1a = entityA.position.x; 226 | var x2a = entityA.position.x + sa; 227 | var y1a = entityA.position.y; 228 | var y2a = entityA.position.y + sa; 229 | var sb = entityB.size; 230 | var x1b = entityB.position.x; 231 | var x2b = entityB.position.x + sb; 232 | var y1b = entityB.position.y; 233 | var y2b = entityB.position.y + sb; 234 | return (x1a < x2b && x2a > x1b && y1a < y2b && y2a > y1b); 235 | } 236 | 237 | //Spawns new enemy 238 | function spawnEnemy(){ 239 | var e = new Enemy(); 240 | var px = Math.floor((Math.random() * canvas.width)); 241 | var py = -e.size; 242 | var v = difficulty; 243 | var a = Math.floor((Math.random() * (v + 15)) + v); 244 | var f = Math.floor((Math.random() * (v + 15)) + v); 245 | e.position.set(px,py); 246 | var r = Math.random(); 247 | if (r > .5){ 248 | straightDownMotion(e,v); 249 | } 250 | else if (r > .3){ 251 | sineMotion(e,a,f,v); 252 | } 253 | else if (r > .1){ 254 | triangularMotion(e,a,f,v); 255 | } 256 | else{ 257 | sawtoothMotion(e,a,f,v); 258 | } 259 | entities.push(e); 260 | } 261 | 262 | //Straight down motion 263 | function straightDownMotion(entity,speed){ 264 | entity.update = function(deltatime){ 265 | this.velocity.x = 0; 266 | this.velocity.y = speed; 267 | Entity.prototype.update.call(this,deltatime); 268 | } 269 | } 270 | 271 | //Define sin wave motion 272 | function sineMotion(entity,amplitude,freq,speed){ 273 | entity.update = function(deltatime){ 274 | this.velocity.x = amplitude * Math.cos(this.position.y/freq); 275 | this.velocity.y = speed; 276 | Entity.prototype.update.call(this,deltatime); 277 | } 278 | } 279 | 280 | //Define saw tooth motion (sorta) 281 | function sawtoothMotion(entity, amplitude,freq,speed){ 282 | var modifier = 1; 283 | if (Math.random() > .5) modifier = -1; 284 | entity.update = function(deltatime){ 285 | this.velocity.x = modifier * ((-2*amplitude)/Math.PI)*Math.atan(1/Math.tan(this.position.y / freq)); 286 | this.velocity.y = speed; 287 | Entity.prototype.update.call(this,deltatime); 288 | } 289 | } 290 | 291 | //Define triangular motion () 292 | function triangularMotion(entity, amplitude,freq,speed){ 293 | entity.update = function(deltatime){ 294 | this.velocity.x = ((2*amplitude)/Math.PI)*Math.asin(Math.sin(this.position.y / freq)); 295 | this.velocity.y = speed; 296 | Entity.prototype.update.call(this,deltatime); 297 | } 298 | } 299 | 300 | //Generate random rgba color string 301 | function randomColor(min,max){ 302 | var r = Math.floor((Math.random() * max) + min); 303 | var g = Math.floor((Math.random() * max) + min); 304 | var b = Math.floor((Math.random() * max) + min); 305 | var col = "rgb(" + r + "," + g + "," + b + ")"; 306 | return col; 307 | } 308 | 309 | // Classes 310 | //---------- 311 | 312 | //Vector2 313 | var Vector2 = function(x1,y1){ 314 | this.x = x1; 315 | this.y = y1; 316 | } 317 | Vector2.prototype.set = function(a,b){ 318 | this.x = a; 319 | this.y = b; 320 | } 321 | 322 | //Entity (Base class) 323 | var Entity = function(){ 324 | this.name = "Entity"; 325 | this.size = 25; 326 | this.position = new Vector2(0,0); 327 | this.velocity = new Vector2(0,0); 328 | this.color = "#FFFFFF"; 329 | } 330 | Entity.prototype.sayName = function(){ 331 | console.log(this.name); 332 | } 333 | Entity.prototype.update = function(deltaTime){ 334 | this.position.x += this.velocity.x * deltaTime; 335 | this.position.y += this.velocity.y * deltaTime; 336 | //Keep in bounds 337 | if (this.position.x - this.size < 0) {this.position.x = this.size;} 338 | if (this.position.x + this.size > canvas.width) {this.position.x = canvas.width - this.size;} 339 | } 340 | Entity.prototype.render = function(){ 341 | ctx.fillStyle = this.color; 342 | ctx.fillRect(this.position.x,this.position.y,this.size,this.size); 343 | } 344 | 345 | //Enemy Entity 346 | var Enemy = function(){ 347 | Entity.call(this); 348 | this.name = "Enemy"; 349 | this.size = Math.floor((Math.random() * 50)+20); 350 | this.color = randomColor(90,150); 351 | } 352 | Enemy.prototype = Object.create(Entity.prototype); 353 | Enemy.prototype.constructor = Entity; 354 | //Player Entity 355 | var Player = function(){ 356 | Entity.call(this); 357 | this.name = "Player"; 358 | this.color = "#4747FF" 359 | } 360 | Player.prototype = Object.create(Entity.prototype); 361 | Player.prototype.constructor = Entity; 362 | 363 | //Particle Entity 364 | var Particle = function(){ 365 | Entity.call(this); 366 | this.name = "Particle"; 367 | this.size = 10; 368 | this.time = 0; 369 | this.maxTime = Math.floor((Math.random() * 10) + 3); 370 | this.velocity.x = Math.floor((Math.random() * 20) - 10); 371 | this.velocity.y = Math.floor((Math.random() * 20) - 10); 372 | } 373 | Particle.prototype = Object.create(Entity.prototype); 374 | Particle.prototype.constructor = Entity; 375 | Particle.prototype.update = function(deltatime){ 376 | Entity.prototype.update.call(this,deltatime); 377 | this.time += deltatime; 378 | if (this.time >= this.maxTime) removeEntity(this); 379 | } 380 | 381 | //Bullet Entity 382 | var Bullet = function(){ 383 | Entity.call(this); 384 | this.name = "Bullet"; 385 | this.size = 10; 386 | this.time = 0; 387 | this.color = "rgba(200,200,200,1)"; 388 | this.particlesDelay = .5; 389 | } 390 | Bullet.prototype = Object.create(Entity.prototype); 391 | Bullet.prototype.constructor = Entity; 392 | Bullet.prototype.update = function(deltatime){ 393 | Entity.prototype.update.call(this,deltatime); 394 | 395 | //Check for collisions 396 | var me = this; 397 | entities.forEach(function(e){ 398 | if (e !== me && e.name != "Particle"){ 399 | if (overlaps(me,e)){ 400 | death(e); 401 | removeEntity(me); 402 | } 403 | } 404 | }) 405 | //Remove from game if outside bounds 406 | if (this.position.y < 0) removeEntity(this); 407 | 408 | //Create particles 409 | this.time += deltatime; 410 | if (this.time >= this.particlesDelay){ 411 | this.time = 0; 412 | var p = new Particle(); 413 | p.size = Math.floor((Math.random() * 5)+2); 414 | p.color = setAlpha("rgb(125,125,125)",Math.random()); 415 | //p.color = setAlpha(randomColor(100,255),Math.random()); //Rainbow colored particles 416 | p.velocity.x /=2; 417 | p.position.x = this.position.x + this.size /2 - p.size/2; 418 | p.position.y = this.position.y - p.size/2; 419 | entities.push(p); 420 | } 421 | } 422 | 423 | 424 | 425 | // These must remain at the bottom of this file & in this order // 426 | // ============================================================ // 427 | 428 | //HTML load event 429 | document.addEventListener('DOMContentLoaded', reset()); 430 | 431 | canvas.addEventListener("click",canvasClick); 432 | 433 | //Mouse move event 434 | canvas.addEventListener('mousemove', function(evt) { 435 | var mousePos = getMousePos(canvas, evt); 436 | if (player && !gameOver) player.position.x = mousePos.x; 437 | }, false); 438 | 439 | -------------------------------------------------------------------------------- /js/jquery.warpdrive.js: -------------------------------------------------------------------------------- 1 | /* 2 | Warp Drive jQuery plugin 3 | Version: 1.0.0 4 | 5 | Written by Niklas Knaack 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | ( function() { 27 | 28 | function WarpDrive( element, params ) { 29 | 30 | var settings = {}; 31 | settings.width = 480; 32 | settings.height = 480; 33 | settings.autoResize = false; 34 | settings.autoResizeMinWidth = null; 35 | settings.autoResizeMaxWidth = null; 36 | settings.autoResizeMinHeight = null; 37 | settings.autoResizeMaxHeight = null; 38 | settings.addMouseControls = true; 39 | settings.addTouchControls = true; 40 | settings.hideContextMenu = true; 41 | settings.starCount = 6666; 42 | settings.starBgCount = 2222; 43 | settings.starBgColor = { r:255, g:255, b:255 }; 44 | settings.starBgColorRangeMin = 10; 45 | settings.starBgColorRangeMax = 40; 46 | settings.starColor = { r:255, g:255, b:255 }; 47 | settings.starColorRangeMin = 10; 48 | settings.starColorRangeMax = 100; 49 | settings.starfieldBackgroundColor = { r:0, g:0, b:0 }; 50 | settings.starDirection = 1; 51 | settings.starSpeed = 20; 52 | settings.starSpeedMax = 200; 53 | settings.starSpeedAnimationDuration = 2; 54 | settings.starFov = 300; 55 | settings.starFovMin = 200; 56 | settings.starFovAnimationDuration = 2; 57 | settings.starRotationPermission = true; 58 | settings.starRotationDirection = 1; 59 | settings.starRotationSpeed = 0.0; 60 | settings.starRotationSpeedMax = 1.0; 61 | settings.starRotationAnimationDuration = 2; 62 | settings.starWarpLineLength = 2.0; 63 | settings.starWarpTunnelDiameter = 100; 64 | settings.starFollowMouseSensitivity = 0.025; 65 | settings.starFollowMouseXAxis = true; 66 | settings.starFollowMouseYAxis = true; 67 | 68 | //--- 69 | 70 | if ( params !== undefined ) { 71 | 72 | for ( var prop in params ) { 73 | 74 | if ( params.hasOwnProperty( prop ) && settings.hasOwnProperty( prop ) ) { 75 | 76 | settings[ prop ] = params[ prop ]; 77 | 78 | } 79 | 80 | } 81 | 82 | } 83 | 84 | //--- 85 | 86 | for ( var prop in settings ) { 87 | 88 | if ( settings.hasOwnProperty( prop ) && prop.indexOf( 'Duration' ) > -1 ) { 89 | 90 | settings[ prop ] = settings[ prop ] * 60; 91 | 92 | } 93 | 94 | } 95 | 96 | if ( typeof settings.starBgColor === 'string' && settings.starBgColor.indexOf( '#' ) > -1 ) { 97 | 98 | settings.starBgColor = hexToRgb( settings.starBgColor ); 99 | 100 | } else if ( typeof settings.starBgColor === 'string' && settings.starBgColor.indexOf( 'rgb' ) > -1 ) { 101 | 102 | settings.starBgColor = parseRGBString( settings.starBgColor ); 103 | 104 | } 105 | 106 | if ( typeof settings.starColor === 'string' && settings.starColor.indexOf( '#' ) > -1 ) { 107 | 108 | settings.starColor = hexToRgb( settings.starColor ); 109 | 110 | } else if ( typeof settings.starColor === 'string' && settings.starColor.indexOf( 'rgb' ) > -1 ) { 111 | 112 | settings.starColor = parseRGBString( settings.starColor ); 113 | 114 | } 115 | 116 | if ( typeof settings.starfieldBackgroundColor === 'string' && settings.starfieldBackgroundColor.indexOf( '#' ) > -1 ) { 117 | 118 | settings.starfieldBackgroundColor = hexToRgb( settings.starfieldBackgroundColor ); 119 | 120 | } else if ( typeof settings.starfieldBackgroundColor === 'string' && settings.starfieldBackgroundColor.indexOf( 'rgb' ) > -1 ) { 121 | 122 | settings.starfieldBackgroundColor = parseRGBString( settings.starfieldBackgroundColor ); 123 | 124 | } 125 | 126 | if ( !element ) { 127 | 128 | throw Error( '\n' + 'No div element found' ); 129 | 130 | } 131 | 132 | //--- 133 | 134 | var MATHPI180 = Math.PI / 180; 135 | var MATHPI2 = Math.PI * 2; 136 | 137 | var canvasWidth = settings.width; 138 | var canvasHeight = settings.height; 139 | 140 | var starCount = settings.starCount; 141 | var starBgCount = settings.starBgCount; 142 | 143 | var starBgColor = settings.starBgColor; 144 | var starBgColorRangeMin = settings.starBgColorRangeMin 145 | var starBgColorRangeMax = settings.starBgColorRangeMax 146 | var starColor = settings.starColor; 147 | var starColorRangeMin = settings.starColorRangeMin; 148 | var starColorRangeMax = settings.starColorRangeMax; 149 | 150 | var starfieldBackgroundColor = settings.starfieldBackgroundColor; 151 | 152 | var starDirection = settings.starDirection; 153 | 154 | var starSpeed = settings.starSpeed; 155 | var starSpeedMin = starSpeed; 156 | var starSpeedMax = settings.starSpeedMax; 157 | var starSpeedAnimationDuration = settings.starFovAnimationDuration; 158 | var starSpeedAnimationTime = 0; 159 | 160 | var starFov = settings.starFov; 161 | var starFovMin = settings.starFovMin; 162 | var starFovMax = starFov; 163 | var starFovAnimationDuration = settings.starFovAnimationDuration; 164 | var starFovAnimationTime = starFovAnimationDuration; 165 | 166 | var starRotation = 0.0; 167 | var starRotationPermission = settings.starRotationPermission; 168 | var starRotationDirection = settings.starRotationDirection; 169 | var starRotationSpeed = settings.starRotationSpeed; 170 | var starRotationSpeedMin = starRotationSpeed; 171 | var starRotationSpeedMax = settings.starRotationSpeedMax; 172 | var starRotationAnimationDuration = settings.starRotationAnimationDuration; 173 | var starRotationAnimationTime = 0; 174 | 175 | var starWarpLineLength = settings.starWarpLineLength; 176 | var starWarpTunnelDiameter = settings.starWarpTunnelDiameter; 177 | var starFollowMouseSensitivity = settings.starFollowMouseSensitivity; 178 | var starFollowMouseXAxis = settings.starFollowMouseXAxis; 179 | var starFollowMouseYAxis = settings.starFollowMouseYAxis; 180 | var starDistance = 8000; 181 | 182 | var starBorderFront = -starFovMin + 1; 183 | var starBorderBack = starDistance; 184 | 185 | var starHolder; 186 | var starBgHolder; 187 | var starColorLookupTable; 188 | var starBgColorLookupTable; 189 | 190 | var canvas, ctx, imageData, pix; 191 | 192 | var center; 193 | 194 | var mouseActive; 195 | var mouseDown; 196 | var mousePos; 197 | 198 | var paused = false; 199 | 200 | //--- 201 | 202 | function init() { 203 | 204 | canvas = document.createElement( 'canvas' ); 205 | canvas.style.backgroundColor = rgbToHex( starfieldBackgroundColor.r, starfieldBackgroundColor.g, starfieldBackgroundColor.b ); 206 | canvas.setAttribute( 'width', canvasWidth ); 207 | canvas.setAttribute( 'height', canvasHeight ); 208 | 209 | if ( settings.addMouseControls ) { 210 | 211 | canvas.addEventListener( 'mousemove', mouseMoveHandler, false ); 212 | canvas.addEventListener( 'mousedown', mouseDownHandler, false ); 213 | canvas.addEventListener( 'mouseup', mouseUpHandler, false ); 214 | canvas.addEventListener( 'mouseenter', mouseEnterHandler, false ); 215 | canvas.addEventListener( 'mouseleave', mouseLeaveHandler, false ); 216 | 217 | } 218 | 219 | if ( settings.addTouchControls ) { 220 | 221 | canvas.addEventListener( 'touchstart', touchStartHandler, false ); 222 | canvas.addEventListener( 'touchend', touchEndHandler, false ); 223 | canvas.addEventListener( 'touchmove', touchMoveHandler, false ); 224 | canvas.addEventListener( 'touchcancel', touchCancelHandler, false ); 225 | 226 | } 227 | 228 | if ( settings.hideContextMenu ) { 229 | 230 | canvas.oncontextmenu = function( e ) { 231 | 232 | e.preventDefault(); 233 | 234 | }; 235 | 236 | } 237 | 238 | element.appendChild( canvas ); 239 | 240 | //--- 241 | 242 | ctx = canvas.getContext( '2d' ); 243 | imageData = ctx.getImageData( 0, 0, canvasWidth, canvasHeight ); 244 | pix = imageData.data; 245 | 246 | //--- 247 | 248 | center = { x:canvas.width / 2, y:canvas.height / 2 }; 249 | 250 | mouseActive = false; 251 | mouseDown = false; 252 | mousePos = { x:center.x, y:center.y }; 253 | 254 | //--- 255 | 256 | starColorLookupTable = []; 257 | starBgColorLookupTable = []; 258 | starHolder = []; 259 | starBgHolder = []; 260 | 261 | addColorLookupTable( starColorLookupTable, starColorRangeMin, starColorRangeMax, starfieldBackgroundColor, starColor ); 262 | addColorLookupTable( starBgColorLookupTable, starBgColorRangeMin, starBgColorRangeMax, starfieldBackgroundColor, starBgColor ); 263 | addStars(); 264 | animloop(); 265 | 266 | //--- 267 | 268 | if ( settings.autoResize ) { 269 | 270 | window.addEventListener( 'resize', resizeHandler ); 271 | 272 | resize(); 273 | 274 | } 275 | 276 | }; 277 | 278 | //--- 279 | 280 | Math.easeInQuad = function( t, b, c, d ) { 281 | 282 | return c * t * t / ( d * d ) + b; 283 | 284 | }; 285 | 286 | Math.easeOutQuad = function( t, b, c, d ) { 287 | 288 | return -c * t * t / ( d * d ) + 2 * c * t / d + b; 289 | 290 | }; 291 | 292 | //--- 293 | //http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors 294 | 295 | function shadeBlend( p, c0, c1 ) { 296 | 297 | var n = p < 0 ? p * -1 : p, u = Math.round, w = parseInt; 298 | var f = w( c0.slice( 1 ), 16 ), t = w( ( c1 ? c1 : p < 0 ? '#000000' : '#FFFFFF' ).slice( 1 ), 16 ), R1 = f >> 16, G1 = f >> 8 & 0x00FF, B1 = f & 0x0000FF; 299 | 300 | return '#' + ( 0x1000000 + ( u ( ( ( t >> 16 ) - R1 ) * n ) + R1 ) * 0x10000 + ( u ( ( ( t >> 8 & 0x00FF ) - G1 ) * n ) + G1 ) * 0x100 + ( u ( ( ( t & 0x0000FF ) - B1 ) * n ) + B1 ) ).toString( 16 ).slice( 1 ); 301 | 302 | }; 303 | 304 | //--- 305 | //http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb 306 | 307 | function hexToRgb( hex ) { 308 | 309 | var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; 310 | 311 | hex = hex.replace( shorthandRegex, function( m, r, g, b ) { 312 | 313 | return r + r + g + g + b + b; 314 | 315 | } ); 316 | 317 | var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( hex ); 318 | 319 | return result ? { 320 | 321 | r: parseInt( result[ 1 ], 16 ), 322 | g: parseInt( result[ 2 ], 16 ), 323 | b: parseInt( result[ 3 ], 16 ) 324 | 325 | } : null; 326 | 327 | }; 328 | 329 | function rgbToHex( r, g, b ) { 330 | 331 | var rgb = b | ( g << 8 ) | ( r << 16 ); 332 | 333 | return '#' + ( 0x1000000 + rgb ).toString( 16 ).slice( 1 ); 334 | 335 | }; 336 | 337 | //--- 338 | 339 | function parseRGBString( rgbString ) { 340 | 341 | rgbString = rgbString.replace( /\s+/g, '' ); 342 | 343 | var rgbValues = rgbString.split( '(' )[ 1 ].split( ')' )[ 0 ].split( ',' ); 344 | 345 | return { r:rgbValues[ 0 ], g:rgbValues[ 1 ], b:rgbValues[ 2 ] }; 346 | 347 | } 348 | 349 | //--- 350 | 351 | function clearImageData() { 352 | 353 | for ( var i = 0, l = pix.length; i < l; i += 4 ) { 354 | 355 | pix[ i ] = starfieldBackgroundColor.r; 356 | pix[ i + 1 ] = starfieldBackgroundColor.g; 357 | pix[ i + 2 ] = starfieldBackgroundColor.b; 358 | pix[ i + 3 ] = 0; 359 | 360 | } 361 | 362 | }; 363 | 364 | function setPixelAdditive( x, y, r, g, b, a ) { 365 | 366 | var i = ( x + y * canvasWidth ) * 4; 367 | 368 | pix[ i ] = pix[ i ] + r; 369 | pix[ i + 1 ] = pix[ i + 1 ] + g; 370 | pix[ i + 2 ] = pix[ i + 2 ] + b; 371 | pix[ i + 3 ] = a; 372 | 373 | }; 374 | 375 | //--- 376 | 377 | function drawLine( x1, y1, x2, y2, r, g, b, a ) { 378 | 379 | var dx = Math.abs( x2 - x1 ); 380 | var dy = Math.abs( y2 - y1 ); 381 | 382 | var sx = ( x1 < x2 ) ? 1 : -1; 383 | var sy = ( y1 < y2 ) ? 1 : -1; 384 | 385 | var err = dx - dy; 386 | 387 | var lx = x1; 388 | var ly = y1; 389 | 390 | while ( true ) { 391 | 392 | if ( lx > -1 && lx < canvasWidth && ly > -1 && ly < canvasHeight ) { 393 | 394 | setPixelAdditive( lx, ly, r, g, b, a ); 395 | 396 | } 397 | 398 | if ( ( lx === x2 ) && ( ly === y2 ) ) 399 | break; 400 | 401 | var e2 = 2 * err; 402 | 403 | if ( e2 > -dx ) { 404 | 405 | err -= dy; 406 | lx += sx; 407 | 408 | } 409 | 410 | if ( e2 < dy ) { 411 | 412 | err += dx; 413 | ly += sy; 414 | 415 | } 416 | 417 | } 418 | 419 | }; 420 | 421 | //--- 422 | 423 | function addColorLookupTable( colorLookupTable, colorRangeMin, colorRangeMax, colorRGBStart, colorRGBEnd ) { 424 | 425 | var colorHexStart = rgbToHex( colorRGBStart.r, colorRGBStart.g, colorRGBStart.b ); 426 | var colorHexEnd = rgbToHex( colorRGBEnd.r, colorRGBEnd.g, colorRGBEnd.b ); 427 | 428 | var colorRange = []; 429 | var colorEndValues = []; 430 | 431 | var percent; 432 | 433 | var i, l, j, k; 434 | 435 | for ( i = 0, l = 100; i <= l; i++ ) { 436 | 437 | percent = i / 100; 438 | 439 | colorRange.push( shadeBlend( percent, colorHexStart, colorHexEnd ) ); 440 | 441 | } 442 | 443 | for ( i = 0, l = colorRangeMax - colorRangeMin; i <= l; i++ ) { 444 | 445 | var index = i + colorRangeMin; 446 | 447 | colorEndValues.push( colorRange[ index ] ); 448 | 449 | } 450 | 451 | for ( i = 0, l = colorEndValues.length; i < l; i++ ) { 452 | 453 | colorRange = []; 454 | 455 | for ( j = 0, k = 100; j <= k; j++ ) { 456 | 457 | percent = j / 100; 458 | 459 | colorRange.push( hexToRgb( shadeBlend( percent, colorHexStart, colorEndValues[ i ] ) ) ); 460 | 461 | 462 | } 463 | 464 | colorLookupTable.push( colorRange ); 465 | 466 | } 467 | 468 | }; 469 | 470 | //--- 471 | 472 | function getStarPosition( radius, sideLength ) { 473 | 474 | var x = Math.random() * sideLength - ( sideLength / 2 ); 475 | var y = Math.random() * sideLength - ( sideLength / 2 ); 476 | 477 | if ( radius > 0 ) { 478 | 479 | while ( Math.sqrt( x * x + y * y ) < radius ) { 480 | 481 | x = Math.random() * sideLength - ( sideLength / 2 ); 482 | y = Math.random() * sideLength - ( sideLength / 2 ); 483 | 484 | } 485 | 486 | } 487 | 488 | return { x:x, y:y }; 489 | 490 | }; 491 | 492 | function addStar( x, y, z, ox, oy, oz ) { 493 | 494 | var star = {}; 495 | star.x = x; 496 | star.y = y; 497 | star.z = z; 498 | star.ox = ox; 499 | star.oy = oy; 500 | star.x2d = 0; 501 | star.y2d = 0; 502 | 503 | return star; 504 | 505 | }; 506 | 507 | function addStars() { 508 | 509 | var i; 510 | 511 | var x, y, z; 512 | 513 | var star, starPosition; 514 | 515 | for ( i = 0; i < starBgCount; i++ ) { 516 | 517 | starPosition = getStarPosition( 0, 20000 ); 518 | 519 | x = starPosition.x; 520 | y = starPosition.y; 521 | z = Math.round( Math.random() * starDistance ); 522 | 523 | star = addStar( x, y, z, x, y, z ); 524 | star.colorIndex = Math.floor( Math.random() * starBgColorLookupTable.length ); 525 | star.colorLookupTable = starBgColorLookupTable[ star.colorIndex ]; 526 | star.color = star.colorLookupTable[ Math.floor( Math.random() * 100 ) ]; 527 | 528 | starBgHolder.push( star ); 529 | 530 | } 531 | 532 | for ( i = 0; i < starCount; i++ ) { 533 | 534 | starPosition = getStarPosition( starWarpTunnelDiameter, 10000 ); 535 | 536 | x = starPosition.x; 537 | y = starPosition.y; 538 | z = Math.round( Math.random() * starDistance ); 539 | 540 | star = addStar( x, y, z, x, y, z ); 541 | star.distance = starDistance - z; 542 | star.distanceTotal = Math.round( starDistance + starFov ); 543 | star.colorIndex = Math.floor( Math.random() * starColorLookupTable.length ); 544 | star.colorLookupTable = starColorLookupTable[ star.colorIndex ]; 545 | star.color = star.colorLookupTable[ Math.floor( ( star.distance / star.distanceTotal ) * 100 ) ]; 546 | 547 | starHolder.push( star ); 548 | 549 | } 550 | 551 | }; 552 | 553 | //--- 554 | 555 | window.requestAnimFrame = ( function() { 556 | 557 | return window.requestAnimationFrame || 558 | window.webkitRequestAnimationFrame || 559 | window.mozRequestAnimationFrame || 560 | function( callback ) { 561 | window.setTimeout( callback, 1000 / 60 ); 562 | }; 563 | 564 | } )(); 565 | 566 | function animloop() { 567 | 568 | requestAnimFrame( animloop ); 569 | 570 | if ( !paused ) { 571 | 572 | render(); 573 | 574 | } 575 | 576 | }; 577 | 578 | //--- 579 | 580 | function render() { 581 | 582 | clearImageData(); 583 | 584 | //--- 585 | 586 | var i, j, l, k, m, n; 587 | 588 | //--- 589 | 590 | var star; 591 | var scale; 592 | 593 | //--- 594 | 595 | if ( starRotationPermission ) { 596 | 597 | if ( mouseDown ) { 598 | 599 | starRotationAnimationTime += 1; 600 | 601 | if ( starRotationAnimationTime > starRotationAnimationDuration ) 602 | starRotationAnimationTime = starRotationAnimationDuration; 603 | 604 | } else { 605 | 606 | starRotationAnimationTime -= 1; 607 | 608 | if ( starRotationAnimationTime < 0 ) 609 | starRotationAnimationTime = 0; 610 | 611 | } 612 | 613 | starRotationSpeed = Math.easeOutQuad( starRotationAnimationTime, starRotationSpeedMin, starRotationSpeedMax, starRotationAnimationDuration ); 614 | starRotation -= starRotationSpeed * starRotationDirection; 615 | 616 | } 617 | 618 | //--- 619 | 620 | if ( mouseActive ) { 621 | 622 | starSpeedAnimationTime += 1; 623 | 624 | if ( starSpeedAnimationTime > starSpeedAnimationDuration ) 625 | starSpeedAnimationTime = starSpeedAnimationDuration; 626 | 627 | starFovAnimationTime -= 1; 628 | 629 | if ( starFovAnimationTime < 0 ) 630 | starFovAnimationTime = 0; 631 | 632 | //--- 633 | 634 | if ( starFollowMouseXAxis ) { 635 | 636 | center.x += ( mousePos.x - center.x ) * starFollowMouseSensitivity; 637 | 638 | } 639 | 640 | if ( starFollowMouseYAxis ) { 641 | 642 | center.y += ( mousePos.y - center.y ) * starFollowMouseSensitivity; 643 | 644 | } 645 | 646 | } else { 647 | 648 | starSpeedAnimationTime -= 1; 649 | 650 | if ( starSpeedAnimationTime < 0 ) 651 | starSpeedAnimationTime = 0; 652 | 653 | starFovAnimationTime += 1; 654 | 655 | if ( starFovAnimationTime > starFovAnimationDuration ) 656 | starFovAnimationTime = starFovAnimationDuration; 657 | 658 | //--- 659 | 660 | if ( starFollowMouseXAxis ) { 661 | 662 | center.x += ( ( canvas.width / 2 ) - center.x ) * starFollowMouseSensitivity; 663 | 664 | } 665 | 666 | if ( starFollowMouseYAxis ) { 667 | 668 | center.y += ( ( canvas.height / 2 ) - center.y ) * starFollowMouseSensitivity; 669 | 670 | } 671 | 672 | } 673 | 674 | starSpeed = Math.easeOutQuad( starSpeedAnimationTime, 0, starSpeedMax - starSpeedMin, starSpeedAnimationDuration ) + starSpeedMin; 675 | starFov = Math.easeInQuad( starFovAnimationTime, 0, starFovMax - starFovMin, starFovAnimationDuration ) + starFovMin; 676 | 677 | //--- 678 | 679 | starBorderFront = -starFov + 1; 680 | 681 | //--- 682 | 683 | var warpSpeedValue = starSpeed * ( starSpeed / ( starSpeedMax / starWarpLineLength ) ); 684 | 685 | //--- 686 | //stars bg 687 | 688 | for ( i = 0, l = starBgHolder.length; i < l; i++ ) { 689 | 690 | star = starBgHolder[ i ]; 691 | 692 | scale = starFov / ( starFov + star.z ); 693 | 694 | star.x2d = ( star.x * scale ) + center.x; 695 | star.y2d = ( star.y * scale ) + center.y; 696 | 697 | if ( star.x2d > -1 && star.x2d < canvasWidth && star.y2d > -1 && star.y2d < canvasHeight ) { 698 | 699 | setPixelAdditive( star.x2d | 0, star.y2d | 0, star.color.r, star.color.g, star.color.b, 255 ); 700 | 701 | } 702 | 703 | } 704 | 705 | //--- 706 | //stars moving 707 | 708 | for ( i = 0, l = starHolder.length; i < l; i++ ) { 709 | 710 | star = starHolder[ i ]; 711 | 712 | //--- 713 | //star distance calc 714 | 715 | star.distanceTotal = Math.round( starDistance + starFov ); 716 | 717 | //--- 718 | //star movement 719 | 720 | if ( starDirection >= 0 ) { 721 | 722 | star.z -= starSpeed; 723 | star.distance += starSpeed; 724 | 725 | if ( star.z < starBorderFront ) { 726 | 727 | star.z = starBorderBack; 728 | star.distance = 0; 729 | 730 | } 731 | 732 | } else { 733 | 734 | star.z += starSpeed; 735 | star.distance -= starSpeed; 736 | 737 | if ( star.z > starBorderBack ) { 738 | 739 | star.z = starBorderFront; 740 | star.distance = star.distanceTotal; 741 | 742 | } 743 | 744 | } 745 | 746 | //--- 747 | //star color 748 | 749 | star.color = star.colorLookupTable[ Math.floor( ( star.distance / star.distanceTotal ) * 100 ) ]; 750 | 751 | //--- 752 | //star position & draw 753 | 754 | scale = starFov / ( starFov + star.z ); 755 | 756 | star.x2d = ( star.x * scale ) + center.x; 757 | star.y2d = ( star.y * scale ) + center.y; 758 | 759 | if ( starSpeed === starSpeedMin ) { 760 | 761 | if ( star.x2d > -1 && star.x2d < canvasWidth && star.y2d > -1 && star.y2d < canvasHeight ) { 762 | 763 | setPixelAdditive( star.x2d | 0, star.y2d | 0, star.color.r, star.color.g, star.color.b, 255 ); 764 | 765 | } 766 | 767 | } else { 768 | 769 | var nz = star.z + warpSpeedValue; 770 | 771 | scale = starFov / ( starFov + nz ); 772 | 773 | var x2d = ( star.x * scale ) + center.x; 774 | var y2d = ( star.y * scale ) + center.y; 775 | 776 | if ( x2d > -1 && x2d < canvasWidth && y2d > -1 && y2d < canvasHeight ) { 777 | 778 | drawLine( star.x2d | 0, star.y2d | 0, x2d | 0, y2d | 0, star.color.r, star.color.g, star.color.b, 255 ); 779 | 780 | } 781 | 782 | } 783 | 784 | //--- 785 | //star rotation 786 | 787 | if ( starRotationSpeed !== starRotationSpeedMin ) { 788 | 789 | var radians = MATHPI180 * starRotation; 790 | 791 | var cos = Math.cos( radians ); 792 | var sin = Math.sin( radians ); 793 | 794 | star.x = cos * star.ox + sin * star.oy; 795 | star.y = cos * star.oy - sin * star.ox; 796 | 797 | } 798 | 799 | } 800 | 801 | //--- 802 | 803 | ctx.putImageData( imageData, 0, 0 ); 804 | 805 | }; 806 | 807 | function resizeHandler( event ) { 808 | 809 | resize(); 810 | 811 | }; 812 | 813 | function resize() { 814 | 815 | canvasWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 816 | canvasHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 817 | 818 | if ( settings.autoResizeMinWidth && canvasWidth < settings.autoResizeMinWidth ) { 819 | 820 | canvasWidth = settings.autoResizeMinWidth; 821 | 822 | } else if ( settings.autoResizeMaxWidth && canvasWidth > settings.autoResizeMaxWidth ) { 823 | 824 | canvasWidth = settings.autoResizeMaxWidth; 825 | 826 | } 827 | 828 | if ( settings.autoResizeMinHeight && canvasHeight < settings.autoResizeMinHeight ) { 829 | 830 | canvasHeight = settings.autoResizeMinHeight; 831 | 832 | } else if ( settings.autoResizeMaxHeight && canvasHeight > settings.autoResizeMaxHeight ) { 833 | 834 | canvasHeight = settings.autoResizeMaxHeight; 835 | 836 | } 837 | 838 | //--- 839 | 840 | canvas.setAttribute( 'width', canvasWidth ); 841 | canvas.setAttribute( 'height', canvasHeight ); 842 | 843 | center = { x:canvas.width / 2, y:canvas.height / 2 }; 844 | 845 | //--- 846 | 847 | imageData = ctx.getImageData( 0, 0, canvasWidth, canvasHeight ); 848 | pix = imageData.data; 849 | 850 | }; 851 | 852 | //--- 853 | 854 | function mouseMoveHandler( event ) { 855 | 856 | mousePos = getMousePos( canvas, event ); 857 | 858 | }; 859 | 860 | function mouseEnterHandler( event ) { 861 | 862 | mouseActive = true; 863 | 864 | }; 865 | 866 | function mouseLeaveHandler( event ) { 867 | 868 | mouseActive = false; 869 | mouseDown = false; 870 | 871 | }; 872 | 873 | function mouseDownHandler( event ) { 874 | 875 | mouseDown = true; 876 | 877 | }; 878 | 879 | function mouseUpHandler( event ) { 880 | 881 | mouseDown = false; 882 | 883 | }; 884 | 885 | //--- 886 | 887 | function getMousePos( canvas, event ) { 888 | 889 | var rect = canvas.getBoundingClientRect(); 890 | 891 | return { x: event.clientX - rect.left, y: event.clientY - rect.top }; 892 | 893 | }; 894 | 895 | //--- 896 | 897 | function touchStartHandler( event ) { 898 | 899 | event.preventDefault(); 900 | 901 | mouseDown = true; 902 | mouseActive = true; 903 | 904 | }; 905 | 906 | function touchEndHandler( event ) { 907 | 908 | event.preventDefault(); 909 | 910 | mouseDown = false; 911 | mouseActive = false; 912 | 913 | }; 914 | 915 | function touchMoveHandler( event ) { 916 | 917 | event.preventDefault(); 918 | 919 | mousePos = getTouchPos( canvas, event ); 920 | 921 | }; 922 | 923 | function touchCancelHandler( event ) { 924 | 925 | mouseDown = false; 926 | mouseActive = false; 927 | 928 | }; 929 | 930 | //--- 931 | 932 | function getTouchPos( canvas, event ) { 933 | 934 | var rect = canvas.getBoundingClientRect(); 935 | 936 | return { x: event.touches[ 0 ].clientX - rect.left, y: event.touches[ 0 ].clientY - rect.top }; 937 | 938 | }; 939 | 940 | //--- 941 | 942 | this.pause = function() { 943 | 944 | paused = true; 945 | 946 | }; 947 | 948 | this.unpause = function() { 949 | 950 | paused = false; 951 | 952 | }; 953 | 954 | //--- 955 | 956 | init(); 957 | 958 | }; 959 | 960 | window.WarpDrive = WarpDrive; 961 | 962 | } () ); 963 | 964 | if ( typeof jQuery !== 'undefined' ) { 965 | 966 | ( function( $ ) { 967 | 968 | $.fn.warpDrive = function( params ) { 969 | 970 | var args = arguments; 971 | 972 | return this.each( function() { 973 | 974 | if ( !$.data( this, 'plugin_WarpDrive' ) ) { 975 | 976 | $.data( this, 'plugin_WarpDrive', new WarpDrive( this, params ) ); 977 | 978 | } else { 979 | 980 | var plugin = $.data( this, 'plugin_WarpDrive' ); 981 | 982 | if ( plugin[ params ] ) { 983 | 984 | plugin[ params ].apply( this, Array.prototype.slice.call( args, 1 ) ); 985 | 986 | } else { 987 | 988 | $.error( 'Method ' + params + ' does not exist on jQuery.warpDrive' ); 989 | 990 | } 991 | 992 | } 993 | 994 | } ); 995 | 996 | }; 997 | 998 | } ( jQuery ) ); 999 | 1000 | } -------------------------------------------------------------------------------- /sky/js/jquery.warpdrive.js: -------------------------------------------------------------------------------- 1 | /* 2 | Warp Drive jQuery plugin 3 | Version: 1.0.0 4 | 5 | Written by Niklas Knaack 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | ( function() { 27 | 28 | function WarpDrive( element, params ) { 29 | 30 | var settings = {}; 31 | settings.width = 480; 32 | settings.height = 480; 33 | settings.autoResize = false; 34 | settings.autoResizeMinWidth = null; 35 | settings.autoResizeMaxWidth = null; 36 | settings.autoResizeMinHeight = null; 37 | settings.autoResizeMaxHeight = null; 38 | settings.addMouseControls = true; 39 | settings.addTouchControls = true; 40 | settings.hideContextMenu = true; 41 | settings.starCount = 6666; 42 | settings.starBgCount = 2222; 43 | settings.starBgColor = { r:255, g:255, b:255 }; 44 | settings.starBgColorRangeMin = 10; 45 | settings.starBgColorRangeMax = 40; 46 | settings.starColor = { r:255, g:255, b:255 }; 47 | settings.starColorRangeMin = 10; 48 | settings.starColorRangeMax = 100; 49 | settings.starfieldBackgroundColor = { r:0, g:0, b:0 }; 50 | settings.starDirection = 1; 51 | settings.starSpeed = 20; 52 | settings.starSpeedMax = 200; 53 | settings.starSpeedAnimationDuration = 2; 54 | settings.starFov = 300; 55 | settings.starFovMin = 200; 56 | settings.starFovAnimationDuration = 2; 57 | settings.starRotationPermission = true; 58 | settings.starRotationDirection = 1; 59 | settings.starRotationSpeed = 0.0; 60 | settings.starRotationSpeedMax = 1.0; 61 | settings.starRotationAnimationDuration = 2; 62 | settings.starWarpLineLength = 2.0; 63 | settings.starWarpTunnelDiameter = 100; 64 | settings.starFollowMouseSensitivity = 0.025; 65 | settings.starFollowMouseXAxis = true; 66 | settings.starFollowMouseYAxis = true; 67 | 68 | //--- 69 | 70 | if ( params !== undefined ) { 71 | 72 | for ( var prop in params ) { 73 | 74 | if ( params.hasOwnProperty( prop ) && settings.hasOwnProperty( prop ) ) { 75 | 76 | settings[ prop ] = params[ prop ]; 77 | 78 | } 79 | 80 | } 81 | 82 | } 83 | 84 | //--- 85 | 86 | for ( var prop in settings ) { 87 | 88 | if ( settings.hasOwnProperty( prop ) && prop.indexOf( 'Duration' ) > -1 ) { 89 | 90 | settings[ prop ] = settings[ prop ] * 60; 91 | 92 | } 93 | 94 | } 95 | 96 | if ( typeof settings.starBgColor === 'string' && settings.starBgColor.indexOf( '#' ) > -1 ) { 97 | 98 | settings.starBgColor = hexToRgb( settings.starBgColor ); 99 | 100 | } else if ( typeof settings.starBgColor === 'string' && settings.starBgColor.indexOf( 'rgb' ) > -1 ) { 101 | 102 | settings.starBgColor = parseRGBString( settings.starBgColor ); 103 | 104 | } 105 | 106 | if ( typeof settings.starColor === 'string' && settings.starColor.indexOf( '#' ) > -1 ) { 107 | 108 | settings.starColor = hexToRgb( settings.starColor ); 109 | 110 | } else if ( typeof settings.starColor === 'string' && settings.starColor.indexOf( 'rgb' ) > -1 ) { 111 | 112 | settings.starColor = parseRGBString( settings.starColor ); 113 | 114 | } 115 | 116 | if ( typeof settings.starfieldBackgroundColor === 'string' && settings.starfieldBackgroundColor.indexOf( '#' ) > -1 ) { 117 | 118 | settings.starfieldBackgroundColor = hexToRgb( settings.starfieldBackgroundColor ); 119 | 120 | } else if ( typeof settings.starfieldBackgroundColor === 'string' && settings.starfieldBackgroundColor.indexOf( 'rgb' ) > -1 ) { 121 | 122 | settings.starfieldBackgroundColor = parseRGBString( settings.starfieldBackgroundColor ); 123 | 124 | } 125 | 126 | if ( !element ) { 127 | 128 | throw Error( '\n' + 'No div element found' ); 129 | 130 | } 131 | 132 | //--- 133 | 134 | var MATHPI180 = Math.PI / 180; 135 | var MATHPI2 = Math.PI * 2; 136 | 137 | var canvasWidth = settings.width; 138 | var canvasHeight = settings.height; 139 | 140 | var starCount = settings.starCount; 141 | var starBgCount = settings.starBgCount; 142 | 143 | var starBgColor = settings.starBgColor; 144 | var starBgColorRangeMin = settings.starBgColorRangeMin 145 | var starBgColorRangeMax = settings.starBgColorRangeMax 146 | var starColor = settings.starColor; 147 | var starColorRangeMin = settings.starColorRangeMin; 148 | var starColorRangeMax = settings.starColorRangeMax; 149 | 150 | var starfieldBackgroundColor = settings.starfieldBackgroundColor; 151 | 152 | var starDirection = settings.starDirection; 153 | 154 | var starSpeed = settings.starSpeed; 155 | var starSpeedMin = starSpeed; 156 | var starSpeedMax = settings.starSpeedMax; 157 | var starSpeedAnimationDuration = settings.starFovAnimationDuration; 158 | var starSpeedAnimationTime = 0; 159 | 160 | var starFov = settings.starFov; 161 | var starFovMin = settings.starFovMin; 162 | var starFovMax = starFov; 163 | var starFovAnimationDuration = settings.starFovAnimationDuration; 164 | var starFovAnimationTime = starFovAnimationDuration; 165 | 166 | var starRotation = 0.0; 167 | var starRotationPermission = settings.starRotationPermission; 168 | var starRotationDirection = settings.starRotationDirection; 169 | var starRotationSpeed = settings.starRotationSpeed; 170 | var starRotationSpeedMin = starRotationSpeed; 171 | var starRotationSpeedMax = settings.starRotationSpeedMax; 172 | var starRotationAnimationDuration = settings.starRotationAnimationDuration; 173 | var starRotationAnimationTime = 0; 174 | 175 | var starWarpLineLength = settings.starWarpLineLength; 176 | var starWarpTunnelDiameter = settings.starWarpTunnelDiameter; 177 | var starFollowMouseSensitivity = settings.starFollowMouseSensitivity; 178 | var starFollowMouseXAxis = settings.starFollowMouseXAxis; 179 | var starFollowMouseYAxis = settings.starFollowMouseYAxis; 180 | var starDistance = 8000; 181 | 182 | var starBorderFront = -starFovMin + 1; 183 | var starBorderBack = starDistance; 184 | 185 | var starHolder; 186 | var starBgHolder; 187 | var starColorLookupTable; 188 | var starBgColorLookupTable; 189 | 190 | var canvas, ctx, imageData, pix; 191 | 192 | var center; 193 | 194 | var mouseActive; 195 | var mouseDown; 196 | var mousePos; 197 | 198 | var paused = false; 199 | 200 | //--- 201 | 202 | function init() { 203 | 204 | canvas = document.createElement( 'canvas' ); 205 | canvas.style.backgroundColor = rgbToHex( starfieldBackgroundColor.r, starfieldBackgroundColor.g, starfieldBackgroundColor.b ); 206 | canvas.setAttribute( 'width', canvasWidth ); 207 | canvas.setAttribute( 'height', canvasHeight ); 208 | 209 | if ( settings.addMouseControls ) { 210 | 211 | canvas.addEventListener( 'mousemove', mouseMoveHandler, false ); 212 | canvas.addEventListener( 'mousedown', mouseDownHandler, false ); 213 | canvas.addEventListener( 'mouseup', mouseUpHandler, false ); 214 | canvas.addEventListener( 'mouseenter', mouseEnterHandler, false ); 215 | canvas.addEventListener( 'mouseleave', mouseLeaveHandler, false ); 216 | 217 | } 218 | 219 | if ( settings.addTouchControls ) { 220 | 221 | canvas.addEventListener( 'touchstart', touchStartHandler, false ); 222 | canvas.addEventListener( 'touchend', touchEndHandler, false ); 223 | canvas.addEventListener( 'touchmove', touchMoveHandler, false ); 224 | canvas.addEventListener( 'touchcancel', touchCancelHandler, false ); 225 | 226 | } 227 | 228 | if ( settings.hideContextMenu ) { 229 | 230 | canvas.oncontextmenu = function( e ) { 231 | 232 | e.preventDefault(); 233 | 234 | }; 235 | 236 | } 237 | 238 | element.appendChild( canvas ); 239 | 240 | //--- 241 | 242 | ctx = canvas.getContext( '2d' ); 243 | imageData = ctx.getImageData( 0, 0, canvasWidth, canvasHeight ); 244 | pix = imageData.data; 245 | 246 | //--- 247 | 248 | center = { x:canvas.width / 2, y:canvas.height / 2 }; 249 | 250 | mouseActive = false; 251 | mouseDown = false; 252 | mousePos = { x:center.x, y:center.y }; 253 | 254 | //--- 255 | 256 | starColorLookupTable = []; 257 | starBgColorLookupTable = []; 258 | starHolder = []; 259 | starBgHolder = []; 260 | 261 | addColorLookupTable( starColorLookupTable, starColorRangeMin, starColorRangeMax, starfieldBackgroundColor, starColor ); 262 | addColorLookupTable( starBgColorLookupTable, starBgColorRangeMin, starBgColorRangeMax, starfieldBackgroundColor, starBgColor ); 263 | addStars(); 264 | animloop(); 265 | 266 | //--- 267 | 268 | if ( settings.autoResize ) { 269 | 270 | window.addEventListener( 'resize', resizeHandler ); 271 | 272 | resize(); 273 | 274 | } 275 | 276 | }; 277 | 278 | //--- 279 | 280 | Math.easeInQuad = function( t, b, c, d ) { 281 | 282 | return c * t * t / ( d * d ) + b; 283 | 284 | }; 285 | 286 | Math.easeOutQuad = function( t, b, c, d ) { 287 | 288 | return -c * t * t / ( d * d ) + 2 * c * t / d + b; 289 | 290 | }; 291 | 292 | //--- 293 | //http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors 294 | 295 | function shadeBlend( p, c0, c1 ) { 296 | 297 | var n = p < 0 ? p * -1 : p, u = Math.round, w = parseInt; 298 | var f = w( c0.slice( 1 ), 16 ), t = w( ( c1 ? c1 : p < 0 ? '#000000' : '#FFFFFF' ).slice( 1 ), 16 ), R1 = f >> 16, G1 = f >> 8 & 0x00FF, B1 = f & 0x0000FF; 299 | 300 | return '#' + ( 0x1000000 + ( u ( ( ( t >> 16 ) - R1 ) * n ) + R1 ) * 0x10000 + ( u ( ( ( t >> 8 & 0x00FF ) - G1 ) * n ) + G1 ) * 0x100 + ( u ( ( ( t & 0x0000FF ) - B1 ) * n ) + B1 ) ).toString( 16 ).slice( 1 ); 301 | 302 | }; 303 | 304 | //--- 305 | //http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb 306 | 307 | function hexToRgb( hex ) { 308 | 309 | var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; 310 | 311 | hex = hex.replace( shorthandRegex, function( m, r, g, b ) { 312 | 313 | return r + r + g + g + b + b; 314 | 315 | } ); 316 | 317 | var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( hex ); 318 | 319 | return result ? { 320 | 321 | r: parseInt( result[ 1 ], 16 ), 322 | g: parseInt( result[ 2 ], 16 ), 323 | b: parseInt( result[ 3 ], 16 ) 324 | 325 | } : null; 326 | 327 | }; 328 | 329 | function rgbToHex( r, g, b ) { 330 | 331 | var rgb = b | ( g << 8 ) | ( r << 16 ); 332 | 333 | return '#' + ( 0x1000000 + rgb ).toString( 16 ).slice( 1 ); 334 | 335 | }; 336 | 337 | //--- 338 | 339 | function parseRGBString( rgbString ) { 340 | 341 | rgbString = rgbString.replace( /\s+/g, '' ); 342 | 343 | var rgbValues = rgbString.split( '(' )[ 1 ].split( ')' )[ 0 ].split( ',' ); 344 | 345 | return { r:rgbValues[ 0 ], g:rgbValues[ 1 ], b:rgbValues[ 2 ] }; 346 | 347 | } 348 | 349 | //--- 350 | 351 | function clearImageData() { 352 | 353 | for ( var i = 0, l = pix.length; i < l; i += 4 ) { 354 | 355 | pix[ i ] = starfieldBackgroundColor.r; 356 | pix[ i + 1 ] = starfieldBackgroundColor.g; 357 | pix[ i + 2 ] = starfieldBackgroundColor.b; 358 | pix[ i + 3 ] = 0; 359 | 360 | } 361 | 362 | }; 363 | 364 | function setPixelAdditive( x, y, r, g, b, a ) { 365 | 366 | var i = ( x + y * canvasWidth ) * 4; 367 | 368 | pix[ i ] = pix[ i ] + r; 369 | pix[ i + 1 ] = pix[ i + 1 ] + g; 370 | pix[ i + 2 ] = pix[ i + 2 ] + b; 371 | pix[ i + 3 ] = a; 372 | 373 | }; 374 | 375 | //--- 376 | 377 | function drawLine( x1, y1, x2, y2, r, g, b, a ) { 378 | 379 | var dx = Math.abs( x2 - x1 ); 380 | var dy = Math.abs( y2 - y1 ); 381 | 382 | var sx = ( x1 < x2 ) ? 1 : -1; 383 | var sy = ( y1 < y2 ) ? 1 : -1; 384 | 385 | var err = dx - dy; 386 | 387 | var lx = x1; 388 | var ly = y1; 389 | 390 | while ( true ) { 391 | 392 | if ( lx > -1 && lx < canvasWidth && ly > -1 && ly < canvasHeight ) { 393 | 394 | setPixelAdditive( lx, ly, r, g, b, a ); 395 | 396 | } 397 | 398 | if ( ( lx === x2 ) && ( ly === y2 ) ) 399 | break; 400 | 401 | var e2 = 2 * err; 402 | 403 | if ( e2 > -dx ) { 404 | 405 | err -= dy; 406 | lx += sx; 407 | 408 | } 409 | 410 | if ( e2 < dy ) { 411 | 412 | err += dx; 413 | ly += sy; 414 | 415 | } 416 | 417 | } 418 | 419 | }; 420 | 421 | //--- 422 | 423 | function addColorLookupTable( colorLookupTable, colorRangeMin, colorRangeMax, colorRGBStart, colorRGBEnd ) { 424 | 425 | var colorHexStart = rgbToHex( colorRGBStart.r, colorRGBStart.g, colorRGBStart.b ); 426 | var colorHexEnd = rgbToHex( colorRGBEnd.r, colorRGBEnd.g, colorRGBEnd.b ); 427 | 428 | var colorRange = []; 429 | var colorEndValues = []; 430 | 431 | var percent; 432 | 433 | var i, l, j, k; 434 | 435 | for ( i = 0, l = 100; i <= l; i++ ) { 436 | 437 | percent = i / 100; 438 | 439 | colorRange.push( shadeBlend( percent, colorHexStart, colorHexEnd ) ); 440 | 441 | } 442 | 443 | for ( i = 0, l = colorRangeMax - colorRangeMin; i <= l; i++ ) { 444 | 445 | var index = i + colorRangeMin; 446 | 447 | colorEndValues.push( colorRange[ index ] ); 448 | 449 | } 450 | 451 | for ( i = 0, l = colorEndValues.length; i < l; i++ ) { 452 | 453 | colorRange = []; 454 | 455 | for ( j = 0, k = 100; j <= k; j++ ) { 456 | 457 | percent = j / 100; 458 | 459 | colorRange.push( hexToRgb( shadeBlend( percent, colorHexStart, colorEndValues[ i ] ) ) ); 460 | 461 | 462 | } 463 | 464 | colorLookupTable.push( colorRange ); 465 | 466 | } 467 | 468 | }; 469 | 470 | //--- 471 | 472 | function getStarPosition( radius, sideLength ) { 473 | 474 | var x = Math.random() * sideLength - ( sideLength / 2 ); 475 | var y = Math.random() * sideLength - ( sideLength / 2 ); 476 | 477 | if ( radius > 0 ) { 478 | 479 | while ( Math.sqrt( x * x + y * y ) < radius ) { 480 | 481 | x = Math.random() * sideLength - ( sideLength / 2 ); 482 | y = Math.random() * sideLength - ( sideLength / 2 ); 483 | 484 | } 485 | 486 | } 487 | 488 | return { x:x, y:y }; 489 | 490 | }; 491 | 492 | function addStar( x, y, z, ox, oy, oz ) { 493 | 494 | var star = {}; 495 | star.x = x; 496 | star.y = y; 497 | star.z = z; 498 | star.ox = ox; 499 | star.oy = oy; 500 | star.x2d = 0; 501 | star.y2d = 0; 502 | 503 | return star; 504 | 505 | }; 506 | 507 | function addStars() { 508 | 509 | var i; 510 | 511 | var x, y, z; 512 | 513 | var star, starPosition; 514 | 515 | for ( i = 0; i < starBgCount; i++ ) { 516 | 517 | starPosition = getStarPosition( 0, 20000 ); 518 | 519 | x = starPosition.x; 520 | y = starPosition.y; 521 | z = Math.round( Math.random() * starDistance ); 522 | 523 | star = addStar( x, y, z, x, y, z ); 524 | star.colorIndex = Math.floor( Math.random() * starBgColorLookupTable.length ); 525 | star.colorLookupTable = starBgColorLookupTable[ star.colorIndex ]; 526 | star.color = star.colorLookupTable[ Math.floor( Math.random() * 100 ) ]; 527 | 528 | starBgHolder.push( star ); 529 | 530 | } 531 | 532 | for ( i = 0; i < starCount; i++ ) { 533 | 534 | starPosition = getStarPosition( starWarpTunnelDiameter, 10000 ); 535 | 536 | x = starPosition.x; 537 | y = starPosition.y; 538 | z = Math.round( Math.random() * starDistance ); 539 | 540 | star = addStar( x, y, z, x, y, z ); 541 | star.distance = starDistance - z; 542 | star.distanceTotal = Math.round( starDistance + starFov ); 543 | star.colorIndex = Math.floor( Math.random() * starColorLookupTable.length ); 544 | star.colorLookupTable = starColorLookupTable[ star.colorIndex ]; 545 | star.color = star.colorLookupTable[ Math.floor( ( star.distance / star.distanceTotal ) * 100 ) ]; 546 | 547 | starHolder.push( star ); 548 | 549 | } 550 | 551 | }; 552 | 553 | //--- 554 | 555 | window.requestAnimFrame = ( function() { 556 | 557 | return window.requestAnimationFrame || 558 | window.webkitRequestAnimationFrame || 559 | window.mozRequestAnimationFrame || 560 | function( callback ) { 561 | window.setTimeout( callback, 1000 / 60 ); 562 | }; 563 | 564 | } )(); 565 | 566 | function animloop() { 567 | 568 | requestAnimFrame( animloop ); 569 | 570 | if ( !paused ) { 571 | 572 | render(); 573 | 574 | } 575 | 576 | }; 577 | 578 | //--- 579 | 580 | function render() { 581 | 582 | clearImageData(); 583 | 584 | //--- 585 | 586 | var i, j, l, k, m, n; 587 | 588 | //--- 589 | 590 | var star; 591 | var scale; 592 | 593 | //--- 594 | 595 | if ( starRotationPermission ) { 596 | 597 | if ( mouseDown ) { 598 | 599 | starRotationAnimationTime += 1; 600 | 601 | if ( starRotationAnimationTime > starRotationAnimationDuration ) 602 | starRotationAnimationTime = starRotationAnimationDuration; 603 | 604 | } else { 605 | 606 | starRotationAnimationTime -= 1; 607 | 608 | if ( starRotationAnimationTime < 0 ) 609 | starRotationAnimationTime = 0; 610 | 611 | } 612 | 613 | starRotationSpeed = Math.easeOutQuad( starRotationAnimationTime, starRotationSpeedMin, starRotationSpeedMax, starRotationAnimationDuration ); 614 | starRotation -= starRotationSpeed * starRotationDirection; 615 | 616 | } 617 | 618 | //--- 619 | 620 | if ( mouseActive ) { 621 | 622 | starSpeedAnimationTime += 1; 623 | 624 | if ( starSpeedAnimationTime > starSpeedAnimationDuration ) 625 | starSpeedAnimationTime = starSpeedAnimationDuration; 626 | 627 | starFovAnimationTime -= 1; 628 | 629 | if ( starFovAnimationTime < 0 ) 630 | starFovAnimationTime = 0; 631 | 632 | //--- 633 | 634 | if ( starFollowMouseXAxis ) { 635 | 636 | center.x += ( mousePos.x - center.x ) * starFollowMouseSensitivity; 637 | 638 | } 639 | 640 | if ( starFollowMouseYAxis ) { 641 | 642 | center.y += ( mousePos.y - center.y ) * starFollowMouseSensitivity; 643 | 644 | } 645 | 646 | } else { 647 | 648 | starSpeedAnimationTime -= 1; 649 | 650 | if ( starSpeedAnimationTime < 0 ) 651 | starSpeedAnimationTime = 0; 652 | 653 | starFovAnimationTime += 1; 654 | 655 | if ( starFovAnimationTime > starFovAnimationDuration ) 656 | starFovAnimationTime = starFovAnimationDuration; 657 | 658 | //--- 659 | 660 | if ( starFollowMouseXAxis ) { 661 | 662 | center.x += ( ( canvas.width / 2 ) - center.x ) * starFollowMouseSensitivity; 663 | 664 | } 665 | 666 | if ( starFollowMouseYAxis ) { 667 | 668 | center.y += ( ( canvas.height / 2 ) - center.y ) * starFollowMouseSensitivity; 669 | 670 | } 671 | 672 | } 673 | 674 | starSpeed = Math.easeOutQuad( starSpeedAnimationTime, 0, starSpeedMax - starSpeedMin, starSpeedAnimationDuration ) + starSpeedMin; 675 | starFov = Math.easeInQuad( starFovAnimationTime, 0, starFovMax - starFovMin, starFovAnimationDuration ) + starFovMin; 676 | 677 | //--- 678 | 679 | starBorderFront = -starFov + 1; 680 | 681 | //--- 682 | 683 | var warpSpeedValue = starSpeed * ( starSpeed / ( starSpeedMax / starWarpLineLength ) ); 684 | 685 | //--- 686 | //stars bg 687 | 688 | for ( i = 0, l = starBgHolder.length; i < l; i++ ) { 689 | 690 | star = starBgHolder[ i ]; 691 | 692 | scale = starFov / ( starFov + star.z ); 693 | 694 | star.x2d = ( star.x * scale ) + center.x; 695 | star.y2d = ( star.y * scale ) + center.y; 696 | 697 | if ( star.x2d > -1 && star.x2d < canvasWidth && star.y2d > -1 && star.y2d < canvasHeight ) { 698 | 699 | setPixelAdditive( star.x2d | 0, star.y2d | 0, star.color.r, star.color.g, star.color.b, 255 ); 700 | 701 | } 702 | 703 | } 704 | 705 | //--- 706 | //stars moving 707 | 708 | for ( i = 0, l = starHolder.length; i < l; i++ ) { 709 | 710 | star = starHolder[ i ]; 711 | 712 | //--- 713 | //star distance calc 714 | 715 | star.distanceTotal = Math.round( starDistance + starFov ); 716 | 717 | //--- 718 | //star movement 719 | 720 | if ( starDirection >= 0 ) { 721 | 722 | star.z -= starSpeed; 723 | star.distance += starSpeed; 724 | 725 | if ( star.z < starBorderFront ) { 726 | 727 | star.z = starBorderBack; 728 | star.distance = 0; 729 | 730 | } 731 | 732 | } else { 733 | 734 | star.z += starSpeed; 735 | star.distance -= starSpeed; 736 | 737 | if ( star.z > starBorderBack ) { 738 | 739 | star.z = starBorderFront; 740 | star.distance = star.distanceTotal; 741 | 742 | } 743 | 744 | } 745 | 746 | //--- 747 | //star color 748 | 749 | star.color = star.colorLookupTable[ Math.floor( ( star.distance / star.distanceTotal ) * 100 ) ]; 750 | 751 | //--- 752 | //star position & draw 753 | 754 | scale = starFov / ( starFov + star.z ); 755 | 756 | star.x2d = ( star.x * scale ) + center.x; 757 | star.y2d = ( star.y * scale ) + center.y; 758 | 759 | if ( starSpeed === starSpeedMin ) { 760 | 761 | if ( star.x2d > -1 && star.x2d < canvasWidth && star.y2d > -1 && star.y2d < canvasHeight ) { 762 | 763 | setPixelAdditive( star.x2d | 0, star.y2d | 0, star.color.r, star.color.g, star.color.b, 255 ); 764 | 765 | } 766 | 767 | } else { 768 | 769 | var nz = star.z + warpSpeedValue; 770 | 771 | scale = starFov / ( starFov + nz ); 772 | 773 | var x2d = ( star.x * scale ) + center.x; 774 | var y2d = ( star.y * scale ) + center.y; 775 | 776 | if ( x2d > -1 && x2d < canvasWidth && y2d > -1 && y2d < canvasHeight ) { 777 | 778 | drawLine( star.x2d | 0, star.y2d | 0, x2d | 0, y2d | 0, star.color.r, star.color.g, star.color.b, 255 ); 779 | 780 | } 781 | 782 | } 783 | 784 | //--- 785 | //star rotation 786 | 787 | if ( starRotationSpeed !== starRotationSpeedMin ) { 788 | 789 | var radians = MATHPI180 * starRotation; 790 | 791 | var cos = Math.cos( radians ); 792 | var sin = Math.sin( radians ); 793 | 794 | star.x = cos * star.ox + sin * star.oy; 795 | star.y = cos * star.oy - sin * star.ox; 796 | 797 | } 798 | 799 | } 800 | 801 | //--- 802 | 803 | ctx.putImageData( imageData, 0, 0 ); 804 | 805 | }; 806 | 807 | function resizeHandler( event ) { 808 | 809 | resize(); 810 | 811 | }; 812 | 813 | function resize() { 814 | 815 | canvasWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 816 | canvasHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 817 | 818 | if ( settings.autoResizeMinWidth && canvasWidth < settings.autoResizeMinWidth ) { 819 | 820 | canvasWidth = settings.autoResizeMinWidth; 821 | 822 | } else if ( settings.autoResizeMaxWidth && canvasWidth > settings.autoResizeMaxWidth ) { 823 | 824 | canvasWidth = settings.autoResizeMaxWidth; 825 | 826 | } 827 | 828 | if ( settings.autoResizeMinHeight && canvasHeight < settings.autoResizeMinHeight ) { 829 | 830 | canvasHeight = settings.autoResizeMinHeight; 831 | 832 | } else if ( settings.autoResizeMaxHeight && canvasHeight > settings.autoResizeMaxHeight ) { 833 | 834 | canvasHeight = settings.autoResizeMaxHeight; 835 | 836 | } 837 | 838 | //--- 839 | 840 | canvas.setAttribute( 'width', canvasWidth ); 841 | canvas.setAttribute( 'height', canvasHeight ); 842 | 843 | center = { x:canvas.width / 2, y:canvas.height / 2 }; 844 | 845 | //--- 846 | 847 | imageData = ctx.getImageData( 0, 0, canvasWidth, canvasHeight ); 848 | pix = imageData.data; 849 | 850 | }; 851 | 852 | //--- 853 | 854 | function mouseMoveHandler( event ) { 855 | 856 | mousePos = getMousePos( canvas, event ); 857 | 858 | }; 859 | 860 | function mouseEnterHandler( event ) { 861 | 862 | mouseActive = true; 863 | 864 | }; 865 | 866 | function mouseLeaveHandler( event ) { 867 | 868 | mouseActive = false; 869 | mouseDown = false; 870 | 871 | }; 872 | 873 | function mouseDownHandler( event ) { 874 | 875 | mouseDown = true; 876 | 877 | }; 878 | 879 | function mouseUpHandler( event ) { 880 | 881 | mouseDown = false; 882 | 883 | }; 884 | 885 | //--- 886 | 887 | function getMousePos( canvas, event ) { 888 | 889 | var rect = canvas.getBoundingClientRect(); 890 | 891 | return { x: event.clientX - rect.left, y: event.clientY - rect.top }; 892 | 893 | }; 894 | 895 | //--- 896 | 897 | function touchStartHandler( event ) { 898 | 899 | event.preventDefault(); 900 | 901 | mouseDown = true; 902 | mouseActive = true; 903 | 904 | }; 905 | 906 | function touchEndHandler( event ) { 907 | 908 | event.preventDefault(); 909 | 910 | mouseDown = false; 911 | mouseActive = false; 912 | 913 | }; 914 | 915 | function touchMoveHandler( event ) { 916 | 917 | event.preventDefault(); 918 | 919 | mousePos = getTouchPos( canvas, event ); 920 | 921 | }; 922 | 923 | function touchCancelHandler( event ) { 924 | 925 | mouseDown = false; 926 | mouseActive = false; 927 | 928 | }; 929 | 930 | //--- 931 | 932 | function getTouchPos( canvas, event ) { 933 | 934 | var rect = canvas.getBoundingClientRect(); 935 | 936 | return { x: event.touches[ 0 ].clientX - rect.left, y: event.touches[ 0 ].clientY - rect.top }; 937 | 938 | }; 939 | 940 | //--- 941 | 942 | this.pause = function() { 943 | 944 | paused = true; 945 | 946 | }; 947 | 948 | this.unpause = function() { 949 | 950 | paused = false; 951 | 952 | }; 953 | 954 | //--- 955 | 956 | init(); 957 | 958 | }; 959 | 960 | window.WarpDrive = WarpDrive; 961 | 962 | } () ); 963 | 964 | if ( typeof jQuery !== 'undefined' ) { 965 | 966 | ( function( $ ) { 967 | 968 | $.fn.warpDrive = function( params ) { 969 | 970 | var args = arguments; 971 | 972 | return this.each( function() { 973 | 974 | if ( !$.data( this, 'plugin_WarpDrive' ) ) { 975 | 976 | $.data( this, 'plugin_WarpDrive', new WarpDrive( this, params ) ); 977 | 978 | } else { 979 | 980 | var plugin = $.data( this, 'plugin_WarpDrive' ); 981 | 982 | if ( plugin[ params ] ) { 983 | 984 | plugin[ params ].apply( this, Array.prototype.slice.call( args, 1 ) ); 985 | 986 | } else { 987 | 988 | $.error( 'Method ' + params + ' does not exist on jQuery.warpDrive' ); 989 | 990 | } 991 | 992 | } 993 | 994 | } ); 995 | 996 | }; 997 | 998 | } ( jQuery ) ); 999 | 1000 | } --------------------------------------------------------------------------------16 | 22 |纯CSS3杂志翻页动画特效 Pure CSS Magazine style layout with transitions
17 | 21 |23 | 24 | 25 | 26 | 27 |273 | 274 |28 |38 |29 |37 |Fashion30 |1 231 |32 |36 |33 |35 |The latest in fashion & fashion design
34 |39 |51 |40 |50 |41 |46 |42 |44 | 45 |The latest in fashion & fashion design
43 |47 | 48 |49 |52 |111 |53 |110 |Fashion54 |2 355 |56 | 57 |58 |59 |109 |60 |62 |61 |
63 |66 |Subtitle
64 |Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a imperdiet sapien. Nunc vehicula lorem neque, eu rutrum sapien posuere ut. Nunc eget ullamcorper turpis. Sed in vehicula magna, vitae eleifend velit. Donec dui turpis, viverra vitae lobortis commodo, lobortis et ex.
65 |67 | L 68 | o 69 | o 70 | k 71 | 72 | a 73 | t 74 | 75 | t 76 | h 77 | i 78 | s 79 | 80 | a 81 | w 82 | e 83 | s 84 | o 85 | m 86 | e 87 |
108 |
88 | h 89 | e 90 | a 91 | d 92 | l 93 | i 94 | n 95 | e 96 | 97 | r 98 | i 99 | g 100 | h 101 | t 102 | 103 | h 104 | e 105 | r 106 | e 107 |112 |189 |113 |188 |114 | 115 | 116 | 117 |118 |119 | 120 |121 | 122 | 128 |129 |187 |130 |141 |131 | 132 | " 133 | 134 | This is a quote 135 | from someone 136 | Jamie Coulter 137 | - Jcoulterdesign 138 | " 139 |
140 |142 |144 |143 |
145 | L 146 | o 147 | o 148 | k 149 | 150 | a 151 | t 152 | 153 | t 154 | h 155 | i 156 | s 157 | 158 | a 159 | w 160 | e 161 | s 162 | o 163 | m 164 | e 165 |
186 |
166 | h 167 | e 168 | a 169 | d 170 | l 171 | i 172 | n 173 | e 174 | 175 | r 176 | i 177 | g 178 | h 179 | t 180 | 181 | h 182 | e 183 | r 184 | e 185 |190 |204 |191 |203 |Fashion192 |4 5193 |194 |199 |195 |198 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
196 |Lorem ipsum dolor sit amet
197 |200 | 201 |202 |205 |232 |206 |231 |207 | 208 | 209 | 210 |211 |212 | 213 |214 | 215 |216 |218 |217 |
219 |224 | 230 |220 |223 |Lorem ipsum dolor sit amet, consectetur adipiscing elit
221 |Lorem ipsum dolor sit amet
222 |233 |255 |234 |254 |Fashion235 |6 7236 |237 |250 |238 |241 |Super
239 |Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a imperdiet sapien. Nunc vehicula lorem neque, eu rutrum sapien posuere ut. Nunc eget ullamcorper turpis. Sed in vehicula magna, vitae eleifend velit.
240 |242 |245 |Awesome
243 |Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a imperdiet sapien. Nunc vehicula lorem neque, eu rutrum sapien posuere ut. Nunc eget ullamcorper turpis. Sed in vehicula magna, vitae eleifend velit.
244 |246 |249 |Great
247 |Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a imperdiet sapien. Nunc vehicula lorem neque, eu rutrum sapien posuere ut. Nunc eget ullamcorper turpis. Sed in vehicula magna.
248 |251 | 252 |253 |256 |272 |257 |271 |258 | 259 | 260 | 261 |262 | 263 | 264 | 270 |