q5 2.14.4 → 2.15.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 +20 -45
- package/deno.json +2 -1
- package/package.json +2 -2
- package/q5.d.ts +4 -4
- package/q5.js +29 -27
- package/q5.min.js +2 -2
- package/q5js_brand.webp +0 -0
- package/q5js_icon.png +0 -0
- package/src/q5-2d-canvas.js +0 -202
- package/src/q5-2d-drawing.js +0 -399
- package/src/q5-2d-image.js +0 -330
- package/src/q5-2d-soft-filters.js +0 -145
- package/src/q5-2d-text.js +0 -279
- package/src/q5-ai.js +0 -65
- package/src/q5-canvas.js +0 -367
- package/src/q5-color.js +0 -322
- package/src/q5-core.js +0 -319
- package/src/q5-display.js +0 -101
- package/src/q5-dom.js +0 -2
- package/src/q5-input.js +0 -215
- package/src/q5-math.js +0 -424
- package/src/q5-noisier.js +0 -264
- package/src/q5-record.js +0 -366
- package/src/q5-sensors.js +0 -98
- package/src/q5-sound.js +0 -64
- package/src/q5-util.js +0 -50
- package/src/q5-vector.js +0 -305
- package/src/q5-webgpu-canvas.js +0 -565
- package/src/q5-webgpu-drawing.js +0 -638
- package/src/q5-webgpu-image.js +0 -268
- package/src/q5-webgpu-text.js +0 -594
- package/src/readme.md +0 -248
package/src/q5-vector.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
Q5.modules.vector = ($) => {
|
|
2
|
-
$.createVector = (x, y, z) => new Q5.Vector(x, y, z, $);
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
Q5.Vector = class {
|
|
6
|
-
constructor(x, y, z, $) {
|
|
7
|
-
this.x = x || 0;
|
|
8
|
-
this.y = y || 0;
|
|
9
|
-
this.z = z || 0;
|
|
10
|
-
this._$ = $ || window;
|
|
11
|
-
this._cn = null;
|
|
12
|
-
this._cnsq = null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
set(x, y, z) {
|
|
16
|
-
this.x = x?.x || x || 0;
|
|
17
|
-
this.y = x?.y || y || 0;
|
|
18
|
-
this.z = x?.z || z || 0;
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
copy() {
|
|
23
|
-
return new Q5.Vector(this.x, this.y, this.z);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
_arg2v(x, y, z) {
|
|
27
|
-
if (x?.x !== undefined) return x;
|
|
28
|
-
if (y !== undefined) {
|
|
29
|
-
return { x, y, z: z || 0 };
|
|
30
|
-
}
|
|
31
|
-
return { x: x, y: x, z: x };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
_calcNorm() {
|
|
35
|
-
this._cnsq = this.x * this.x + this.y * this.y + this.z * this.z;
|
|
36
|
-
this._cn = Math.sqrt(this._cnsq);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
add() {
|
|
40
|
-
let u = this._arg2v(...arguments);
|
|
41
|
-
this.x += u.x;
|
|
42
|
-
this.y += u.y;
|
|
43
|
-
this.z += u.z;
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
rem() {
|
|
48
|
-
let u = this._arg2v(...arguments);
|
|
49
|
-
this.x %= u.x;
|
|
50
|
-
this.y %= u.y;
|
|
51
|
-
this.z %= u.z;
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
sub() {
|
|
56
|
-
let u = this._arg2v(...arguments);
|
|
57
|
-
this.x -= u.x;
|
|
58
|
-
this.y -= u.y;
|
|
59
|
-
this.z -= u.z;
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
mult() {
|
|
64
|
-
let u = this._arg2v(...arguments);
|
|
65
|
-
this.x *= u.x;
|
|
66
|
-
this.y *= u.y;
|
|
67
|
-
this.z *= u.z;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
div() {
|
|
72
|
-
let u = this._arg2v(...arguments);
|
|
73
|
-
if (u.x) this.x /= u.x;
|
|
74
|
-
else this.x = 0;
|
|
75
|
-
if (u.y) this.y /= u.y;
|
|
76
|
-
else this.y = 0;
|
|
77
|
-
if (u.z) this.z /= u.z;
|
|
78
|
-
else this.z = 0;
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
mag() {
|
|
83
|
-
this._calcNorm();
|
|
84
|
-
return this._cn;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
magSq() {
|
|
88
|
-
this._calcNorm();
|
|
89
|
-
return this._cnsq;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
dot() {
|
|
93
|
-
let u = this._arg2v(...arguments);
|
|
94
|
-
return this.x * u.x + this.y * u.y + this.z * u.z;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
dist() {
|
|
98
|
-
let u = this._arg2v(...arguments);
|
|
99
|
-
let x = this.x - u.x;
|
|
100
|
-
let y = this.y - u.y;
|
|
101
|
-
let z = this.z - u.z;
|
|
102
|
-
return Math.sqrt(x * x + y * y + z * z);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
cross() {
|
|
106
|
-
let u = this._arg2v(...arguments);
|
|
107
|
-
let x = this.y * u.z - this.z * u.y;
|
|
108
|
-
let y = this.z * u.x - this.x * u.z;
|
|
109
|
-
let z = this.x * u.y - this.y * u.x;
|
|
110
|
-
this.x = x;
|
|
111
|
-
this.y = y;
|
|
112
|
-
this.z = z;
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
normalize() {
|
|
117
|
-
this._calcNorm();
|
|
118
|
-
let n = this._cn;
|
|
119
|
-
if (n != 0) {
|
|
120
|
-
this.x /= n;
|
|
121
|
-
this.y /= n;
|
|
122
|
-
this.z /= n;
|
|
123
|
-
}
|
|
124
|
-
this._cn = 1;
|
|
125
|
-
this._cnsq = 1;
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
limit(m) {
|
|
130
|
-
this._calcNorm();
|
|
131
|
-
let n = this._cn;
|
|
132
|
-
if (n > m) {
|
|
133
|
-
let t = m / n;
|
|
134
|
-
this.x *= t;
|
|
135
|
-
this.y *= t;
|
|
136
|
-
this.z *= t;
|
|
137
|
-
this._cn = m;
|
|
138
|
-
this._cnsq = m * m;
|
|
139
|
-
}
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
setMag(m) {
|
|
144
|
-
this._calcNorm();
|
|
145
|
-
let n = this._cn;
|
|
146
|
-
let t = m / n;
|
|
147
|
-
this.x *= t;
|
|
148
|
-
this.y *= t;
|
|
149
|
-
this.z *= t;
|
|
150
|
-
this._cn = m;
|
|
151
|
-
this._cnsq = m * m;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
heading() {
|
|
156
|
-
return this._$.atan2(this.y, this.x);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
setHeading(ang) {
|
|
160
|
-
let mag = this.mag();
|
|
161
|
-
this.x = mag * this._$.cos(ang);
|
|
162
|
-
this.y = mag * this._$.sin(ang);
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
rotate(ang) {
|
|
167
|
-
let costh = this._$.cos(ang);
|
|
168
|
-
let sinth = this._$.sin(ang);
|
|
169
|
-
let vx = this.x * costh - this.y * sinth;
|
|
170
|
-
let vy = this.x * sinth + this.y * costh;
|
|
171
|
-
this.x = vx;
|
|
172
|
-
this.y = vy;
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
angleBetween() {
|
|
177
|
-
let u = this._arg2v(...arguments);
|
|
178
|
-
let o = Q5.Vector.cross(this, u);
|
|
179
|
-
let ang = this._$.atan2(o.mag(), this.dot(u));
|
|
180
|
-
return ang * Math.sign(o.z || 1);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
lerp() {
|
|
184
|
-
let args = [...arguments];
|
|
185
|
-
let amt = args.at(-1);
|
|
186
|
-
if (amt == 0) return this;
|
|
187
|
-
let u = this._arg2v(...args.slice(0, -1));
|
|
188
|
-
this.x += (u.x - this.x) * amt;
|
|
189
|
-
this.y += (u.y - this.y) * amt;
|
|
190
|
-
this.z += (u.z - this.z) * amt;
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
slerp() {
|
|
195
|
-
let args = [...arguments];
|
|
196
|
-
let amt = args.at(-1);
|
|
197
|
-
if (amt == 0) return this;
|
|
198
|
-
let u = this._arg2v(...args.slice(0, -1));
|
|
199
|
-
if (amt == 1) return this.set(u);
|
|
200
|
-
|
|
201
|
-
let v0Mag = this.mag();
|
|
202
|
-
let v1Mag = u.mag();
|
|
203
|
-
|
|
204
|
-
if (v0Mag == 0 || v1Mag == 0) {
|
|
205
|
-
return this.mult(1 - amt).add(u.mult(amt));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
let axis = Q5.Vector.cross(this, u);
|
|
209
|
-
let axisMag = axis.mag();
|
|
210
|
-
let theta = Math.atan2(axisMag, this.dot(u));
|
|
211
|
-
|
|
212
|
-
if (axisMag > 0) {
|
|
213
|
-
axis.div(axisMag);
|
|
214
|
-
} else if (theta < this._$.HALF_PI) {
|
|
215
|
-
return this.mult(1 - amt).add(u.mult(amt));
|
|
216
|
-
} else {
|
|
217
|
-
if (this.z == 0 && u.z == 0) axis.set(0, 0, 1);
|
|
218
|
-
else if (this.x != 0) axis.set(this.y, -this.x, 0).normalize();
|
|
219
|
-
else axis.set(1, 0, 0);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
let ey = axis.cross(this);
|
|
223
|
-
let lerpedMagFactor = 1 - amt + (amt * v1Mag) / v0Mag;
|
|
224
|
-
let cosMultiplier = lerpedMagFactor * Math.cos(amt * theta);
|
|
225
|
-
let sinMultiplier = lerpedMagFactor * Math.sin(amt * theta);
|
|
226
|
-
|
|
227
|
-
this.x = this.x * cosMultiplier + ey.x * sinMultiplier;
|
|
228
|
-
this.y = this.y * cosMultiplier + ey.y * sinMultiplier;
|
|
229
|
-
this.z = this.z * cosMultiplier + ey.z * sinMultiplier;
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
reflect(n) {
|
|
234
|
-
n.normalize();
|
|
235
|
-
return this.sub(n.mult(2 * this.dot(n)));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
array() {
|
|
239
|
-
return [this.x, this.y, this.z];
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
equals(u, epsilon) {
|
|
243
|
-
epsilon ??= Number.EPSILON || 0;
|
|
244
|
-
return Math.abs(u.x - this.x) < epsilon && Math.abs(u.y - this.y) < epsilon && Math.abs(u.z - this.z) < epsilon;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
fromAngle(th, l) {
|
|
248
|
-
if (l === undefined) l = 1;
|
|
249
|
-
this._cn = l;
|
|
250
|
-
this._cnsq = l * l;
|
|
251
|
-
this.x = l * this._$.cos(th);
|
|
252
|
-
this.y = l * this._$.sin(th);
|
|
253
|
-
this.z = 0;
|
|
254
|
-
return this;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
fromAngles(th, ph, l) {
|
|
258
|
-
if (l === undefined) l = 1;
|
|
259
|
-
this._cn = l;
|
|
260
|
-
this._cnsq = l * l;
|
|
261
|
-
const cosph = this._$.cos(ph);
|
|
262
|
-
const sinph = this._$.sin(ph);
|
|
263
|
-
const costh = this._$.cos(th);
|
|
264
|
-
const sinth = this._$.sin(th);
|
|
265
|
-
this.x = l * sinth * sinph;
|
|
266
|
-
this.y = -l * costh;
|
|
267
|
-
this.z = l * sinth * cosph;
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
random2D() {
|
|
272
|
-
this._cn = this._cnsq = 1;
|
|
273
|
-
return this.fromAngle(Math.random() * Math.PI * 2);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
random3D() {
|
|
277
|
-
this._cn = this._cnsq = 1;
|
|
278
|
-
return this.fromAngles(Math.random() * Math.PI * 2, Math.random() * Math.PI * 2);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
toString() {
|
|
282
|
-
return `[${this.x}, ${this.y}, ${this.z}]`;
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
Q5.Vector.add = (v, u) => v.copy().add(u);
|
|
287
|
-
Q5.Vector.cross = (v, u) => v.copy().cross(u);
|
|
288
|
-
Q5.Vector.dist = (v, u) => Math.hypot(v.x - u.x, v.y - u.y, v.z - u.z);
|
|
289
|
-
Q5.Vector.div = (v, u) => v.copy().div(u);
|
|
290
|
-
Q5.Vector.dot = (v, u) => v.copy().dot(u);
|
|
291
|
-
Q5.Vector.equals = (v, u, epsilon) => v.equals(u, epsilon);
|
|
292
|
-
Q5.Vector.lerp = (v, u, amt) => v.copy().lerp(u, amt);
|
|
293
|
-
Q5.Vector.slerp = (v, u, amt) => v.copy().slerp(u, amt);
|
|
294
|
-
Q5.Vector.limit = (v, m) => v.copy().limit(m);
|
|
295
|
-
Q5.Vector.heading = (v) => this._$.atan2(v.y, v.x);
|
|
296
|
-
Q5.Vector.magSq = (v) => v.x * v.x + v.y * v.y + v.z * v.z;
|
|
297
|
-
Q5.Vector.mag = (v) => Math.sqrt(Q5.Vector.magSq(v));
|
|
298
|
-
Q5.Vector.mult = (v, u) => v.copy().mult(u);
|
|
299
|
-
Q5.Vector.normalize = (v) => v.copy().normalize();
|
|
300
|
-
Q5.Vector.rem = (v, u) => v.copy().rem(u);
|
|
301
|
-
Q5.Vector.sub = (v, u) => v.copy().sub(u);
|
|
302
|
-
|
|
303
|
-
for (let k of ['fromAngle', 'fromAngles', 'random2D', 'random3D']) {
|
|
304
|
-
Q5.Vector[k] = (u, v, t) => new Q5.Vector()[k](u, v, t);
|
|
305
|
-
}
|