q5 2.9.20 → 2.9.22
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 -18
- package/package.json +1 -1
- package/q5.js +196 -103
- package/q5.min.js +1 -1
- package/src/q5-2d-canvas.js +8 -2
- package/src/q5-2d-drawing.js +41 -83
- package/src/q5-2d-image.js +1 -0
- package/src/q5-2d-text.js +7 -0
- package/src/q5-canvas.js +6 -5
- package/src/q5-color.js +5 -0
- package/src/q5-core.js +11 -1
- package/src/q5-input.js +12 -0
- package/src/q5-math.js +10 -3
- package/src/q5-record.js +2 -0
- package/src/q5-vector.js +33 -0
- package/src/q5-webgpu-canvas.js +4 -4
- package/src/q5-webgpu-drawing.js +53 -5
- package/src/q5-webgpu-text.js +5 -0
package/src/q5-2d-drawing.js
CHANGED
|
@@ -47,12 +47,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
47
47
|
|
|
48
48
|
$.line = (x0, y0, x1, y1) => {
|
|
49
49
|
if ($._doStroke) {
|
|
50
|
-
|
|
51
|
-
x0 *= $._da;
|
|
52
|
-
y0 *= $._da;
|
|
53
|
-
x1 *= $._da;
|
|
54
|
-
y1 *= $._da;
|
|
55
|
-
}
|
|
50
|
+
$._da && ((x0 *= $._da), (y0 *= $._da), (x1 *= $._da), (y1 *= $._da));
|
|
56
51
|
$.ctx.beginPath();
|
|
57
52
|
$.ctx.moveTo(x0, y0);
|
|
58
53
|
$.ctx.lineTo(x1, y1);
|
|
@@ -92,6 +87,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
92
87
|
$.ctx.stroke();
|
|
93
88
|
}
|
|
94
89
|
}
|
|
90
|
+
|
|
95
91
|
$.arc = (x, y, w, h, start, stop, mode) => {
|
|
96
92
|
if (start == stop) return $.ellipse(x, y, w, h);
|
|
97
93
|
|
|
@@ -101,7 +97,6 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
101
97
|
w *= $._da;
|
|
102
98
|
h *= $._da;
|
|
103
99
|
}
|
|
104
|
-
|
|
105
100
|
mode ??= $.PIE_OPEN;
|
|
106
101
|
|
|
107
102
|
if ($._ellipseMode == $.CENTER) {
|
|
@@ -120,6 +115,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
120
115
|
$.ctx.ellipse(x, y, w / 2, h / 2, 0, 0, $.TAU);
|
|
121
116
|
ink();
|
|
122
117
|
}
|
|
118
|
+
|
|
123
119
|
$.ellipse = (x, y, w, h) => {
|
|
124
120
|
h ??= w;
|
|
125
121
|
if ($._da) {
|
|
@@ -138,6 +134,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
138
134
|
ellipse((x + w) / 2, (y + h) / 2, w - x, h - y);
|
|
139
135
|
}
|
|
140
136
|
};
|
|
137
|
+
|
|
141
138
|
$.circle = (x, y, d) => {
|
|
142
139
|
if ($._ellipseMode == $.CENTER) {
|
|
143
140
|
if ($._da) {
|
|
@@ -179,6 +176,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
179
176
|
$.ctx.rect(x, y, w, h);
|
|
180
177
|
ink();
|
|
181
178
|
}
|
|
179
|
+
|
|
182
180
|
function roundedRect(x, y, w, h, tl, tr, br, bl) {
|
|
183
181
|
if (tl === undefined) {
|
|
184
182
|
return rect(x, y, w, h);
|
|
@@ -211,30 +209,34 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
211
209
|
roundedRect(x, y, w - x, h - y, tl, tr, br, bl);
|
|
212
210
|
}
|
|
213
211
|
};
|
|
212
|
+
|
|
214
213
|
$.square = (x, y, s, tl, tr, br, bl) => {
|
|
215
214
|
return $.rect(x, y, s, s, tl, tr, br, bl);
|
|
216
215
|
};
|
|
217
216
|
|
|
218
217
|
$.beginShape = () => {
|
|
219
|
-
curveBuff =
|
|
218
|
+
curveBuff.length = 0;
|
|
220
219
|
$.ctx.beginPath();
|
|
221
220
|
firstVertex = true;
|
|
222
221
|
};
|
|
222
|
+
|
|
223
223
|
$.beginContour = () => {
|
|
224
224
|
$.ctx.closePath();
|
|
225
|
-
curveBuff =
|
|
225
|
+
curveBuff.length = 0;
|
|
226
226
|
firstVertex = true;
|
|
227
227
|
};
|
|
228
|
+
|
|
228
229
|
$.endContour = () => {
|
|
229
|
-
curveBuff =
|
|
230
|
+
curveBuff.length = 0;
|
|
230
231
|
firstVertex = true;
|
|
231
232
|
};
|
|
233
|
+
|
|
232
234
|
$.vertex = (x, y) => {
|
|
233
235
|
if ($._da) {
|
|
234
236
|
x *= $._da;
|
|
235
237
|
y *= $._da;
|
|
236
238
|
}
|
|
237
|
-
curveBuff =
|
|
239
|
+
curveBuff.length = 0;
|
|
238
240
|
if (firstVertex) {
|
|
239
241
|
$.ctx.moveTo(x, y);
|
|
240
242
|
} else {
|
|
@@ -242,6 +244,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
242
244
|
}
|
|
243
245
|
firstVertex = false;
|
|
244
246
|
};
|
|
247
|
+
|
|
245
248
|
$.bezierVertex = (cp1x, cp1y, cp2x, cp2y, x, y) => {
|
|
246
249
|
if ($._da) {
|
|
247
250
|
cp1x *= $._da;
|
|
@@ -251,9 +254,10 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
251
254
|
x *= $._da;
|
|
252
255
|
y *= $._da;
|
|
253
256
|
}
|
|
254
|
-
curveBuff =
|
|
257
|
+
curveBuff.length = 0;
|
|
255
258
|
$.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
256
259
|
};
|
|
260
|
+
|
|
257
261
|
$.quadraticVertex = (cp1x, cp1y, x, y) => {
|
|
258
262
|
if ($._da) {
|
|
259
263
|
cp1x *= $._da;
|
|
@@ -261,15 +265,17 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
261
265
|
x *= $._da;
|
|
262
266
|
y *= $._da;
|
|
263
267
|
}
|
|
264
|
-
curveBuff =
|
|
268
|
+
curveBuff.length = 0;
|
|
265
269
|
$.ctx.quadraticCurveTo(cp1x, cp1y, x, y);
|
|
266
270
|
};
|
|
271
|
+
|
|
267
272
|
$.bezier = (x1, y1, x2, y2, x3, y3, x4, y4) => {
|
|
268
273
|
$.beginShape();
|
|
269
274
|
$.vertex(x1, y1);
|
|
270
275
|
$.bezierVertex(x2, y2, x3, y3, x4, y4);
|
|
271
276
|
$.endShape();
|
|
272
277
|
};
|
|
278
|
+
|
|
273
279
|
$.triangle = (x1, y1, x2, y2, x3, y3) => {
|
|
274
280
|
$.beginShape();
|
|
275
281
|
$.vertex(x1, y1);
|
|
@@ -277,6 +283,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
277
283
|
$.vertex(x3, y3);
|
|
278
284
|
$.endShape($.CLOSE);
|
|
279
285
|
};
|
|
286
|
+
|
|
280
287
|
$.quad = (x1, y1, x2, y2, x3, y3, x4, y4) => {
|
|
281
288
|
$.beginShape();
|
|
282
289
|
$.vertex(x1, y1);
|
|
@@ -285,69 +292,12 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
285
292
|
$.vertex(x4, y4);
|
|
286
293
|
$.endShape($.CLOSE);
|
|
287
294
|
};
|
|
295
|
+
|
|
288
296
|
$.endShape = (close) => {
|
|
289
|
-
curveBuff =
|
|
297
|
+
curveBuff.length = 0;
|
|
290
298
|
if (close) $.ctx.closePath();
|
|
291
299
|
ink();
|
|
292
300
|
};
|
|
293
|
-
function catmullRomSpline(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y, numPts, alpha) {
|
|
294
|
-
function catmullromSplineGetT(t, p0x, p0y, p1x, p1y, alpha) {
|
|
295
|
-
let a = Math.pow(p1x - p0x, 2.0) + Math.pow(p1y - p0y, 2.0);
|
|
296
|
-
let b = Math.pow(a, alpha * 0.5);
|
|
297
|
-
return b + t;
|
|
298
|
-
}
|
|
299
|
-
let pts = [];
|
|
300
|
-
|
|
301
|
-
let t0 = 0.0;
|
|
302
|
-
let t1 = catmullromSplineGetT(t0, p0x, p0y, p1x, p1y, alpha);
|
|
303
|
-
let t2 = catmullromSplineGetT(t1, p1x, p1y, p2x, p2y, alpha);
|
|
304
|
-
let t3 = catmullromSplineGetT(t2, p2x, p2y, p3x, p3y, alpha);
|
|
305
|
-
|
|
306
|
-
for (let i = 0; i < numPts; i++) {
|
|
307
|
-
let t = t1 + (i / (numPts - 1)) * (t2 - t1);
|
|
308
|
-
let s = [
|
|
309
|
-
(t1 - t) / (t1 - t0),
|
|
310
|
-
(t - t0) / (t1 - t0),
|
|
311
|
-
(t2 - t) / (t2 - t1),
|
|
312
|
-
(t - t1) / (t2 - t1),
|
|
313
|
-
(t3 - t) / (t3 - t2),
|
|
314
|
-
(t - t2) / (t3 - t2),
|
|
315
|
-
(t2 - t) / (t2 - t0),
|
|
316
|
-
(t - t0) / (t2 - t0),
|
|
317
|
-
(t3 - t) / (t3 - t1),
|
|
318
|
-
(t - t1) / (t3 - t1)
|
|
319
|
-
];
|
|
320
|
-
for (let j = 0; j < s.length; j += 2) {
|
|
321
|
-
if (isNaN(s[j])) {
|
|
322
|
-
s[j] = 1;
|
|
323
|
-
s[j + 1] = 0;
|
|
324
|
-
}
|
|
325
|
-
if (!isFinite(s[j])) {
|
|
326
|
-
if (s[j] > 0) {
|
|
327
|
-
s[j] = 1;
|
|
328
|
-
s[j + 1] = 0;
|
|
329
|
-
} else {
|
|
330
|
-
s[j] = 0;
|
|
331
|
-
s[j + 1] = 1;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
let a1x = p0x * s[0] + p1x * s[1];
|
|
336
|
-
let a1y = p0y * s[0] + p1y * s[1];
|
|
337
|
-
let a2x = p1x * s[2] + p2x * s[3];
|
|
338
|
-
let a2y = p1y * s[2] + p2y * s[3];
|
|
339
|
-
let a3x = p2x * s[4] + p3x * s[5];
|
|
340
|
-
let a3y = p2y * s[4] + p3y * s[5];
|
|
341
|
-
let b1x = a1x * s[6] + a2x * s[7];
|
|
342
|
-
let b1y = a1y * s[6] + a2y * s[7];
|
|
343
|
-
let b2x = a2x * s[8] + a3x * s[9];
|
|
344
|
-
let b2y = a2y * s[8] + a3y * s[9];
|
|
345
|
-
let cx = b1x * s[2] + b2x * s[3];
|
|
346
|
-
let cy = b1y * s[2] + b2y * s[3];
|
|
347
|
-
pts.push([cx, cy]);
|
|
348
|
-
}
|
|
349
|
-
return pts;
|
|
350
|
-
}
|
|
351
301
|
|
|
352
302
|
$.curveVertex = (x, y) => {
|
|
353
303
|
if ($._da) {
|
|
@@ -356,20 +306,24 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
356
306
|
}
|
|
357
307
|
curveBuff.push([x, y]);
|
|
358
308
|
if (curveBuff.length < 4) return;
|
|
359
|
-
|
|
360
|
-
let
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
309
|
+
|
|
310
|
+
let p0 = curveBuff.at(-4),
|
|
311
|
+
p1 = curveBuff.at(-3),
|
|
312
|
+
p2 = curveBuff.at(-2),
|
|
313
|
+
p3 = curveBuff.at(-1);
|
|
314
|
+
|
|
315
|
+
let cp1x = p1[0] + (p2[0] - p0[0]) / 6,
|
|
316
|
+
cp1y = p1[1] + (p2[1] - p0[1]) / 6,
|
|
317
|
+
cp2x = p2[0] - (p3[0] - p1[0]) / 6,
|
|
318
|
+
cp2y = p2[1] - (p3[1] - p1[1]) / 6;
|
|
319
|
+
|
|
320
|
+
if (firstVertex) {
|
|
321
|
+
$.ctx.moveTo(p1[0], p1[1]);
|
|
370
322
|
firstVertex = false;
|
|
371
323
|
}
|
|
324
|
+
$.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, p2[0], p2[1]);
|
|
372
325
|
};
|
|
326
|
+
|
|
373
327
|
$.curve = (x1, y1, x2, y2, x3, y3, x4, y4) => {
|
|
374
328
|
$.beginShape();
|
|
375
329
|
$.curveVertex(x1, y1);
|
|
@@ -378,6 +332,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
378
332
|
$.curveVertex(x4, y4);
|
|
379
333
|
$.endShape();
|
|
380
334
|
};
|
|
335
|
+
|
|
381
336
|
$.curvePoint = (a, b, c, d, t) => {
|
|
382
337
|
const t3 = t * t * t,
|
|
383
338
|
t2 = t * t,
|
|
@@ -387,6 +342,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
387
342
|
f4 = 0.5 * t3 - 0.5 * t2;
|
|
388
343
|
return a * f1 + b * f2 + c * f3 + d * f4;
|
|
389
344
|
};
|
|
345
|
+
|
|
390
346
|
$.bezierPoint = (a, b, c, d, t) => {
|
|
391
347
|
const adjustedT = 1 - t;
|
|
392
348
|
return (
|
|
@@ -396,6 +352,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
396
352
|
Math.pow(t, 3) * d
|
|
397
353
|
);
|
|
398
354
|
};
|
|
355
|
+
|
|
399
356
|
$.curveTangent = (a, b, c, d, t) => {
|
|
400
357
|
const t2 = t * t,
|
|
401
358
|
f1 = (-3 * t2) / 2 + 2 * t - 0.5,
|
|
@@ -404,6 +361,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
404
361
|
f4 = (3 * t2) / 2 - t;
|
|
405
362
|
return a * f1 + b * f2 + c * f3 + d * f4;
|
|
406
363
|
};
|
|
364
|
+
|
|
407
365
|
$.bezierTangent = (a, b, c, d, t) => {
|
|
408
366
|
const adjustedT = 1 - t;
|
|
409
367
|
return (
|
package/src/q5-2d-image.js
CHANGED
package/src/q5-2d-text.js
CHANGED
|
@@ -36,6 +36,7 @@ Q5.renderers.q2d.text = ($, q) => {
|
|
|
36
36
|
fontMod = true;
|
|
37
37
|
styleHash = -1;
|
|
38
38
|
};
|
|
39
|
+
|
|
39
40
|
$.textSize = (x) => {
|
|
40
41
|
if (x == undefined || x == $._textSize) return $._textSize;
|
|
41
42
|
if ($._da) x *= $._da;
|
|
@@ -47,12 +48,14 @@ Q5.renderers.q2d.text = ($, q) => {
|
|
|
47
48
|
leadDiff = leading - x;
|
|
48
49
|
}
|
|
49
50
|
};
|
|
51
|
+
|
|
50
52
|
$.textStyle = (x) => {
|
|
51
53
|
if (!x || x == emphasis) return emphasis;
|
|
52
54
|
emphasis = x;
|
|
53
55
|
fontMod = true;
|
|
54
56
|
styleHash = -1;
|
|
55
57
|
};
|
|
58
|
+
|
|
56
59
|
$.textLeading = (x) => {
|
|
57
60
|
leadingSet = true;
|
|
58
61
|
if (x == undefined || x == leading) return leading;
|
|
@@ -61,6 +64,7 @@ Q5.renderers.q2d.text = ($, q) => {
|
|
|
61
64
|
leadDiff = x - $._textSize;
|
|
62
65
|
styleHash = -1;
|
|
63
66
|
};
|
|
67
|
+
|
|
64
68
|
$.textAlign = (horiz, vert) => {
|
|
65
69
|
$.ctx.textAlign = $._textAlign = horiz;
|
|
66
70
|
if (vert) {
|
|
@@ -90,6 +94,7 @@ Q5.renderers.q2d.text = ($, q) => {
|
|
|
90
94
|
if (enable !== undefined) useCache = enable;
|
|
91
95
|
return useCache;
|
|
92
96
|
};
|
|
97
|
+
|
|
93
98
|
$.createTextImage = (str, w, h) => {
|
|
94
99
|
genTextImage = true;
|
|
95
100
|
img = $.text(str, 0, 0, w, h);
|
|
@@ -98,6 +103,7 @@ Q5.renderers.q2d.text = ($, q) => {
|
|
|
98
103
|
};
|
|
99
104
|
|
|
100
105
|
let lines = [];
|
|
106
|
+
|
|
101
107
|
$.text = (str, x, y, w, h) => {
|
|
102
108
|
if (str === undefined || (!$._doFill && !$._doStroke)) return;
|
|
103
109
|
str = str.toString();
|
|
@@ -223,6 +229,7 @@ Q5.renderers.q2d.text = ($, q) => {
|
|
|
223
229
|
$.textImage(img, x, y);
|
|
224
230
|
}
|
|
225
231
|
};
|
|
232
|
+
|
|
226
233
|
$.textImage = (img, x, y) => {
|
|
227
234
|
if (typeof img == 'string') img = $.createTextImage(img);
|
|
228
235
|
|
package/src/q5-canvas.js
CHANGED
|
@@ -146,7 +146,7 @@ Q5.modules.canvas = ($, q) => {
|
|
|
146
146
|
return g;
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
async function saveFile(data, name, ext) {
|
|
150
150
|
name = name || 'untitled';
|
|
151
151
|
ext = ext || 'png';
|
|
152
152
|
if (ext == 'jpg' || ext == 'png' || ext == 'webp') {
|
|
@@ -174,18 +174,19 @@ Q5.modules.canvas = ($, q) => {
|
|
|
174
174
|
a.download = name + '.' + ext;
|
|
175
175
|
a.click();
|
|
176
176
|
URL.revokeObjectURL(a.href);
|
|
177
|
-
}
|
|
177
|
+
}
|
|
178
|
+
|
|
178
179
|
$.save = (a, b, c) => {
|
|
179
180
|
if (!a || (typeof a == 'string' && (!b || (!c && b.length < 5)))) {
|
|
180
181
|
c = b;
|
|
181
182
|
b = a;
|
|
182
183
|
a = $.canvas;
|
|
183
184
|
}
|
|
184
|
-
if (c) return
|
|
185
|
+
if (c) return saveFile(a, b, c);
|
|
185
186
|
if (b) {
|
|
186
187
|
b = b.split('.');
|
|
187
|
-
|
|
188
|
-
} else
|
|
188
|
+
saveFile(a, b[0], b.at(-1));
|
|
189
|
+
} else saveFile(a);
|
|
189
190
|
};
|
|
190
191
|
|
|
191
192
|
$._setCanvasSize = (w, h) => {
|
package/src/q5-color.js
CHANGED
|
@@ -146,6 +146,7 @@ Q5.Color = class {
|
|
|
146
146
|
this._q5Color = true;
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
|
+
|
|
149
150
|
Q5.ColorOKLCH = class extends Q5.Color {
|
|
150
151
|
constructor(l, c, h, a) {
|
|
151
152
|
super();
|
|
@@ -158,6 +159,7 @@ Q5.ColorOKLCH = class extends Q5.Color {
|
|
|
158
159
|
return `oklch(${this.l} ${this.c} ${this.h} / ${this.a})`;
|
|
159
160
|
}
|
|
160
161
|
};
|
|
162
|
+
|
|
161
163
|
Q5.ColorRGBA = class extends Q5.Color {
|
|
162
164
|
constructor(r, g, b, a) {
|
|
163
165
|
super();
|
|
@@ -173,11 +175,13 @@ Q5.ColorRGBA = class extends Q5.Color {
|
|
|
173
175
|
return `color(srgb ${this.r} ${this.g} ${this.b} / ${this.a})`;
|
|
174
176
|
}
|
|
175
177
|
};
|
|
178
|
+
|
|
176
179
|
Q5.ColorRGBA_P3 = class extends Q5.ColorRGBA {
|
|
177
180
|
toString() {
|
|
178
181
|
return `color(display-p3 ${this.r} ${this.g} ${this.b} / ${this.a})`;
|
|
179
182
|
}
|
|
180
183
|
};
|
|
184
|
+
|
|
181
185
|
// legacy 8-bit (0-255) integer color format
|
|
182
186
|
Q5.ColorRGBA_8 = class extends Q5.ColorRGBA {
|
|
183
187
|
constructor(r, g, b, a) {
|
|
@@ -202,6 +206,7 @@ Q5.ColorRGBA_8 = class extends Q5.ColorRGBA {
|
|
|
202
206
|
return `rgb(${this.r} ${this.g} ${this.b} / ${this.a / 255})`;
|
|
203
207
|
}
|
|
204
208
|
};
|
|
209
|
+
|
|
205
210
|
// p3 10-bit color in integer color format, for backwards compatibility
|
|
206
211
|
Q5.ColorRGBA_P3_8 = class extends Q5.ColorRGBA {
|
|
207
212
|
constructor(r, g, b, a) {
|
package/src/q5-core.js
CHANGED
|
@@ -9,7 +9,12 @@ function Q5(scope, parent, renderer) {
|
|
|
9
9
|
let $ = this;
|
|
10
10
|
$._q5 = true;
|
|
11
11
|
$._parent = parent;
|
|
12
|
-
|
|
12
|
+
if (renderer == 'webgpu-fallback') {
|
|
13
|
+
$._webgpuFallback = true;
|
|
14
|
+
$._renderer = 'q2d';
|
|
15
|
+
} else {
|
|
16
|
+
$._renderer = renderer || 'q2d';
|
|
17
|
+
}
|
|
13
18
|
$._preloadCount = 0;
|
|
14
19
|
|
|
15
20
|
let autoLoaded = scope == 'auto';
|
|
@@ -172,6 +177,11 @@ function Q5(scope, parent, renderer) {
|
|
|
172
177
|
delete Q5.Q5;
|
|
173
178
|
}
|
|
174
179
|
|
|
180
|
+
if ($._webgpuFallback) {
|
|
181
|
+
$.colorMode('rgb', 1);
|
|
182
|
+
$._beginRender = () => $.translate($.canvas.hw, $.canvas.hh);
|
|
183
|
+
}
|
|
184
|
+
|
|
175
185
|
for (let m of Q5.methods.init) {
|
|
176
186
|
m.call($);
|
|
177
187
|
}
|
package/src/q5-input.js
CHANGED
|
@@ -59,6 +59,7 @@ Q5.modules.input = ($, q) => {
|
|
|
59
59
|
q.moveX = e.movementX;
|
|
60
60
|
q.moveY = e.movementY;
|
|
61
61
|
};
|
|
62
|
+
|
|
62
63
|
$._onmousedown = (e) => {
|
|
63
64
|
$._startAudio();
|
|
64
65
|
$._updateMouse(e);
|
|
@@ -66,22 +67,26 @@ Q5.modules.input = ($, q) => {
|
|
|
66
67
|
q.mouseButton = mouseBtns[e.button];
|
|
67
68
|
$.mousePressed(e);
|
|
68
69
|
};
|
|
70
|
+
|
|
69
71
|
$._onmousemove = (e) => {
|
|
70
72
|
$._updateMouse(e);
|
|
71
73
|
if ($.mouseIsPressed) $.mouseDragged(e);
|
|
72
74
|
else $.mouseMoved(e);
|
|
73
75
|
};
|
|
76
|
+
|
|
74
77
|
$._onmouseup = (e) => {
|
|
75
78
|
$._updateMouse(e);
|
|
76
79
|
q.mouseIsPressed = false;
|
|
77
80
|
$.mouseReleased(e);
|
|
78
81
|
};
|
|
82
|
+
|
|
79
83
|
$._onclick = (e) => {
|
|
80
84
|
$._updateMouse(e);
|
|
81
85
|
q.mouseIsPressed = true;
|
|
82
86
|
$.mouseClicked(e);
|
|
83
87
|
q.mouseIsPressed = false;
|
|
84
88
|
};
|
|
89
|
+
|
|
85
90
|
$._onwheel = (e) => {
|
|
86
91
|
$._updateMouse(e);
|
|
87
92
|
e.delta = e.deltaY;
|
|
@@ -99,9 +104,11 @@ Q5.modules.input = ($, q) => {
|
|
|
99
104
|
}
|
|
100
105
|
$.canvas.style.cursor = name + pfx;
|
|
101
106
|
};
|
|
107
|
+
|
|
102
108
|
$.noCursor = () => {
|
|
103
109
|
$.canvas.style.cursor = 'none';
|
|
104
110
|
};
|
|
111
|
+
|
|
105
112
|
if (window) {
|
|
106
113
|
$.requestPointerLock = document.body?.requestPointerLock;
|
|
107
114
|
$.exitPointerLock = document.exitPointerLock;
|
|
@@ -117,6 +124,7 @@ Q5.modules.input = ($, q) => {
|
|
|
117
124
|
$.keyPressed(e);
|
|
118
125
|
if (e.key.length == 1) $.keyTyped(e);
|
|
119
126
|
};
|
|
127
|
+
|
|
120
128
|
$._onkeyup = (e) => {
|
|
121
129
|
q.keyIsPressed = false;
|
|
122
130
|
q.key = e.key;
|
|
@@ -124,6 +132,7 @@ Q5.modules.input = ($, q) => {
|
|
|
124
132
|
keysHeld[$.keyCode] = keysHeld[$.key.toLowerCase()] = false;
|
|
125
133
|
$.keyReleased(e);
|
|
126
134
|
};
|
|
135
|
+
|
|
127
136
|
$.keyIsDown = (v) => !!keysHeld[typeof v == 'string' ? v.toLowerCase() : v];
|
|
128
137
|
|
|
129
138
|
function getTouchInfo(touch) {
|
|
@@ -136,6 +145,7 @@ Q5.modules.input = ($, q) => {
|
|
|
136
145
|
id: touch.identifier
|
|
137
146
|
};
|
|
138
147
|
}
|
|
148
|
+
|
|
139
149
|
$._ontouchstart = (e) => {
|
|
140
150
|
$._startAudio();
|
|
141
151
|
q.touches = [...e.touches].map(getTouchInfo);
|
|
@@ -148,6 +158,7 @@ Q5.modules.input = ($, q) => {
|
|
|
148
158
|
}
|
|
149
159
|
if (!$.touchStarted(e)) e.preventDefault();
|
|
150
160
|
};
|
|
161
|
+
|
|
151
162
|
$._ontouchmove = (e) => {
|
|
152
163
|
q.touches = [...e.touches].map(getTouchInfo);
|
|
153
164
|
if (!$._isTouchAware) {
|
|
@@ -157,6 +168,7 @@ Q5.modules.input = ($, q) => {
|
|
|
157
168
|
}
|
|
158
169
|
if (!$.touchMoved(e)) e.preventDefault();
|
|
159
170
|
};
|
|
171
|
+
|
|
160
172
|
$._ontouchend = (e) => {
|
|
161
173
|
q.touches = [...e.touches].map(getTouchInfo);
|
|
162
174
|
if (!$._isTouchAware && !$.touches.length) {
|
package/src/q5-math.js
CHANGED
|
@@ -42,13 +42,15 @@ Q5.modules.math = ($, q) => {
|
|
|
42
42
|
return Math.min(Math.max(val, ostop), ostart);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
$.constrain = (x, lo, hi) => Math.min(Math.max(x, lo), hi);
|
|
45
|
+
|
|
47
46
|
$.dist = function () {
|
|
48
47
|
let a = arguments;
|
|
49
48
|
if (a.length == 4) return Math.hypot(a[0] - a[2], a[1] - a[3]);
|
|
50
49
|
else return Math.hypot(a[0] - a[3], a[1] - a[4], a[2] - a[5]);
|
|
51
50
|
};
|
|
51
|
+
|
|
52
|
+
$.lerp = (a, b, t) => a * (1 - t) + b * t;
|
|
53
|
+
$.constrain = (x, lo, hi) => Math.min(Math.max(x, lo), hi);
|
|
52
54
|
$.norm = (value, start, stop) => $.map(value, start, stop, 0, 1);
|
|
53
55
|
$.sq = (x) => x * x;
|
|
54
56
|
$.fract = (x) => x - Math.floor(x);
|
|
@@ -69,7 +71,6 @@ Q5.modules.math = ($, q) => {
|
|
|
69
71
|
let a = Math.atan(x);
|
|
70
72
|
return !angleMode ? a : a * RADTODEG;
|
|
71
73
|
};
|
|
72
|
-
|
|
73
74
|
$.atan2 = (y, x) => {
|
|
74
75
|
let a = Math.atan2(y, x);
|
|
75
76
|
return !angleMode ? a : a * RADTODEG;
|
|
@@ -93,6 +94,7 @@ Q5.modules.math = ($, q) => {
|
|
|
93
94
|
}
|
|
94
95
|
};
|
|
95
96
|
}
|
|
97
|
+
|
|
96
98
|
function shr3() {
|
|
97
99
|
let jsr, seed;
|
|
98
100
|
let m = 4294967295;
|
|
@@ -111,6 +113,7 @@ Q5.modules.math = ($, q) => {
|
|
|
111
113
|
}
|
|
112
114
|
};
|
|
113
115
|
}
|
|
116
|
+
|
|
114
117
|
let rng1 = shr3();
|
|
115
118
|
rng1.setSeed();
|
|
116
119
|
|
|
@@ -127,6 +130,7 @@ Q5.modules.math = ($, q) => {
|
|
|
127
130
|
return a[Math.trunc(a.length * rng1.rand())];
|
|
128
131
|
}
|
|
129
132
|
};
|
|
133
|
+
|
|
130
134
|
$.randomGenerator = (method) => {
|
|
131
135
|
if (method == $.LCG) rng1 = lcg();
|
|
132
136
|
else if (method == $.SHR3) rng1 = shr3();
|
|
@@ -282,13 +286,16 @@ Q5.modules.math = ($, q) => {
|
|
|
282
286
|
q.Noise = Q5[mode[0].toUpperCase() + mode.slice(1) + 'Noise'];
|
|
283
287
|
_noise = null;
|
|
284
288
|
};
|
|
289
|
+
|
|
285
290
|
$.noiseSeed = (seed) => {
|
|
286
291
|
_noise = new $.Noise(seed);
|
|
287
292
|
};
|
|
293
|
+
|
|
288
294
|
$.noise = (x = 0, y = 0, z = 0) => {
|
|
289
295
|
_noise ??= new $.Noise();
|
|
290
296
|
return _noise.noise(x, y, z);
|
|
291
297
|
};
|
|
298
|
+
|
|
292
299
|
$.noiseDetail = (lod, falloff) => {
|
|
293
300
|
_noise ??= new $.Noise();
|
|
294
301
|
if (lod > 0) _noise.octaves = lod;
|
package/src/q5-record.js
ADDED