├── README.md ├── codef ├── codef_3d.js ├── codef_core.js ├── codef_fx.js ├── codef_gradient.js ├── codef_scrolltext.js ├── codef_starfield.js ├── codef_stats.js └── codef_tween.js └── extras ├── codef_music.js └── codef_music.js.full /README.md: -------------------------------------------------------------------------------- 1 | CODEF 2 | ===== 3 | 4 | Canvas Oldskool Demo Effects Framework (javascript / canvas / html5 / demoscene / old school ) 5 | 6 | Copyright (c) 2011 Antoine Santo Aka NoNameNo 7 | 8 | Project HomePage -> http://codef.santo.fr
9 | Demo Gallery -> http://www.wab.com 10 | 11 | 12 | Some parts of Codef are based on : 13 | 14 | * MrDoob's Three.js 15 | * Christian Corti's flod 16 | * tween.js 17 | * 18 | * thanks to them... ;) 19 | -------------------------------------------------------------------------------- /codef/codef_core.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------ 2 | Copyright (c) 2011 Antoine Santo Aka NoNameNo 3 | 4 | This File is part of the CODEF project. (https://github.com/N0NameN0/CODEF) 5 | 6 | More info : http://codef.santo.fr 7 | Demo gallery http://www.wab.com 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | ------------------------------------------------------------------------------*/ 27 | 28 | window.requestAnimFrame = (function(){ 29 | return window.requestAnimationFrame || 30 | window.webkitRequestAnimationFrame || 31 | window.mozRequestAnimationFrame || 32 | window.oRequestAnimationFrame || 33 | window.msRequestAnimationFrame || 34 | function(/* function */ callback, /* DOMElement */ element){ 35 | window.setTimeout(callback, 1000 / 60); 36 | }; 37 | })(); 38 | 39 | function canvas(w, h, divname){ 40 | this.width=w; 41 | this.height=h; 42 | this.canvas; 43 | this.contex; 44 | this.canvas = document.createElement("canvas"); 45 | if(divname) document.getElementById(divname).appendChild(this.canvas); 46 | this.canvas.setAttribute('width', w); 47 | this.canvas.setAttribute('height', h); 48 | this.contex = this.canvas.getContext('2d'); 49 | 50 | this.handlex=0; 51 | this.handley=0; 52 | this.midhandled=false; 53 | this.tilew=0; 54 | this.tileh=0; 55 | this.tilestart=0; 56 | 57 | this.fill = function(color){ 58 | var tmp = this.contex.fillStyle; 59 | var tmp2= this.contex.globalAlpha; 60 | this.contex.globalAlpha=1; 61 | this.contex.fillStyle = color; 62 | this.contex.fillRect (0, 0, this.canvas.width, this.canvas.height); 63 | this.contex.fillStyle = tmp 64 | this.contex.globalAlpha=tmp2; 65 | } 66 | 67 | this.clear = function(){ 68 | this.contex.clearRect (0, 0, this.canvas.width, this.canvas.height); 69 | } 70 | 71 | this.plot = function(x,y,width,color){ 72 | this.quad(x,y,x+width,y,x+width,y+width,x,y+width,color); 73 | } 74 | 75 | this.line = function(x1,y1,x2,y2,width,color){ 76 | var tmp=this.contex.strokeStyle; 77 | this.contex.strokeStyle=color; 78 | this.contex.lineWidth=width; 79 | this.contex.beginPath(); 80 | this.contex.moveTo(x1,y1); 81 | this.contex.lineTo(x2,y2); 82 | this.contex.stroke(); 83 | this.contex.closePath(); 84 | this.contex.strokeStyle=tmp; 85 | } 86 | 87 | this.triangle = function(x1,y1,x2,y2,x3,y3,color){ 88 | this.contex.beginPath(); 89 | this.contex.moveTo(x1,y1); 90 | this.contex.lineTo(x2,y2); 91 | this.contex.lineTo(x3,y3); 92 | this.contex.closePath(); 93 | this.contex.fillStyle=color; 94 | this.contex.fill(); 95 | } 96 | 97 | this.quad = function(x1,y1,x2,y2,x3,y3,x4,y4,color){ 98 | this.contex.beginPath(); 99 | 100 | if(arguments.length==5){ 101 | this.contex.moveTo(x1,y1); 102 | this.contex.lineTo(x1+x2,y1); 103 | this.contex.lineTo(x1+x2,y1+y2); 104 | this.contex.lineTo(x1,y1+y2); 105 | this.contex.closePath(); 106 | this.contex.fillStyle=x3; 107 | 108 | } 109 | else{ 110 | this.contex.moveTo(x1,y1); 111 | this.contex.lineTo(x2,y2); 112 | this.contex.lineTo(x3,y3); 113 | this.contex.lineTo(x4,y4); 114 | this.contex.closePath(); 115 | this.contex.fillStyle=color; 116 | 117 | } 118 | this.contex.fill(); 119 | } 120 | 121 | this.initTile=function(tilew,tileh, tilestart){ 122 | this.tileh=tileh; 123 | this.tilew=tilew; 124 | if(typeof(tilestart)!='undefined') 125 | this.tilestart=tilestart; 126 | } 127 | 128 | this.draw = function(dst,x,y,alpha, rot,w,h){ 129 | var tmp=dst.contex.globalAlpha; 130 | if(typeof(alpha)=='undefined') alpha=1; 131 | dst.contex.globalAlpha=alpha; 132 | if(arguments.length==3 || arguments.length==4) 133 | dst.contex.drawImage(this.canvas, x-this.handlex,y-this.handley); 134 | else if(arguments.length==5){ 135 | dst.contex.translate(x,y); 136 | dst.contex.rotate(rot*Math.PI/180); 137 | dst.contex.translate(-this.handlex,-this.handley); 138 | dst.contex.drawImage(this.canvas, 0,0); 139 | dst.contex.setTransform(1, 0, 0, 1, 0, 0); 140 | } 141 | else{ 142 | dst.contex.translate(x,y); 143 | dst.contex.rotate(rot*Math.PI/180); 144 | dst.contex.scale(w,h); 145 | dst.contex.translate(-this.handlex,-this.handley); 146 | dst.contex.drawImage(this.canvas, 0,0); 147 | dst.contex.setTransform(1, 0, 0, 1, 0, 0); 148 | } 149 | dst.contex.globalAlpha=tmp; 150 | } 151 | 152 | this.drawTile = function(dst, nb, x, y, alpha, rot, w, h){ 153 | var tmp=dst.contex.globalAlpha; 154 | if(typeof(alpha)=='undefined') alpha=1; 155 | dst.contex.globalAlpha=alpha; 156 | this.drawPart(dst,x,y,Math.floor((nb%(this.canvas.width/this.tilew)))*this.tilew,Math.floor(nb/(this.canvas.width/this.tilew))*this.tileh,this.tilew,this.tileh,alpha, rot, w, h); 157 | dst.contex.globalAlpha=tmp; 158 | 159 | } 160 | 161 | this.drawPart = function(dst,x,y,partx,party,partw,parth,alpha, rot,zx,zy){ 162 | var tmp=dst.contex.globalAlpha; 163 | if(typeof(alpha)=='undefined') alpha=1; 164 | dst.contex.globalAlpha=alpha; 165 | if(arguments.length==7 || arguments.length==8){ 166 | dst.contex.translate(x,y); 167 | if(this.midhandled==true) dst.contex.translate(-partw/2,-parth/2); else dst.contex.translate(-this.handlex,-this.handley); 168 | dst.contex.drawImage(this.canvas,partx,party,partw,parth,null,null,partw,parth); 169 | dst.contex.setTransform(1, 0, 0, 1, 0, 0); 170 | } 171 | else if(arguments.length==9){ 172 | dst.contex.translate(x,y); 173 | dst.contex.rotate(rot*Math.PI/180); 174 | if(this.midhandled==true) dst.contex.translate(-partw/2,-parth/2); else dst.contex.translate(-this.handlex,-this.handley); 175 | dst.contex.drawImage(this.canvas,partx,party,partw,parth,null,null,partw,parth); 176 | dst.contex.setTransform(1, 0, 0, 1, 0, 0); 177 | } 178 | else{ 179 | dst.contex.translate(x,y); 180 | dst.contex.rotate(rot*Math.PI/180); 181 | dst.contex.scale(zx,zy); 182 | if(this.midhandled==true) dst.contex.translate(-partw/2,-parth/2); else dst.contex.translate(-this.handlex,-this.handley); 183 | dst.contex.drawImage(this.canvas,partx,party,partw,parth,null,null,partw,parth); 184 | dst.contex.setTransform(1, 0, 0, 1, 0, 0); 185 | } 186 | dst.contex.globalAlpha=tmp; 187 | } 188 | 189 | this.setmidhandle=function(){ 190 | this.handlex=parseInt(this.canvas.width/2); 191 | this.handley=parseInt(this.canvas.height/2); 192 | this.midhandled=true; 193 | } 194 | 195 | this.sethandle=function(x,y){ 196 | this.handlex=x; 197 | this.handley=y; 198 | this.midhandled=false; 199 | } 200 | 201 | this.print=function(dst, str, x, y, alpha, rot, w, h){ 202 | for(var i=0; i y) ? 1 : 0)); 39 | } 40 | 41 | function sortPosy(a, b) { 42 | var x = a.posy; 43 | var y = b.posy; 44 | return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 45 | } 46 | 47 | function scrolltext_horizontal(){ 48 | this.scroffset=0; 49 | this.oldspeed=0; 50 | this.speed=1; 51 | this.font; 52 | this.letters = new Object(); 53 | this.scrtxt=" "; 54 | this.pausetimer=0; 55 | this.pausedelay=0; 56 | 57 | this.init = function(dst, font,speed,sinparam,type){ 58 | this.speed=speed; 59 | this.dst=dst; 60 | this.font=font; 61 | this.fontw = this.font.tilew; 62 | this.fonth = this.font.tileh; 63 | this.fontstart = this.font.tilestart; 64 | this.wide=Math.ceil(this.dst.canvas.width/this.fontw)+1; 65 | for(i=0;i<=this.wide;i++){ 66 | this.letters[i]=new ltrobj(Math.ceil((this.wide*this.fontw)+i*this.fontw),0,this.scrtxt.charCodeAt(this.scroffset)); 67 | this.scroffset++; 68 | } 69 | if(typeof(sinparam)!='undefined') 70 | this.sinparam=sinparam; 71 | if(typeof(type)=='undefined') 72 | this.type=0; 73 | else 74 | this.type=type; 75 | } 76 | 77 | this.draw = function(posy){ 78 | var prov = 0; 79 | var temp = new Array(); 80 | var tmp=this.dst.contex.globalAlpha; 81 | this.dst.contex.globalAlpha=1; 82 | var oldvalue=new Array(); 83 | var i; 84 | if(typeof(this.sinparam)!='undefined'){ 85 | for(var j=0;j this.scrtxt.length-1) 121 | this.scroffset=0; 122 | } 123 | } 124 | } 125 | if(typeof(this.sinparam)!='undefined'){ 126 | for(var j=0;j this.scrtxt.length-1) 241 | this.scroffset=0; 242 | } 243 | } 244 | } 245 | if(typeof(this.sinparam)!='undefined'){ 246 | for(var j=0;j>4; if(this.star[i][0]>this.x<<1) { this.star[i][0]-=this.w<<1; this.test=false; } if(this.star[i][0]<-this.x<<1) { this.star[i][0]+=this.w<<1; this.test=false; } 77 | this.star[i][1]+=(this.centy-this.y)>>4; if(this.star[i][1]>this.y<<1) { this.star[i][1]-=this.h<<1; this.test=false; } if(this.star[i][1]<-this.y<<1) { this.star[i][1]+=this.h<<1; this.test=false; } 78 | this.star[i][2]-=this.star_speed; if(this.star[i][2]>this.z) { this.star[i][2]-=this.z; this.test=false; } if(this.star[i][2]<0) { this.star[i][2]+=this.z; this.test=false; } 79 | this.star[i][3]=this.x+(this.star[i][0]/this.star[i][2])*this.star_ratio; 80 | this.star[i][4]=this.y+(this.star[i][1]/this.star[i][2])*this.star_ratio; 81 | if(this.star_x_save>0&&this.star_x_save0&&this.star_y_savethis.dst.canvas.width) this.stars[i].x=0; 117 | if(this.stars[i].x<0) this.stars[i].x=this.dst.canvas.width; 118 | if(this.stars[i].y>this.dst.canvas.height) this.stars[i].y=0; 119 | if(this.stars[i].y<0) this.stars[i].y=this.dst.canvas.height; 120 | } 121 | } 122 | 123 | } 124 | 125 | function starfield2D_img(dst,img,params){ 126 | this.dst=dst; 127 | this.stars=new Array(); 128 | this.img=img; 129 | var t=0; 130 | 131 | for(var i=0; ithis.dst.canvas.width) this.stars[i].x=0-this.img[this.stars[i].params].img.width; 144 | if(this.stars[i].x<0-this.img[this.stars[i].params].img.width) this.stars[i].x=this.dst.canvas.width; 145 | if(this.stars[i].y>this.dst.canvas.height) this.stars[i].y=0-this.img[this.stars[i].params].img.height; 146 | if(this.stars[i].y<0-this.img[this.stars[i].params].img.height) this.stars[i].y=this.dst.canvas.height; 147 | } 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /codef/codef_stats.js: -------------------------------------------------------------------------------- 1 | // stats.js r6 - http://github.com/mrdoob/stats.js 2 | var Stats=function(){function s(a,g,d){var f,c,e;for(c=0;c<30;c++)for(f=0;f<73;f++)e=(f+c*74)*4,a[e]=a[e+4],a[e+1]=a[e+5],a[e+2]=a[e+6];for(c=0;c<30;c++)e=(73+c*74)*4,c'+n+" MS ("+z+"-"+A+")";o.putImageData(B,0,0);F=j;if(j> 9 | v+1E3){l=Math.round(u*1E3/(j-v));w=Math.min(w,l);x=Math.max(x,l);s(y.data,Math.min(30,30-l/100*30),"fps");d.innerHTML=''+l+" FPS ("+w+"-"+x+")";m.putImageData(y,0,0);if(t==3)p=performance.memory.usedJSHeapSize*9.54E-7,C=Math.min(C,p),D=Math.max(D,p),s(E.data,Math.min(30,30-p/2),"mb"),i.innerHTML=''+Math.round(p)+" MB ("+Math.round(C)+"-"+Math.round(D)+")",q.putImageData(E,0,0);v=j;u=0}}}}; 10 | 11 | var codef_stats = new Stats(); 12 | codef_stats.domElement.style.position = 'absolute'; 13 | codef_stats.domElement.style.top = '0px'; 14 | 15 | function addstats(){ 16 | document.body.appendChild( codef_stats.domElement ); 17 | } 18 | 19 | function updatestats(){ 20 | codef_stats.update(); 21 | } -------------------------------------------------------------------------------- /codef/codef_tween.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author sole / http://soledadpenades.com 3 | * @author mr.doob / http://mrdoob.com 4 | * @author Robert Eisele / http://www.xarg.org 5 | * @author Philippe / http://philippe.elsass.me 6 | * @author Robert Penner / http://www.robertpenner.com/easing_terms_of_use.html 7 | * @author Paul Lewis / http://www.aerotwist.com/ 8 | * @author lechecacharro 9 | * @author Josh Faul / http://jocafa.com/ 10 | */ 11 | 12 | var TWEEN = TWEEN || ( function () { 13 | 14 | var i, tl, interval, time, fps = 60, autostart = false, tweens = []; 15 | 16 | return { 17 | 18 | setFPS: function ( f ) { 19 | 20 | fps = f || 60; 21 | 22 | }, 23 | 24 | start: function ( f ) { 25 | 26 | if( arguments.length != 0 ) { 27 | this.setFPS( f ); 28 | } 29 | 30 | interval = setInterval( this.update, 1000 / fps ); 31 | 32 | }, 33 | 34 | stop: function () { 35 | 36 | clearInterval( interval ); 37 | 38 | }, 39 | 40 | setAutostart: function ( value ) { 41 | 42 | autostart = value; 43 | 44 | if(autostart && !interval) { 45 | this.start(); 46 | } 47 | 48 | }, 49 | 50 | add: function ( tween ) { 51 | 52 | tweens.push( tween ); 53 | 54 | if (autostart && !interval) { 55 | 56 | this.start(); 57 | 58 | } 59 | 60 | }, 61 | 62 | getAll: function() { 63 | 64 | return tweens; 65 | 66 | }, 67 | 68 | removeAll: function() { 69 | 70 | tweens = []; 71 | 72 | }, 73 | 74 | remove: function ( tween ) { 75 | 76 | i = tweens.indexOf( tween ); 77 | 78 | if ( i !== -1 ) { 79 | 80 | tweens.splice( i, 1 ); 81 | 82 | } 83 | 84 | }, 85 | 86 | update: function (_time) { 87 | 88 | i = 0; num_tweens = tweens.length; 89 | var time = _time || Date.now(); 90 | 91 | while ( i < num_tweens ) { 92 | 93 | if ( tweens[ i ].update( time ) ) { 94 | 95 | i++; 96 | 97 | } else { 98 | 99 | tweens.splice( i, 1 ); 100 | num_tweens--; 101 | 102 | } 103 | 104 | } 105 | 106 | if (num_tweens == 0 && autostart == true) { 107 | 108 | this.stop(); 109 | 110 | } 111 | 112 | } 113 | 114 | }; 115 | 116 | } )(); 117 | 118 | TWEEN.Tween = function ( object ) { 119 | 120 | var _object = object, 121 | _valuesStart = {}, 122 | _valuesDelta = {}, 123 | _valuesEnd = {}, 124 | _duration = 1000, 125 | _delayTime = 0, 126 | _startTime = null, 127 | _easingFunction = TWEEN.Easing.Linear.EaseNone, 128 | _chainedTween = null, 129 | _onUpdateCallback = null, 130 | _onCompleteCallback = null; 131 | 132 | this.to = function ( properties, duration ) { 133 | 134 | if( duration !== null ) { 135 | 136 | _duration = duration; 137 | 138 | } 139 | 140 | for ( var property in properties ) { 141 | 142 | // This prevents the engine from interpolating null values 143 | if ( _object[ property ] === null ) { 144 | 145 | continue; 146 | 147 | } 148 | 149 | // The current values are read when the tween starts; 150 | // here we only store the final desired values 151 | _valuesEnd[ property ] = properties[ property ]; 152 | 153 | } 154 | 155 | return this; 156 | 157 | }; 158 | 159 | this.start = function (_time) { 160 | 161 | TWEEN.add( this ); 162 | 163 | _startTime = _time ? _time + _delayTime : Date.now() + _delayTime; 164 | 165 | for ( var property in _valuesEnd ) { 166 | 167 | // Again, prevent dealing with null values 168 | if ( _object[ property ] === null ) { 169 | 170 | continue; 171 | 172 | } 173 | 174 | _valuesStart[ property ] = _object[ property ]; 175 | _valuesDelta[ property ] = _valuesEnd[ property ] - _object[ property ]; 176 | 177 | } 178 | 179 | return this; 180 | }; 181 | 182 | this.stop = function () { 183 | 184 | TWEEN.remove( this ); 185 | return this; 186 | 187 | }; 188 | 189 | this.delay = function ( amount ) { 190 | 191 | _delayTime = amount; 192 | return this; 193 | 194 | }; 195 | 196 | this.easing = function ( easing ) { 197 | 198 | _easingFunction = easing; 199 | return this; 200 | 201 | }; 202 | 203 | this.chain = function ( chainedTween ) { 204 | 205 | _chainedTween = chainedTween; 206 | 207 | }; 208 | 209 | this.onUpdate = function ( onUpdateCallback ) { 210 | 211 | _onUpdateCallback = onUpdateCallback; 212 | return this; 213 | 214 | }; 215 | 216 | this.onComplete = function ( onCompleteCallback ) { 217 | 218 | _onCompleteCallback = onCompleteCallback; 219 | return this; 220 | 221 | }; 222 | 223 | this.update = function ( time ) { 224 | 225 | var property, elapsed, value; 226 | 227 | if ( time < _startTime ) { 228 | 229 | return true; 230 | 231 | } 232 | 233 | elapsed = ( time - _startTime ) / _duration; 234 | elapsed = elapsed > 1 ? 1 : elapsed; 235 | 236 | value = _easingFunction( elapsed ); 237 | 238 | for ( property in _valuesDelta ) { 239 | 240 | _object[ property ] = _valuesStart[ property ] + _valuesDelta[ property ] * value; 241 | 242 | } 243 | 244 | if ( _onUpdateCallback !== null ) { 245 | 246 | _onUpdateCallback.call( _object, value ); 247 | 248 | } 249 | 250 | if ( elapsed == 1 ) { 251 | 252 | if ( _onCompleteCallback !== null ) { 253 | 254 | _onCompleteCallback.call( _object ); 255 | 256 | } 257 | 258 | if ( _chainedTween !== null ) { 259 | 260 | _chainedTween.start(); 261 | 262 | } 263 | 264 | return false; 265 | 266 | } 267 | 268 | return true; 269 | 270 | }; 271 | 272 | /* 273 | this.destroy = function () { 274 | 275 | TWEEN.remove( this ); 276 | 277 | }; 278 | */ 279 | } 280 | 281 | TWEEN.Easing = { Linear: {}, Quadratic: {}, Cubic: {}, Quartic: {}, Quintic: {}, Sinusoidal: {}, Exponential: {}, Circular: {}, Elastic: {}, Back: {}, Bounce: {} }; 282 | 283 | 284 | TWEEN.Easing.Linear.EaseNone = function ( k ) { 285 | 286 | return k; 287 | 288 | }; 289 | 290 | // 291 | 292 | TWEEN.Easing.Quadratic.EaseIn = function ( k ) { 293 | 294 | return k * k; 295 | 296 | }; 297 | 298 | TWEEN.Easing.Quadratic.EaseOut = function ( k ) { 299 | 300 | return - k * ( k - 2 ); 301 | 302 | }; 303 | 304 | TWEEN.Easing.Quadratic.EaseInOut = function ( k ) { 305 | 306 | if ( ( k *= 2 ) < 1 ) return 0.5 * k * k; 307 | return - 0.5 * ( --k * ( k - 2 ) - 1 ); 308 | 309 | }; 310 | 311 | // 312 | 313 | TWEEN.Easing.Cubic.EaseIn = function ( k ) { 314 | 315 | return k * k * k; 316 | 317 | }; 318 | 319 | TWEEN.Easing.Cubic.EaseOut = function ( k ) { 320 | 321 | return --k * k * k + 1; 322 | 323 | }; 324 | 325 | TWEEN.Easing.Cubic.EaseInOut = function ( k ) { 326 | 327 | if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k; 328 | return 0.5 * ( ( k -= 2 ) * k * k + 2 ); 329 | 330 | }; 331 | 332 | // 333 | 334 | TWEEN.Easing.Quartic.EaseIn = function ( k ) { 335 | 336 | return k * k * k * k; 337 | 338 | }; 339 | 340 | TWEEN.Easing.Quartic.EaseOut = function ( k ) { 341 | 342 | return - ( --k * k * k * k - 1 ); 343 | 344 | } 345 | 346 | TWEEN.Easing.Quartic.EaseInOut = function ( k ) { 347 | 348 | if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k; 349 | return - 0.5 * ( ( k -= 2 ) * k * k * k - 2 ); 350 | 351 | }; 352 | 353 | // 354 | 355 | TWEEN.Easing.Quintic.EaseIn = function ( k ) { 356 | 357 | return k * k * k * k * k; 358 | 359 | }; 360 | 361 | TWEEN.Easing.Quintic.EaseOut = function ( k ) { 362 | 363 | return ( k = k - 1 ) * k * k * k * k + 1; 364 | 365 | }; 366 | 367 | TWEEN.Easing.Quintic.EaseInOut = function ( k ) { 368 | 369 | if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k; 370 | return 0.5 * ( ( k -= 2 ) * k * k * k * k + 2 ); 371 | 372 | }; 373 | 374 | // 375 | 376 | TWEEN.Easing.Sinusoidal.EaseIn = function ( k ) { 377 | 378 | return - Math.cos( k * Math.PI / 2 ) + 1; 379 | 380 | }; 381 | 382 | TWEEN.Easing.Sinusoidal.EaseOut = function ( k ) { 383 | 384 | return Math.sin( k * Math.PI / 2 ); 385 | 386 | }; 387 | 388 | TWEEN.Easing.Sinusoidal.EaseInOut = function ( k ) { 389 | 390 | return - 0.5 * ( Math.cos( Math.PI * k ) - 1 ); 391 | 392 | }; 393 | 394 | // 395 | 396 | TWEEN.Easing.Exponential.EaseIn = function ( k ) { 397 | 398 | return k == 0 ? 0 : Math.pow( 2, 10 * ( k - 1 ) ); 399 | 400 | }; 401 | 402 | TWEEN.Easing.Exponential.EaseOut = function ( k ) { 403 | 404 | return k == 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1; 405 | 406 | }; 407 | 408 | TWEEN.Easing.Exponential.EaseInOut = function ( k ) { 409 | 410 | if ( k == 0 ) return 0; 411 | if ( k == 1 ) return 1; 412 | if ( ( k *= 2 ) < 1 ) return 0.5 * Math.pow( 2, 10 * ( k - 1 ) ); 413 | return 0.5 * ( - Math.pow( 2, - 10 * ( k - 1 ) ) + 2 ); 414 | 415 | }; 416 | 417 | // 418 | 419 | TWEEN.Easing.Circular.EaseIn = function ( k ) { 420 | 421 | return - ( Math.sqrt( 1 - k * k ) - 1); 422 | 423 | }; 424 | 425 | TWEEN.Easing.Circular.EaseOut = function ( k ) { 426 | 427 | return Math.sqrt( 1 - --k * k ); 428 | 429 | }; 430 | 431 | TWEEN.Easing.Circular.EaseInOut = function ( k ) { 432 | 433 | if ( ( k /= 0.5 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1); 434 | return 0.5 * ( Math.sqrt( 1 - ( k -= 2) * k) + 1); 435 | 436 | }; 437 | 438 | // 439 | 440 | TWEEN.Easing.Elastic.EaseIn = function( k ) { 441 | 442 | var s, a = 0.1, p = 0.4; 443 | if ( k == 0 ) return 0; if ( k == 1 ) return 1; if ( !p ) p = 0.3; 444 | if ( !a || a < 1 ) { a = 1; s = p / 4; } 445 | else s = p / ( 2 * Math.PI ) * Math.asin( 1 / a ); 446 | return - ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) ); 447 | 448 | }; 449 | 450 | TWEEN.Easing.Elastic.EaseOut = function( k ) { 451 | 452 | var s, a = 0.1, p = 0.4; 453 | if ( k == 0 ) return 0; if ( k == 1 ) return 1; if ( !p ) p = 0.3; 454 | if ( !a || a < 1 ) { a = 1; s = p / 4; } 455 | else s = p / ( 2 * Math.PI ) * Math.asin( 1 / a ); 456 | return ( a * Math.pow( 2, - 10 * k) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) + 1 ); 457 | 458 | }; 459 | 460 | TWEEN.Easing.Elastic.EaseInOut = function( k ) { 461 | 462 | var s, a = 0.1, p = 0.4; 463 | if ( k == 0 ) return 0; if ( k == 1 ) return 1; if ( !p ) p = 0.3; 464 | if ( !a || a < 1 ) { a = 1; s = p / 4; } 465 | else s = p / ( 2 * Math.PI ) * Math.asin( 1 / a ); 466 | if ( ( k *= 2 ) < 1 ) return - 0.5 * ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) ); 467 | return a * Math.pow( 2, -10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) * 0.5 + 1; 468 | 469 | }; 470 | 471 | // 472 | 473 | TWEEN.Easing.Back.EaseIn = function( k ) { 474 | 475 | var s = 1.70158; 476 | return k * k * ( ( s + 1 ) * k - s ); 477 | 478 | }; 479 | 480 | TWEEN.Easing.Back.EaseOut = function( k ) { 481 | 482 | var s = 1.70158; 483 | return ( k = k - 1 ) * k * ( ( s + 1 ) * k + s ) + 1; 484 | 485 | }; 486 | 487 | TWEEN.Easing.Back.EaseInOut = function( k ) { 488 | 489 | var s = 1.70158 * 1.525; 490 | if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) ); 491 | return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 ); 492 | 493 | }; 494 | 495 | // 496 | 497 | TWEEN.Easing.Bounce.EaseIn = function( k ) { 498 | 499 | return 1 - TWEEN.Easing.Bounce.EaseOut( 1 - k ); 500 | 501 | }; 502 | 503 | TWEEN.Easing.Bounce.EaseOut = function( k ) { 504 | 505 | if ( ( k /= 1 ) < ( 1 / 2.75 ) ) { 506 | 507 | return 7.5625 * k * k; 508 | 509 | } else if ( k < ( 2 / 2.75 ) ) { 510 | 511 | return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75; 512 | 513 | } else if ( k < ( 2.5 / 2.75 ) ) { 514 | 515 | return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375; 516 | 517 | } else { 518 | 519 | return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375; 520 | 521 | } 522 | 523 | }; 524 | 525 | TWEEN.Easing.Bounce.EaseInOut = function( k ) { 526 | 527 | if ( k < 0.5 ) return TWEEN.Easing.Bounce.EaseIn( k * 2 ) * 0.5; 528 | return TWEEN.Easing.Bounce.EaseOut( k * 2 - 1 ) * 0.5 + 0.5; 529 | 530 | }; --------------------------------------------------------------------------------