artistic-engine
Version:
General purpose html5 canvas rendering game engine
1 lines • 3.5 kB
JavaScript
var t={d:(e,s)=>{for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{Zx:()=>r,WI:()=>o,Dg:()=>s,e1:()=>i});class s{constructor(t,e,s,r,i){if(this.startTime=0,this.elapsedTime=0,Number.isNaN(t)||Math.abs(t)===1/0)throw new Error(t+"is not a valid parameter for 'from' parameter.");if(Number.isNaN(e)||Math.abs(e)===1/0)throw new Error(e+"is not a valid parameter for 'to' parameter.");if(Number.isNaN(s)||s===1/0||s<=0)throw new Error(s+"is not a valid parameter for 'duration' parameter.");this.from=t,this.diff=e-t,this.duration=s,this.modifyFunction=r,this.easeFunction=i??(t=>t)}get Progress(){return this.elapsedTime/this.duration}get Duration(){return this.duration}get StartTime(){return this.startTime}get EndTime(){return this.startTime+this.duration}register(t=0){this.startTime=performance.now()+t,this.elapsedTime=0}tick(){this.elapsedTime=performance.now()-this.startTime;const t=Math.min(this.Progress,1);this.modify(this.from+this.easeFunction(t)*this.diff)}modify(t){this.modifyFunction(t)}}class r extends s{constructor(...t){let e=0;for(const s of t)e=Math.max(s.Duration);super(0,1,e,(()=>{if(0===this.modifiers.length)return;let t=[];for(let e=0;e<this.modifiers.length;e++){const s=this.modifiers[e];s.tick(),s.Progress>=1&&t.push(e)}t=t.reverse();for(const e of t)this.modifiers.splice(e,1)})),this.modifiers=t}get Progress(){return 0===this.duration?1:0===this.modifiers.length?super.Progress:.9999999999999999}register(t=0){super.register(t);for(const t of this.modifiers)t.register()}}class i extends s{constructor(...t){let e=0;for(const s of t)e+=s.Duration;super(0,1,e,(()=>{if(0===this.modifiers.length)return;const t=this.modifiers[0];t.tick(),t.Progress>=1&&(this.modifiers.shift(),this.modifiers.length>0&&this.modifiers[0].register(performance.now()-t.EndTime))})),this.modifiers=t}get Progress(){if(0===this.duration)return 1;const t=super.Progress;return 1===this.modifiers.length&&t>=1?.9999999999999999:t}register(t=0){super.register(t),this.modifiers[0].register()}}const a=t=>{const e=2.75,s=2.75*t;return 7.5625*(s<1?t*t:s<2?(t-=1.5/e)*t+.75:s<2.5?(t-=2.25/e)*t+.9375:(t-=2.625/e)*t+.984375)},o={EaseInSine:t=>1-Math.cos(t*Math.PI/2),EaseOutSine:t=>Math.sin(t*Math.PI/2),EaseInOutSine:t=>-(Math.cos(Math.PI*t)-1)/2,EaseInExpo:t=>0===t?0:Math.pow(2,10*t-10),EaseOutExpo:t=>1===t?1:1-Math.pow(2,-10*t),EaseInOutExpo:t=>0===t?0:1===t?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2,EaseInCirc:t=>1-Math.sqrt(1-Math.pow(t,2)),EaseOutCirc:t=>Math.sqrt(1-Math.pow(t-1,2)),EaseInOutCirc:t=>t<.5?(1-Math.sqrt(1-Math.pow(2*t,2)))/2:(Math.sqrt(1-Math.pow(-2*t+2,2))+1)/2,EaseInBack:t=>Math.pow(t,2)*(2.70158*t-1.70158),EaseOutBack:t=>1+Math.pow(t-1,2)*(2.70158*(t-1)+1.70158),EaseInOutBack:t=>(t<.5?Math.pow(2*t,2)*(7.189819*t-2.5949095):Math.pow(2*t-2,2)*(3.5949095*(2*t-2)+2.5949095)+2)/2,EaseInElastic:t=>0===t?0:1===t?1:-Math.pow(2,10*t-10)*Math.sin((10*t-10.75)*(2*Math.PI)/3),EaseOutElastic:t=>0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin((10*t-.75)*(2*Math.PI)/3)+1,EaseInOutElastic:t=>0===t?0:1===t?1:t<.5?-Math.pow(2,20*t-10)*Math.sin((20*t-11.125)*(2*Math.PI)/4.5)/2:Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*(2*Math.PI)/4.5)/2+1,EaseInBounce:t=>1-a(1-t),EaseOutBounce:a,EaseInOutBounce:t=>t<.5?(1-a(1-2*t))/2:(1+a(2*t-1))/2};var n=e.Zx,h=e.WI,u=e.Dg,f=e.e1;export{n as ConcurrentModifier,h as EaseFunctions,u as Modifier,f as SequentialModifier};