@litecanvas/utils 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/actor.js +3 -3
- package/dist/actor.min.js +1 -1
- package/dist/all.js +27 -7
- package/dist/all.min.js +2 -2
- package/dist/grid.js +3 -3
- package/dist/image.min.js +1 -1
- package/dist/math.js +25 -3
- package/dist/math.min.js +1 -1
- package/dist/noise.js +3 -3
- package/dist/noise.min.js +1 -1
- package/dist/tween.js +3 -3
- package/dist/tween.min.js +1 -1
- package/dist/vector.js +5 -7
- package/dist/vector.min.js +1 -1
- package/package.json +4 -4
- package/src/actor/README.md +9 -9
- package/src/camera/README.md +7 -3
- package/src/math/dist.js +12 -0
- package/src/math/index.js +3 -0
- package/src/math/mag.js +10 -0
- package/src/math/round.js +14 -0
- package/src/vector/index.js +2 -4
package/README.md
CHANGED
|
@@ -50,4 +50,5 @@ const pos = vec(0, 0)
|
|
|
50
50
|
- **Grid**: class to handle retangular grid areas. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/grid)
|
|
51
51
|
- **Collision** utilities. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/collision)
|
|
52
52
|
- **Tween** to create animations. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/tween)
|
|
53
|
+
- **Image** to manipulate images. [Usage & Docs](https://github.com/litecanvas/utils/tree/main/src/image)
|
|
53
54
|
- And some [math utilities](https://github.com/litecanvas/utils/tree/main/src/math)...
|
package/dist/actor.js
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// src/actor/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
20
|
ANCHOR_BOT_LEFT: () => ANCHOR_BOT_LEFT,
|
|
21
21
|
ANCHOR_BOT_RIGHT: () => ANCHOR_BOT_RIGHT,
|
|
22
22
|
ANCHOR_CENTER: () => ANCHOR_CENTER,
|
|
@@ -213,5 +213,5 @@
|
|
|
213
213
|
};
|
|
214
214
|
|
|
215
215
|
// src/actor/_web.js
|
|
216
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
216
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
217
217
|
})();
|
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var c=Object.defineProperty;var l=(r,t)=>{for(var e in t)c(r,e,{get:t[e],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let r in globalThis.utils)r!=="global"&&(globalThis[r]=globalThis.utils[r])};var m={};l(m,{ANCHOR_BOT_LEFT:()=>d,ANCHOR_BOT_RIGHT:()=>D,ANCHOR_CENTER:()=>b,ANCHOR_TOP_LEFT:()=>p,ANCHOR_TOP_RIGHT:()=>h,Actor:()=>u});var _=2*Math.PI,n=class{x;y;constructor(t=0,e=t){this.x=t,this.y=e}toString(){return`Vector (${this.x}, ${this.y})`}},f=r=>r instanceof n,s=(r=0,t=r)=>(f(r)&&(t=r.y,r=r.x),new n(r,t));var b=s(.5,.5),p=s(0,0),h=s(1,0),d=s(0,1),D=s(1,1),u=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,e,a=p){this.sprite=t,this.pos=e||s(0),this._o=s(a),this._s=s(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,e=t){this._s.x=t,this._s.y=e}scaleBy(t,e=t){this._s.x*=t,this._s.y*=e}getBounds(t=!0){let e=this.sprite.width*(t?this._s.x:1),a=this.sprite.height*(t?this._s.y:1),i=this.pos.x-e*this.anchor.x,o=this.pos.y-a*this.anchor.y;return[i,o,e,a]}draw(t=globalThis,e=!0){this.hidden||this.opacity<=0||(e&&t.push(),this.transform(t),this.drawImage(t),e&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,e=!0){let a=this.anchor,i=-this.sprite.width*(this.flipX?1-a.x:a.x),o=-this.sprite.height*(this.flipY?1-a.y:a.y);e&&t.alpha(this.opacity),t.image(i,o,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},m);})();
|
package/dist/all.js
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// src/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
20
|
ANCHOR_BOT_LEFT: () => ANCHOR_BOT_LEFT,
|
|
21
21
|
ANCHOR_BOT_RIGHT: () => ANCHOR_BOT_RIGHT,
|
|
22
22
|
ANCHOR_CENTER: () => ANCHOR_CENTER,
|
|
@@ -49,12 +49,15 @@
|
|
|
49
49
|
ZERO: () => ZERO,
|
|
50
50
|
advance: () => advance_default,
|
|
51
51
|
diff: () => diff_default,
|
|
52
|
+
dist: () => dist_default,
|
|
52
53
|
flipImage: () => flip_default,
|
|
53
54
|
fract: () => fract_default,
|
|
54
55
|
intersection: () => intersection_default,
|
|
56
|
+
mag: () => mag_default,
|
|
55
57
|
mod: () => mod_default,
|
|
56
58
|
range: () => range_default,
|
|
57
59
|
resolve: () => resolve_default,
|
|
60
|
+
round: () => round_default,
|
|
58
61
|
scaleImage: () => scale_default,
|
|
59
62
|
tint: () => tint_default,
|
|
60
63
|
tween: () => tween,
|
|
@@ -655,7 +658,7 @@
|
|
|
655
658
|
vecMult(v, value);
|
|
656
659
|
return v;
|
|
657
660
|
};
|
|
658
|
-
var vecMag = (v) =>
|
|
661
|
+
var vecMag = (v) => Math.hypot(v.x, v.y);
|
|
659
662
|
var vecMag2 = (v) => v.x * v.x + v.y * v.y;
|
|
660
663
|
var vecNorm = (v) => {
|
|
661
664
|
const length = vecMag(v);
|
|
@@ -673,9 +676,7 @@
|
|
|
673
676
|
return v;
|
|
674
677
|
};
|
|
675
678
|
var vecDist = (a, b) => {
|
|
676
|
-
|
|
677
|
-
const dy = a.y - b.y;
|
|
678
|
-
return sqrt(dx * dx + dy * dy);
|
|
679
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
679
680
|
};
|
|
680
681
|
var vecDist2 = (a, b) => {
|
|
681
682
|
const dx = a.x - b.x;
|
|
@@ -913,6 +914,25 @@
|
|
|
913
914
|
// src/math/mod.js
|
|
914
915
|
var mod_default = (a, b) => (b + a % b) % b;
|
|
915
916
|
|
|
917
|
+
// src/math/round.js
|
|
918
|
+
var round_default = (n, decimals) => {
|
|
919
|
+
if (!decimals) {
|
|
920
|
+
return Math.round(n);
|
|
921
|
+
}
|
|
922
|
+
const multiplier = Math.pow(10, decimals);
|
|
923
|
+
return Math.round(n * multiplier) / multiplier;
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
// src/math/dist.js
|
|
927
|
+
var dist_default = (x1, y1, x2, y2) => {
|
|
928
|
+
return Math.hypot(x2 - x1, y2 - y1);
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
// src/math/mag.js
|
|
932
|
+
var mag_default = (x, y) => {
|
|
933
|
+
return Math.hypot(x, y);
|
|
934
|
+
};
|
|
935
|
+
|
|
916
936
|
// src/tween/index.js
|
|
917
937
|
var HALF_PI = Math.PI / 2;
|
|
918
938
|
var tween = (object, prop, toValue, duration = 1, easing = LINEAR) => {
|
|
@@ -1296,6 +1316,6 @@
|
|
|
1296
1316
|
};
|
|
1297
1317
|
|
|
1298
1318
|
// src/_web.js
|
|
1299
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
1319
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
1300
1320
|
})();
|
|
1301
1321
|
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/all.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`)}},
|
|
1
|
+
(()=>{var mt=Object.defineProperty;var ft=(e,t)=>{for(var r in t)mt(e,r,{get:t[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var X={};ft(X,{ANCHOR_BOT_LEFT:()=>Wt,ANCHOR_BOT_RIGHT:()=>zt,ANCHOR_CENTER:()=>Yt,ANCHOR_TOP_LEFT:()=>K,ANCHOR_TOP_RIGHT:()=>Nt,Actor:()=>O,BACK_IN:()=>$t,BACK_IN_OUT:()=>Kt,BACK_OUT:()=>Zt,BOUNCE_IN:()=>ot,BOUNCE_IN_OUT:()=>te,BOUNCE_OUT:()=>C,Camera:()=>D,DOWN:()=>Rt,EASE_IN:()=>jt,EASE_IN_OUT:()=>qt,EASE_OUT:()=>Gt,ELASTIC_IN:()=>Jt,ELASTIC_IN_OUT:()=>vt,ELASTIC_OUT:()=>Qt,Grid:()=>T,LEFT:()=>Xt,LINEAR:()=>nt,Noise:()=>R,ONE:()=>kt,RIGHT:()=>St,TypedGrid:()=>B,UP:()=>Ct,Vector:()=>y,ZERO:()=>Z,advance:()=>et,diff:()=>J,dist:()=>at,flipImage:()=>pt,fract:()=>v,intersection:()=>w,mag:()=>it,mod:()=>rt,range:()=>tt,resolve:()=>N,round:()=>st,scaleImage:()=>ct,tint:()=>lt,tween:()=>Ft,vec:()=>n,vecAbs:()=>Ut,vecAdd:()=>A,vecAngle:()=>It,vecAngleBetween:()=>wt,vecCeil:()=>Bt,vecClamp:()=>Pt,vecCross:()=>Tt,vecDist:()=>yt,vecDist2:()=>Et,vecDiv:()=>L,vecDot:()=>$,vecEq:()=>V,vecFloor:()=>Vt,vecIsZero:()=>Ot,vecLerp:()=>Lt,vecLimit:()=>Dt,vecMag:()=>G,vecMag2:()=>q,vecMove:()=>Ht,vecMult:()=>E,vecNorm:()=>H,vecRand:()=>Mt,vecReflect:()=>xt,vecRotate:()=>dt,vecRound:()=>At,vecSet:()=>j,vecSetMag:()=>gt,vecSub:()=>P,wave:()=>Q});var w=(e,t,r,s,a,i,o,h)=>{let u=Math.max(e,a),b=Math.min(e+r,a+o)-u,c=Math.max(t,i),d=Math.min(t+s,i+h)-c;return[u,c,b,d]};var N=(e,t,r,s,a,i,o,h)=>{let[u,b,c,d]=w(e,t,r,s,a,i,o,h),_="",g=e,l=t;return c<d?e<a?(_="right",g=a-r):(_="left",g=a+o):t<i?(_="bottom",l=i-s):(_="top",l=i+h),{direction:_,x:g,y:l}};var D=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,r=0,s=0,a=null,i=null){this._engine=t||globalThis,this.ox=r,this.oy=s,this.resize(a||this._engine.WIDTH-r,i||this._engine.HEIGHT-s),this.x=this.width/2,this.y=this.height/2}resize(t,r){this.width=t,this.height=r,this._engine.emit("camera-resized",this)}start(t=!1){if(this._engine.push(),t){let a=path();a.rect(this.ox,this.oy,this.width,this.height),this._engine.clip(a)}let r=this.ox+this.width/2,s=this.oy+this.height/2;this._engine.translate(r,s),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,r){this.x=t,this.y=r}move(t,r){this.x+=t,this.y+=r}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,r=(r-this.height/2-this.oy)/this.scale,s.x=a*t-i*r+this.x,s.y=i*t+a*r+this.y,s}getCameraPoint(t,r,s={}){let a=Math.cos(-this.rotation),i=Math.sin(-this.rotation);return t=t-this.x,r=r-this.y,t=a*t-i*r,r=i*t+a*r,s.x=t*this.scale+this.width/2+this.ox,s.y=r*this.scale+this.height/2+this.oy,s}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,r,s,a){let i=this.width/2-this.x,o=this.height/2-this.y,h=this.width/this.scale,u=this.height/this.scale;return this._engine.colrect(t,r,s,a,i,o,h,u)}shake(t=1,r=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",s=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),r-=s,r<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var T=class e{_w;_h;_c;constructor(t,r,s=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~r),this._c=s}[Symbol.iterator](){let t=0;return{next:()=>({value:[this.indexToPointX(t),this.indexToPointY(t),this._c[t++]],done:t>this._c.length})}}clone(){return new e(this._w,this._h,this._c)}clear(){this.forEach((t,r)=>this.set(t,r,void 0))}get width(){return this._w}get height(){return this._h}set(t,r,s){this._c[this.pointToIndex(t,r)]=s}get(t,r){return this._c[this.pointToIndex(t,r)]}has(t,r){return this.get(t,r)!=null}check(t,r){return t>=0&&t<this._w&&r>=0&&r<this._h}get length(){return this._w*this._h}pointToIndex(t,r){return this.clampX(~~t)+this.clampY(~~r)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,r=!1){let s=r?this.length-1:0,a=r?-1:this.length,i=r?-1:1;for(;s!==a;){let o=this.indexToPointX(s),h=this.indexToPointY(s),u=this._c[s];if(t(o,h,u,this)===!1)break;s+=i}}fill(t){this.forEach((r,s)=>{this.set(r,s,t)})}clampX(t){return W(t,0,this._w-1)}clampY(t){return W(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",r=!0){if(!r)return this._c.join(t);let s=[];return this.forEach((a,i,o)=>{s[i]=s[i]||"",s[i]+=o+t}),s.join(`
|
|
2
|
+
`)}},B=class e extends T{constructor(t,r,s=Uint8Array){super(t,r,null),this._c=new s(this._w*this._h)}has(t,r){return this.get(t,r)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((r,s,a)=>{t.set(r,s,a)}),t}};function W(e,t,r){return e<t?t:e>r?r:e}var _t=Math.sqrt,z=Math.cos,F=Math.sin,bt=2*Math.PI,y=class{x;y;constructor(t=0,r=t){this.x=t,this.y=r}toString(){return`Vector (${this.x}, ${this.y})`}},x=e=>e instanceof y,n=(e=0,t=e)=>(x(e)&&(t=e.y,e=e.x),new y(e,t)),V=(e,t,r=t)=>x(t)?V(e,t.x,t.y):e.x===t&&e.y===r,j=(e,t,r=t)=>(x(t)?j(e,t.x,t.y):(e.x=t,e.y=r),e),A=(e,t,r=t)=>x(t)?A(e,t.x,t.y):(e.x+=t,e.y+=r,e),P=(e,t,r=t)=>x(t)?P(e,t.x,t.y):(e.x-=t,e.y-=r,e),E=(e,t,r=t)=>x(t)?E(e,t.x,t.y):(e.x*=t,e.y*=r,e),L=(e,t,r=t)=>x(t)?L(e,t.x,t.y):(e.x/=t||1,e.y/=r||1,e),dt=(e,t)=>{let r=z(t),s=F(t);return e.x=r*e.x-s*e.y,e.y=s*e.x+r*e.y,e},xt=(e,t)=>{let r=H(n(t));return P(e,E(r,2*$(e,r)))},gt=(e,t)=>(H(e),E(e,t),e),G=e=>Math.hypot(e.x,e.y),q=e=>e.x*e.x+e.y*e.y,H=e=>{let t=G(e);return t>0&&L(e,t),e},Dt=(e,t=1)=>{let r=q(e);return r>t*t&&(L(e,_t(r)),E(e,t)),e},yt=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),Et=(e,t)=>{let r=e.x-t.x,s=e.y-t.y;return r*r+s*s},It=e=>Math.atan2(e.y,e.x),wt=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),$=(e,t)=>e.x*t.x+e.y*t.y,Tt=(e,t)=>e.x*t.y-e.y*t.x,Lt=(e,t,r)=>(e.x+=(t.x-e.x)*r||0,e.y+=(t.y-e.y)*r||0,e),Mt=(e=1,t=e,r=globalThis.rand||Math.random)=>{let s=r()*bt,a=r()*(t-e)+e;return n(z(s)*a,F(s)*a)},Ut=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),Bt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),Vt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),At=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),Pt=(e,t,r)=>(e.x<t.x&&(e.x=t.x),e.x>r.x&&(e.x=r.x),e.y<t.y&&(e.y=t.y),e.y>r.y&&(e.y=r.y),e),Ht=(e,t,r=1)=>A(e,t.x*r,t.y*r),Ot=e=>V(e,Z),Z=n(0,0),kt=n(1,1),Ct=n(0,-1),St=n(1,0),Rt=n(0,1),Xt=n(-1,0);var Yt=n(.5,.5),K=n(0,0),Nt=n(1,0),Wt=n(0,1),zt=n(1,1),O=class{sprite;pos;_o;_s;flipX=!1;flipY=!1;angle=0;opacity=1;hidden=!1;constructor(t,r,s=K){this.sprite=t,this.pos=r||n(0),this._o=n(s),this._s=n(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}scaleTo(t,r=t){this._s.x=t,this._s.y=r}scaleBy(t,r=t){this._s.x*=t,this._s.y*=r}getBounds(t=!0){let r=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),a=this.pos.x-r*this.anchor.x,i=this.pos.y-s*this.anchor.y;return[a,i,r,s]}draw(t=globalThis,r=!0){this.hidden||this.opacity<=0||(r&&t.push(),this.transform(t),this.drawImage(t),r&&t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(t.deg2rad(this.angle)),t.scale((this.flipX?-1:1)*this._s.x,(this.flipY?-1:1)*this._s.y)}drawImage(t,r=!0){let s=this.anchor,a=-this.sprite.width*(this.flipX?1-s.x:s.x),i=-this.sprite.height*(this.flipY?1-s.y:s.y);r&&t.alpha(this.opacity),t.image(a,i,this.sprite)}};var J=(e,t)=>Math.abs(t-e)||0;var Q=(e,t,r,s=Math.sin)=>e+(s(r)+1)/2*(t-e);var v=e=>e%1||0;var tt=e=>Array.from(Array(e).keys());var et=advance=(e,t,r,s=1)=>{r&&(t.x+=r.x*s,t.y+=r.y*s),e.x+=t.x*s,e.y+=t.y*s};var rt=(e,t)=>(t+e%t)%t;var st=(e,t)=>{if(!t)return Math.round(e);let r=Math.pow(10,t);return Math.round(e*r)/r};var at=(e,t,r,s)=>Math.hypot(r-e,s-t);var it=(e,t)=>Math.hypot(e,t);var M=Math.PI/2,Ft=(e,t,r,s=1,a=nt)=>new k(e,t,r,s,a),nt=e=>e,jt=e=>e*e,Gt=e=>-e*(e-2),qt=e=>e<.5?2*e*e:-2*e*e+4*e-1,$t=e=>e*e*e-e*Math.sin(e*Math.PI),Zt=e=>{let t=1-e;return 1-(t*t*t-t*Math.sin(t*Math.PI))},Kt=e=>{if(e<.5){let r=2*e;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let t=1-(2*e-1);return .5*(1-(t*t*t-t*Math.sin(e*Math.PI)))+.5},Jt=e=>Math.sin(13*M*e)*Math.pow(2,10*(e-1)),Qt=e=>Math.sin(-13*M*(e+1))*Math.pow(2,-10*e)+1,vt=e=>{if(e<.5){let s=Math.sin(13*M*(2*e)),a=Math.pow(2,10*(2*e-1));return .5*s*a}let t=Math.sin(-13*M*(2*e-1+1)),r=Math.pow(2,-10*(2*e-1));return .5*(t*r+2)},ot=e=>1-C(1-e),C=e=>e<4/11?121*e*e/16:e<8/11?363/40*e*e-99/10*e+17/5:e<9/10?4356/361*e*e-35442/1805*e+16061/1805:54/5*e*e-513/25*e+268/25,te=e=>e<.5?.5*ot(e*2):.5*C(e*2-1)+.5,k=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(t,r,s,a,i){this._o=t,this._p=r,this._x=s,this._d=a,this._e=i,this._w=0}start(t){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,s=this._rel?r+this._x:this._x;return this._lc=this._lc||t||globalThis,this._u=this._lc.listen("update",a=>{if(this._t<=this._w){this._t+=a;return}let i=this._t-this._w;this._o[this._p]=this._lc.lerp(r,s,this._e(i/this._d)),this._t+=a,i>=this._d&&(this._o[this._p]=s,this.stop())}),this}stop(t=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,t)for(let r of this._cb)r(this._o);return this}restart(t=null,r=!1){return this.stop(r).restart(t)}onEnd(t){return this._cb.push(t),this}chain(t){return this._ch.onEnd(()=>{this._cu=t.start(this._lc)}),this._ch=t,this}reset(){return this._cb.length=0,this.stop()}relative(t=!0){return this._rel=t,this}delay(t){return this._w=t,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};var ht=4,U=1<<ht,ut=8,ee=1<<ut,f=4095,S=e=>.5*(1-Math.cos(e*Math.PI)),R=class{_p=[];_po=4;_pf=.5;_e=null;constructor(t){this._e=t||globalThis,this.noiseSeed()}noise(t,r=0,s=0){t<0&&(t=-t),r<0&&(r=-r),s<0&&(s=-s);let a=Math.floor(t),i=Math.floor(r),o=Math.floor(s),h=t-a,u=r-i,b=s-o,c,d,_=0,g=.5,l,p,I;for(let Y=0;Y<this._po;Y++){let m=a+(i<<ht)+(o<<ut);c=S(h),d=S(u),l=this._p[m&f],l+=c*(this._p[m+1&f]-l),p=this._p[m+U&f],p+=c*(this._p[m+U+1&f]-p),l+=d*(p-l),m+=ee,p=this._p[m&f],p+=c*(this._p[m+1&f]-p),I=this._p[m+U&f],I+=c*(this._p[m+U+1&f]-I),p+=d*(I-p),l+=S(b)*(p-l),_+=l*g,g*=this._pf,a<<=1,h*=2,i<<=1,u*=2,o<<=1,b*=2,h>=1&&(a++,h--),u>=1&&(i++,u--),b>=1&&(o++,b--)}return _}noiseDetail(t,r){t>0&&(this._po=t),r>0&&(this._pf=r)}noiseSeed(t=null){t!=null&&this._e.seed(t);let r=this._e.rand||Math.random;for(let s=0;s<f+1;s++)this._p[s]=r()}};var lt=(e,t,r=1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.alpha(r),s.rectfill(0,0,e.width,e.height,t),a.globalCompositeOperation="destination-atop",s.alpha(1),s.image(0,0,e),s.pop()});var ct=(e,t,r=!0,s=globalThis)=>s.paint(e.width*t,e.height*t,a=>{s.push(),a.imageSmoothingEnabled=!r,s.scale(t),s.image(0,0,e),s.pop()});var pt=(e,t=!0,r=!1,s=globalThis)=>s.paint(e.width,e.height,a=>{s.push(),s.scale(t?-1:1,r?-1:1),s.image(t?-e.width:0,r?-e.height:0,e),s.pop()});globalThis.utils=Object.assign(globalThis.utils||{},X);})();
|
|
3
3
|
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/grid.js
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// src/grid/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
20
|
Grid: () => Grid,
|
|
21
21
|
TypedGrid: () => TypedGrid
|
|
22
22
|
});
|
|
@@ -250,5 +250,5 @@
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
// src/grid/_web.js
|
|
253
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
253
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
254
254
|
})();
|
package/dist/image.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let
|
|
1
|
+
(()=>{globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var s=(e,a,r=1,t=globalThis)=>t.paint(e.width,e.height,n=>{t.push(),t.alpha(r),t.rectfill(0,0,e.width,e.height,a),n.globalCompositeOperation="destination-atop",t.alpha(1),t.image(0,0,e),t.pop()});var i=(e,a,r=!0,t=globalThis)=>t.paint(e.width*a,e.height*a,n=>{t.push(),n.imageSmoothingEnabled=!r,t.scale(a),t.image(0,0,e),t.pop()});var u=(e,a=!0,r=!1,t=globalThis)=>t.paint(e.width,e.height,n=>{t.push(),t.scale(a?-1:1,r?-1:1),t.image(a?-e.width:0,r?-e.height:0,e),t.pop()});globalThis.utils=Object.assign(globalThis.utils||{},{tint:s,scaleImage:i,flipImage:u});})();
|
package/dist/math.js
CHANGED
|
@@ -15,13 +15,16 @@
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// src/math/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
20
|
advance: () => advance_default,
|
|
21
21
|
diff: () => diff_default,
|
|
22
|
+
dist: () => dist_default,
|
|
22
23
|
fract: () => fract_default,
|
|
24
|
+
mag: () => mag_default,
|
|
23
25
|
mod: () => mod_default,
|
|
24
26
|
range: () => range_default,
|
|
27
|
+
round: () => round_default,
|
|
25
28
|
wave: () => wave_default
|
|
26
29
|
});
|
|
27
30
|
|
|
@@ -53,6 +56,25 @@
|
|
|
53
56
|
// src/math/mod.js
|
|
54
57
|
var mod_default = (a, b) => (b + a % b) % b;
|
|
55
58
|
|
|
59
|
+
// src/math/round.js
|
|
60
|
+
var round_default = (n, decimals) => {
|
|
61
|
+
if (!decimals) {
|
|
62
|
+
return Math.round(n);
|
|
63
|
+
}
|
|
64
|
+
const multiplier = Math.pow(10, decimals);
|
|
65
|
+
return Math.round(n * multiplier) / multiplier;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/math/dist.js
|
|
69
|
+
var dist_default = (x1, y1, x2, y2) => {
|
|
70
|
+
return Math.hypot(x2 - x1, y2 - y1);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/math/mag.js
|
|
74
|
+
var mag_default = (x, y) => {
|
|
75
|
+
return Math.hypot(x, y);
|
|
76
|
+
};
|
|
77
|
+
|
|
56
78
|
// src/math/_web.js
|
|
57
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
79
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
58
80
|
})();
|
package/dist/math.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var i=Object.defineProperty;var h=(t,r)=>{for(var o in r)i(t,o,{get:r[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var s={};h(s,{advance:()=>u,diff:()=>n,dist:()=>f,fract:()=>x,mag:()=>l,mod:()=>p,range:()=>a,round:()=>y,wave:()=>c});var n=(t,r)=>Math.abs(r-t)||0;var c=(t,r,o,e=Math.sin)=>t+(e(o)+1)/2*(r-t);var x=t=>t%1||0;var a=t=>Array.from(Array(t).keys());var T=2*Math.PI;var u=advance=(t,r,o,e=1)=>{o&&(r.x+=o.x*e,r.y+=o.y*e),t.x+=r.x*e,t.y+=r.y*e};var p=(t,r)=>(r+t%r)%r;var y=(t,r)=>{if(!r)return Math.round(t);let o=Math.pow(10,r);return Math.round(t*o)/o};var f=(t,r,o,e)=>Math.hypot(o-t,e-r);var l=(t,r)=>Math.hypot(t,r);globalThis.utils=Object.assign(globalThis.utils||{},s);})();
|
package/dist/noise.js
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// src/noise/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
20
|
Noise: () => Noise
|
|
21
21
|
});
|
|
22
22
|
var PERLIN_YWRAPB = 4;
|
|
@@ -149,5 +149,5 @@
|
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
// src/noise/_web.js
|
|
152
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
152
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
153
153
|
})();
|
package/dist/noise.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var T=Object.defineProperty;var y=(i,e)=>{for(var t in e)T(i,t,{get:e[t],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let i in globalThis.utils)i!=="global"&&(globalThis[i]=globalThis.utils[i])};var g={};y(g,{Noise:()=>E});var B=4,h=1<<B,V=8,v=1<<V,s=4095,_=i=>.5*(1-Math.cos(i*Math.PI)),E=class{_p=[];_po=4;_pf=.5;_e=null;constructor(e){this._e=e||globalThis,this.noiseSeed()}noise(e,t=0,r=0){e<0&&(e=-e),t<0&&(t=-t),r<0&&(r=-r);let o=Math.floor(e),l=Math.floor(t),p=Math.floor(r),f=e-o,b=t-l,c=r-p,m,D,I=0,L=.5,u,a,d;for(let U=0;U<this._po;U++){let n=o+(l<<B)+(p<<V);m=_(f),D=_(b),u=this._p[n&s],u+=m*(this._p[n+1&s]-u),a=this._p[n+h&s],a+=m*(this._p[n+h+1&s]-a),u+=D*(a-u),n+=v,a=this._p[n&s],a+=m*(this._p[n+1&s]-a),d=this._p[n+h&s],d+=m*(this._p[n+h+1&s]-d),a+=D*(d-a),u+=_(c)*(a-u),I+=u*L,L*=this._pf,o<<=1,f*=2,l<<=1,b*=2,p<<=1,c*=2,f>=1&&(o++,f--),b>=1&&(l++,b--),c>=1&&(p++,c--)}return I}noiseDetail(e,t){e>0&&(this._po=e),t>0&&(this._pf=t)}noiseSeed(e=null){e!=null&&this._e.seed(e);let t=this._e.rand||Math.random;for(let r=0;r<s+1;r++)this._p[r]=t()}};globalThis.utils=Object.assign(globalThis.utils||{},g);})();
|
package/dist/tween.js
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// src/tween/index.js
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
20
|
BACK_IN: () => BACK_IN,
|
|
21
21
|
BACK_IN_OUT: () => BACK_IN_OUT,
|
|
22
22
|
BACK_OUT: () => BACK_OUT,
|
|
@@ -250,5 +250,5 @@
|
|
|
250
250
|
};
|
|
251
251
|
|
|
252
252
|
// src/tween/_web.js
|
|
253
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
253
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
254
254
|
})();
|
package/dist/tween.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var c=Object.defineProperty;var f=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let t in globalThis.utils)t!=="global"&&(globalThis[t]=globalThis.utils[t])};var o={};f(o,{BACK_IN:()=>D,BACK_IN_OUT:()=>g,BACK_OUT:()=>E,BOUNCE_IN:()=>p,BOUNCE_IN_OUT:()=>T,BOUNCE_OUT:()=>m,EASE_IN:()=>h,EASE_IN_OUT:()=>d,EASE_OUT:()=>_,ELASTIC_IN:()=>I,ELASTIC_IN_OUT:()=>U,ELASTIC_OUT:()=>L,LINEAR:()=>l,tween:()=>b});var i=Math.PI/2,b=(t,e,r,a=1,s=l)=>new u(t,e,r,a,s),l=t=>t,h=t=>t*t,_=t=>-t*(t-2),d=t=>t<.5?2*t*t:-2*t*t+4*t-1,D=t=>t*t*t-t*Math.sin(t*Math.PI),E=t=>{let e=1-t;return 1-(e*e*e-e*Math.sin(e*Math.PI))},g=t=>{if(t<.5){let r=2*t;return .5*(r*r*r-r*Math.sin(r*Math.PI))}let e=1-(2*t-1);return .5*(1-(e*e*e-e*Math.sin(t*Math.PI)))+.5},I=t=>Math.sin(13*i*t)*Math.pow(2,10*(t-1)),L=t=>Math.sin(-13*i*(t+1))*Math.pow(2,-10*t)+1,U=t=>{if(t<.5){let a=Math.sin(13*i*(2*t)),s=Math.pow(2,10*(2*t-1));return .5*a*s}let e=Math.sin(-13*i*(2*t-1+1)),r=Math.pow(2,-10*(2*t-1));return .5*(e*r+2)},p=t=>1-m(1-t),m=t=>t<4/11?121*t*t/16:t<8/11?363/40*t*t-99/10*t+17/5:t<9/10?4356/361*t*t-35442/1805*t+16061/1805:54/5*t*t-513/25*t+268/25,T=t=>t<.5?.5*p(t*2):.5*m(t*2-1)+.5,u=class{running=!1;_o;_p;_x;_d;_w;_e;_rel;_cb=[];_t=0;_u=0;_ch=this;_cu=this;_lc;constructor(e,r,a,s,n){this._o=e,this._p=r,this._x=a,this._d=s,this._e=n,this._w=0}start(e){if(this.running)return this;this._cu.stop(!1),this._ch=this._cu=this,this.running=!0;let r=this._o[this._p]||0,a=this._rel?r+this._x:this._x;return this._lc=this._lc||e||globalThis,this._u=this._lc.listen("update",s=>{if(this._t<=this._w){this._t+=s;return}let n=this._t-this._w;this._o[this._p]=this._lc.lerp(r,a,this._e(n/this._d)),this._t+=s,n>=this._d&&(this._o[this._p]=a,this.stop())}),this}stop(e=!0){if(!this._u)return this;if(this.running=!1,this._u(),this._t=0,e)for(let r of this._cb)r(this._o);return this}restart(e=null,r=!1){return this.stop(r).restart(e)}onEnd(e){return this._cb.push(e),this}chain(e){return this._ch.onEnd(()=>{this._cu=e.start(this._lc)}),this._ch=e,this}reset(){return this._cb.length=0,this.stop()}relative(e=!0){return this._rel=e,this}delay(e){return this._w=e,this}get current(){return this._cu}get progress(){return this.running&&this._t>this._w?(this._t-this._w)/this._d:0}};globalThis.utils=Object.assign(globalThis.utils||{},o);})();
|
package/dist/vector.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/vector/index.js
|
|
9
|
-
var
|
|
10
|
-
__export(
|
|
9
|
+
var index_exports = {};
|
|
10
|
+
__export(index_exports, {
|
|
11
11
|
DOWN: () => DOWN,
|
|
12
12
|
LEFT: () => LEFT,
|
|
13
13
|
ONE: () => ONE,
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
vecMult(v, value);
|
|
140
140
|
return v;
|
|
141
141
|
};
|
|
142
|
-
var vecMag = (v) =>
|
|
142
|
+
var vecMag = (v) => Math.hypot(v.x, v.y);
|
|
143
143
|
var vecMag2 = (v) => v.x * v.x + v.y * v.y;
|
|
144
144
|
var vecNorm = (v) => {
|
|
145
145
|
const length = vecMag(v);
|
|
@@ -157,9 +157,7 @@
|
|
|
157
157
|
return v;
|
|
158
158
|
};
|
|
159
159
|
var vecDist = (a, b) => {
|
|
160
|
-
|
|
161
|
-
const dy = a.y - b.y;
|
|
162
|
-
return sqrt(dx * dx + dy * dy);
|
|
160
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
163
161
|
};
|
|
164
162
|
var vecDist2 = (a, b) => {
|
|
165
163
|
const dx = a.x - b.x;
|
|
@@ -217,5 +215,5 @@
|
|
|
217
215
|
var LEFT = /* @__PURE__ */ vec(-1, 0);
|
|
218
216
|
|
|
219
217
|
// src/vector/_web.js
|
|
220
|
-
globalThis.utils = Object.assign(globalThis.utils || {},
|
|
218
|
+
globalThis.utils = Object.assign(globalThis.utils || {}, index_exports);
|
|
221
219
|
})();
|
package/dist/vector.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var q=Object.defineProperty;var A=(t,e)=>{for(var o in e)q(t,o,{get:e[o],enumerable:!0})};var a={};A(a,{DOWN:()=>K,LEFT:()=>Q,ONE:()=>k,RIGHT:()=>J,UP:()=>z,Vector:()=>s,ZERO:()=>T,vec:()=>r,vecAbs:()=>j,vecAdd:()=>u,vecAngle:()=>P,vecAngleBetween:()=>w,vecCeil:()=>B,vecClamp:()=>H,vecCross:()=>U,vecDist:()=>L,vecDist2:()=>N,vecDiv:()=>x,vecDot:()=>D,vecEq:()=>p,vecFloor:()=>F,vecIsZero:()=>W,vecLerp:()=>Z,vecLimit:()=>b,vecMag:()=>d,vecMag2:()=>R,vecMove:()=>V,vecMult:()=>y,vecNorm:()=>h,vecRand:()=>$,vecReflect:()=>O,vecRotate:()=>I,vecRound:()=>G,vecSet:()=>g,vecSetMag:()=>S,vecSub:()=>i});var C=Math.sqrt,M=Math.cos,f=Math.sin,E=2*Math.PI,s=class{x;y;constructor(e=0,o=e){this.x=e,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},n=t=>t instanceof s,r=(t=0,e=t)=>(n(t)&&(e=t.y,t=t.x),new s(t,e)),p=(t,e,o=e)=>n(e)?p(t,e.x,e.y):t.x===e&&t.y===o,g=(t,e,o=e)=>(n(e)?g(t,e.x,e.y):(t.x=e,t.y=o),t),u=(t,e,o=e)=>n(e)?u(t,e.x,e.y):(t.x+=e,t.y+=o,t),i=(t,e,o=e)=>n(e)?i(t,e.x,e.y):(t.x-=e,t.y-=o,t),y=(t,e,o=e)=>n(e)?y(t,e.x,e.y):(t.x*=e,t.y*=o,t),x=(t,e,o=e)=>n(e)?x(t,e.x,e.y):(t.x/=e||1,t.y/=o||1,t),I=(t,e)=>{let o=M(e),c=f(e);return t.x=o*t.x-c*t.y,t.y=c*t.x+o*t.y,t},O=(t,e)=>{let o=h(r(e));return i(t,y(o,2*D(t,o)))},S=(t,e)=>(h(t),y(t,e),t),d=t=>Math.hypot(t.x,t.y),R=t=>t.x*t.x+t.y*t.y,h=t=>{let e=d(t);return e>0&&x(t,e),t},b=(t,e=1)=>{let o=R(t);return o>e*e&&(x(t,C(o)),y(t,e)),t},L=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),N=(t,e)=>{let o=t.x-e.x,c=t.y-e.y;return o*o+c*c},P=t=>Math.atan2(t.y,t.x),w=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),D=(t,e)=>t.x*e.x+t.y*e.y,U=(t,e)=>t.x*e.y-t.y*e.x,Z=(t,e,o)=>(t.x+=(e.x-t.x)*o||0,t.y+=(e.y-t.y)*o||0,t),$=(t=1,e=t,o=globalThis.rand||Math.random)=>{let c=o()*E,l=o()*(e-t)+t;return r(M(c)*l,f(c)*l)},j=t=>(t.x=Math.abs(t.x),t.y=Math.abs(t.y),t),B=t=>(t.x=Math.ceil(t.x),t.y=Math.ceil(t.y),t),F=t=>(t.x=Math.floor(t.x),t.y=Math.floor(t.y),t),G=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t),H=(t,e,o)=>(t.x<e.x&&(t.x=e.x),t.x>o.x&&(t.x=o.x),t.y<e.y&&(t.y=e.y),t.y>o.y&&(t.y=o.y),t),V=(t,e,o=1)=>u(t,e.x*o,e.y*o),W=t=>p(t,T),T=r(0,0),k=r(1,1),z=r(0,-1),J=r(1,0),K=r(0,1),Q=r(-1,0);globalThis.utils=Object.assign(globalThis.utils||{},a);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litecanvas/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Utilities to help build litecanvas games",
|
|
5
5
|
"author": "Luiz Bills <luizbills@pm.me>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"litecanvas": "
|
|
37
|
+
"litecanvas": "latest"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"esbuild": "^0.
|
|
40
|
+
"esbuild": "^0.25.0",
|
|
41
41
|
"gzip-size": "^7.0.0",
|
|
42
|
-
"prettier": "^3.
|
|
42
|
+
"prettier": "^3.5.2"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/actor/README.md
CHANGED
|
@@ -14,11 +14,11 @@ litecanvas({
|
|
|
14
14
|
loop: { init, tapped, draw },
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
// create a
|
|
17
|
+
// lets create a image to our actor
|
|
18
18
|
mySprite = paint(3, 3, ["303", "030", "303"], { scale: 10 })
|
|
19
19
|
|
|
20
20
|
function init() {
|
|
21
|
-
// create a actor
|
|
21
|
+
// create a actor and pass its image
|
|
22
22
|
player = new Actor(mySprite)
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -42,9 +42,12 @@ Set or get the actor position vector
|
|
|
42
42
|
|
|
43
43
|
```js
|
|
44
44
|
player.pos.x = 100
|
|
45
|
-
player.pos.
|
|
45
|
+
player.pos.y = 200
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
> Note:
|
|
49
|
+
> The `player.pos` is a [Vector](https://github.com/litecanvas/utils/blob/main/src/vector/README.md) instance.
|
|
50
|
+
|
|
48
51
|
## Actor#x / Actor#y
|
|
49
52
|
|
|
50
53
|
Set or get the actor position X or Y
|
|
@@ -99,15 +102,12 @@ If `true` the actor sprite is flipped vertically. Default is `false`.
|
|
|
99
102
|
Set or get the actor anchor (origin). By default, the anchor is a vector `(0, 0)` (meaning anchor Top Left).
|
|
100
103
|
|
|
101
104
|
```js
|
|
102
|
-
//
|
|
105
|
+
// example: actor position based on their center
|
|
103
106
|
player.anchor.x = 0.5
|
|
104
107
|
player.anchor.y = 0.5
|
|
105
|
-
```
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
// alternatively
|
|
109
|
+
// or...
|
|
109
110
|
import { ANCHOR_CENTER } from "@litecanvas/utils"
|
|
110
|
-
|
|
111
111
|
player.anchor = ANCHOR_CENTER
|
|
112
112
|
```
|
|
113
113
|
|
|
@@ -173,4 +173,4 @@ player.sprite = anotherSprite
|
|
|
173
173
|
|
|
174
174
|
> The actor sprite must be a `Image`, `HTMLCanvas` or `OffscreenCanvas`.
|
|
175
175
|
>
|
|
176
|
-
> Remember, you can create a image using the litecanvas' `paint()` built-in helper or [load a image](https://github.com/litecanvas/plugin-asset-loader?tab=readme-ov-file#loading-images)
|
|
176
|
+
> Remember, you can create a image using the litecanvas' `paint()` built-in helper or [load a image](https://github.com/litecanvas/plugin-asset-loader?tab=readme-ov-file#loading-images).
|
package/src/camera/README.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
import { litecanvas } from "litecanvas"
|
|
9
9
|
import { Camera } from "@litecanvas/utils"
|
|
10
10
|
|
|
11
|
+
litecanvas({
|
|
12
|
+
loop: { init, draw }
|
|
13
|
+
})
|
|
14
|
+
|
|
11
15
|
function init() {
|
|
12
16
|
camera = new Camera()
|
|
13
17
|
}
|
|
@@ -17,11 +21,11 @@ function draw() {
|
|
|
17
21
|
|
|
18
22
|
camera.start()
|
|
19
23
|
|
|
20
|
-
// draw your game objects here
|
|
24
|
+
// draw your dynamic game objects here (player, enemies, tilemap, etc)
|
|
21
25
|
|
|
22
26
|
camera.end()
|
|
23
27
|
|
|
24
|
-
// draw your UI here
|
|
28
|
+
// draw your UI here (score, lifes, etc)
|
|
25
29
|
}
|
|
26
30
|
```
|
|
27
31
|
|
|
@@ -43,7 +47,7 @@ function draw() {
|
|
|
43
47
|
|
|
44
48
|
Apply the camera transformations (move, zoom and rotate). You must call this method before draw anything inside of the camera.
|
|
45
49
|
|
|
46
|
-
###
|
|
50
|
+
### end()
|
|
47
51
|
|
|
48
52
|
Stop looking through the camera. You must call this method after draw anything inside of the camera.
|
|
49
53
|
|
package/src/math/dist.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the distance between a point (x1, y1) to another (x2, y2).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} x1
|
|
5
|
+
* @param {number} y1
|
|
6
|
+
* @param {number} x2
|
|
7
|
+
* @param {number} y2
|
|
8
|
+
* @returns {number}
|
|
9
|
+
*/
|
|
10
|
+
export default (x1, y1, x2, y2) => {
|
|
11
|
+
return Math.hypot(x2 - x1, y2 - y1)
|
|
12
|
+
}
|
package/src/math/index.js
CHANGED
|
@@ -4,3 +4,6 @@ export { default as fract } from "./fract.js"
|
|
|
4
4
|
export { default as range } from "./range.js"
|
|
5
5
|
export { default as advance } from "./advance.js"
|
|
6
6
|
export { default as mod } from "./mod.js"
|
|
7
|
+
export { default as round } from "./round.js"
|
|
8
|
+
export { default as dist } from "./dist.js"
|
|
9
|
+
export { default as mag } from "./mag.js"
|
package/src/math/mag.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the integer closest to a number.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} n number to round.
|
|
5
|
+
* @param {number} [decimals] number of decimal places to round to, default is 0.
|
|
6
|
+
* @returns {number} rounded number.
|
|
7
|
+
*/
|
|
8
|
+
export default (n, decimals) => {
|
|
9
|
+
if (!decimals) {
|
|
10
|
+
return Math.round(n)
|
|
11
|
+
}
|
|
12
|
+
const multiplier = Math.pow(10, decimals)
|
|
13
|
+
return Math.round(n * multiplier) / multiplier
|
|
14
|
+
}
|
package/src/vector/index.js
CHANGED
|
@@ -205,7 +205,7 @@ export const vecSetMag = (v, value) => {
|
|
|
205
205
|
* @param {Vector} v
|
|
206
206
|
* @returns {number}
|
|
207
207
|
*/
|
|
208
|
-
export const vecMag = (v) =>
|
|
208
|
+
export const vecMag = (v) => Math.hypot(v.x, v.y)
|
|
209
209
|
|
|
210
210
|
/**
|
|
211
211
|
* Calculates the magnitude (length) of the vector squared.
|
|
@@ -253,9 +253,7 @@ export const vecLimit = (v, max = 1) => {
|
|
|
253
253
|
* @returns {number}
|
|
254
254
|
*/
|
|
255
255
|
export const vecDist = (a, b) => {
|
|
256
|
-
|
|
257
|
-
const dy = a.y - b.y
|
|
258
|
-
return sqrt(dx * dx + dy * dy)
|
|
256
|
+
return Math.hypot(b.x - a.x, b.y - a.y)
|
|
259
257
|
}
|
|
260
258
|
|
|
261
259
|
/**
|