p5 2.2.1-rc.0 → 2.2.1

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.
Files changed (117) hide show
  1. package/dist/accessibility/color_namer.js +5 -6
  2. package/dist/accessibility/describe.js +4 -26
  3. package/dist/accessibility/index.js +5 -6
  4. package/dist/accessibility/outputs.js +6 -38
  5. package/dist/app.js +5 -6
  6. package/dist/color/color_conversion.js +5 -6
  7. package/dist/color/creating_reading.js +1 -1
  8. package/dist/color/index.js +2 -2
  9. package/dist/color/p5.Color.js +1 -1
  10. package/dist/color/setting.js +59 -357
  11. package/dist/{constants-DEJVKr9Z.js → constants-DQyACdzq.js} +11 -61
  12. package/dist/core/constants.js +1 -1
  13. package/dist/core/environment.js +26 -158
  14. package/dist/core/filterShaders.js +1 -1
  15. package/dist/core/friendly_errors/fes_core.js +1 -1
  16. package/dist/core/friendly_errors/file_errors.js +1 -1
  17. package/dist/core/friendly_errors/index.js +1 -1
  18. package/dist/core/friendly_errors/param_validator.js +1 -1
  19. package/dist/core/friendly_errors/sketch_verifier.js +1 -1
  20. package/dist/core/helpers.js +1 -1
  21. package/dist/core/init.js +5 -6
  22. package/dist/core/internationalization.js +1 -1
  23. package/dist/core/legacy.js +5 -6
  24. package/dist/core/main.js +5 -6
  25. package/dist/core/p5.Graphics.js +4 -5
  26. package/dist/core/p5.Renderer.js +3 -4
  27. package/dist/core/p5.Renderer2D.js +5 -6
  28. package/dist/core/p5.Renderer3D.js +4 -5
  29. package/dist/core/rendering.js +4 -5
  30. package/dist/core/structure.js +13 -52
  31. package/dist/core/transform.js +32 -176
  32. package/dist/{creating_reading-CgHCHxqN.js → creating_reading-ZXzcZEsb.js} +3 -196
  33. package/dist/data/local_storage.js +4 -30
  34. package/dist/dom/dom.js +24 -159
  35. package/dist/dom/index.js +2 -2
  36. package/dist/dom/p5.Element.js +31 -208
  37. package/dist/dom/p5.File.js +1 -32
  38. package/dist/dom/p5.MediaElement.js +10 -113
  39. package/dist/events/acceleration.js +11 -64
  40. package/dist/events/keyboard.js +13 -81
  41. package/dist/events/pointer.js +18 -160
  42. package/dist/image/const.js +1 -1
  43. package/dist/image/filterRenderer2D.js +4 -5
  44. package/dist/image/image.js +4 -5
  45. package/dist/image/index.js +4 -5
  46. package/dist/image/loading_displaying.js +4 -5
  47. package/dist/image/p5.Image.js +3 -4
  48. package/dist/image/pixels.js +17 -100
  49. package/dist/io/files.js +4 -5
  50. package/dist/io/index.js +4 -5
  51. package/dist/io/p5.Table.js +66 -158
  52. package/dist/io/p5.TableRow.js +48 -71
  53. package/dist/io/p5.XML.js +6 -99
  54. package/dist/io/utilities.js +8 -3
  55. package/dist/{main-_RXV5Lx8.js → main-DvN69W3f.js} +13 -42
  56. package/dist/math/Matrices/Matrix.js +87 -126
  57. package/dist/math/Matrices/MatrixNumjs.js +1 -5
  58. package/dist/math/calculation.js +10 -112
  59. package/dist/math/index.js +1 -1
  60. package/dist/math/math.js +2 -12
  61. package/dist/math/noise.js +5 -32
  62. package/dist/math/p5.Matrix.js +3 -3
  63. package/dist/math/p5.Vector.js +104 -345
  64. package/dist/math/random.js +5 -32
  65. package/dist/math/trigonometry.js +15 -105
  66. package/dist/{p5.Renderer-QoFcvj3f.js → p5.Renderer-D-5LdCRz.js} +25 -178
  67. package/dist/{rendering-CsICjEXA.js → rendering-h9unX5K0.js} +254 -1156
  68. package/dist/shape/2d_primitives.js +33 -194
  69. package/dist/shape/attributes.js +12 -73
  70. package/dist/shape/curves.js +30 -95
  71. package/dist/shape/custom_shapes.js +63 -144
  72. package/dist/shape/index.js +2 -2
  73. package/dist/shape/vertex.js +21 -106
  74. package/dist/strands/p5.strands.js +248 -46
  75. package/dist/type/index.js +3 -4
  76. package/dist/type/p5.Font.js +4 -49
  77. package/dist/type/textCore.js +5 -158
  78. package/dist/utilities/conversion.js +17 -104
  79. package/dist/utilities/time_date.js +3 -40
  80. package/dist/utilities/utility_functions.js +6 -48
  81. package/dist/webgl/3d_primitives.js +4 -5
  82. package/dist/webgl/GeometryBuilder.js +1 -2
  83. package/dist/webgl/ShapeBuilder.js +22 -2
  84. package/dist/webgl/enums.js +1 -1
  85. package/dist/webgl/index.js +4 -5
  86. package/dist/webgl/interaction.js +6 -33
  87. package/dist/webgl/light.js +4 -5
  88. package/dist/webgl/loading.js +12 -46
  89. package/dist/webgl/material.js +4 -5
  90. package/dist/webgl/p5.Camera.js +4 -5
  91. package/dist/webgl/p5.DataArray.js +0 -4
  92. package/dist/webgl/p5.Framebuffer.js +4 -5
  93. package/dist/webgl/p5.Geometry.js +12 -106
  94. package/dist/webgl/p5.Quat.js +1 -1
  95. package/dist/webgl/p5.RendererGL.js +7 -18
  96. package/dist/webgl/p5.Shader.js +12 -36
  97. package/dist/webgl/p5.Texture.js +4 -5
  98. package/dist/webgl/text.js +4 -5
  99. package/dist/webgl/utils.js +4 -5
  100. package/dist/webgpu/index.js +1 -1
  101. package/dist/webgpu/p5.RendererWebGPU.js +529 -208
  102. package/dist/webgpu/shaders/color.js +32 -17
  103. package/dist/webgpu/shaders/filters/base.js +18 -7
  104. package/dist/webgpu/shaders/font.js +52 -40
  105. package/dist/webgpu/shaders/line.js +50 -36
  106. package/dist/webgpu/shaders/material.js +90 -83
  107. package/dist/webgpu/strands_wgslBackend.js +5 -2
  108. package/lib/p5.esm.js +5576 -7811
  109. package/lib/p5.esm.min.js +1 -1
  110. package/lib/p5.js +5576 -7811
  111. package/lib/p5.min.js +1 -1
  112. package/lib/p5.webgpu.esm.js +786 -453
  113. package/lib/p5.webgpu.js +786 -453
  114. package/lib/p5.webgpu.min.js +1 -1
  115. package/package.json +13 -13
  116. package/types/global.d.ts +16905 -16783
  117. package/types/p5.d.ts +11142 -11081
@@ -1,6 +1,6 @@
1
1
  import { Vector } from '../p5.Vector.js';
2
2
  import { MatrixInterface } from './MatrixInterface.js';
3
- import '../../constants-DEJVKr9Z.js';
3
+ import '../../constants-DQyACdzq.js';
4
4
 
5
5
  /**
6
6
  * @module Math
@@ -81,20 +81,19 @@ class Matrix extends MatrixInterface {
81
81
  * @throws {Error} If the matrices do not have the same dimensions.
82
82
  *
83
83
  * @example
84
+ * // META:norender
84
85
  * const matrix1 = new p5.Matrix([1, 2, 3]);
85
86
  * const matrix2 = new p5.Matrix([4, 5, 6]);
86
87
  * matrix1.add(matrix2); // matrix1 is now [5, 7, 9]
87
88
  *
88
- * // p5.js script example
89
- * <div class="norender"><code>
89
+ * @example
90
+ * // META:norender
90
91
  * function setup() {
91
- *
92
92
  * const matrix1 = new p5.Matrix([1, 2, 3, 4]);
93
93
  * const matrix2 = new p5.Matrix([5, 6, 7, 8]);
94
94
  * matrix1.add(matrix2);
95
95
  * console.log(matrix1.matrix); // Output: [6, 8, 10, 12]
96
96
  * }
97
- * </code></div>
98
97
  */
99
98
  add(matrix) {
100
99
  if (this.matrix.length !== matrix.matrix.length) {
@@ -147,18 +146,14 @@ class Matrix extends MatrixInterface {
147
146
  * @returns {Matrix} The current instance of the Matrix, allowing for method chaining.
148
147
  *
149
148
  * @example
149
+ * // META:norender
150
150
  * // Assuming matrix is an instance of Matrix with initial values [1, 2, 3, 4] matrix.setElement(2, 99);
151
151
  * // Now the matrix values are [1, 2, 99, 4]
152
- *
153
- * // p5.js script example
154
- * <div class="norender"><code>
155
152
  * function setup() {
156
- *
157
153
  * const matrix = new p5.Matrix([1, 2, 3, 4]);
158
154
  * matrix.setElement(2, 99);
159
155
  * console.log(matrix.matrix); // Output: [1, 2, 99, 4]
160
156
  * }
161
- * </code></div>
162
157
  */
163
158
  setElement(index, value) {
164
159
  if (index >= 0 && index < this.matrix.length) {
@@ -177,6 +172,7 @@ class Matrix extends MatrixInterface {
177
172
  * @returns {Matrix} The current instance of the Matrix class, allowing for method chaining.
178
173
  *
179
174
  * @example
175
+ * // META:norender
180
176
  * // Resetting a 4x4 matrix to an identity matrix
181
177
  * const matrix = new p5.Matrix(4);
182
178
  * matrix.scale(2, 2, 2); // Apply some transformations
@@ -184,17 +180,15 @@ class Matrix extends MatrixInterface {
184
180
  * matrix.reset(); // Reset to identity matrix
185
181
  * console.log(matrix.matrix); // Output: Identity matrix
186
182
  *
187
- * // p5.js script example
188
- * <div class="norender"><code>
183
+ * @example
184
+ * // META:norender
189
185
  * function setup() {
190
- *
191
186
  * const matrix = new p5.Matrix(4);
192
187
  * matrix.scale(2, 2, 2); // Apply scaling transformation
193
188
  * console.log("Before reset:", matrix.matrix);
194
189
  * matrix.reset(); // Reset to identity matrix
195
190
  * console.log("After reset:", matrix.matrix);
196
191
  * }
197
- * </code></div>
198
192
  */
199
193
  reset() {
200
194
  this.matrix = this.#createIdentityMatrix(this.#sqDimention);
@@ -220,6 +214,7 @@ class Matrix extends MatrixInterface {
220
214
  * method chaining.
221
215
  *
222
216
  * @example
217
+ * // META:norender
223
218
  * // Replacing the contents of a matrix with another matrix
224
219
  * const matrix1 = new p5.Matrix([1, 2, 3, 4]);
225
220
  * const matrix2 = new p5.Matrix([5, 6, 7, 8]);
@@ -236,16 +231,14 @@ class Matrix extends MatrixInterface {
236
231
  * matrix.set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
237
232
  * console.log(matrix.matrix); // Output: [1, 2, 3, ..., 16]
238
233
  *
239
- * // p5.js script example
240
- * <div class="norender"><code>
234
+ * @example
235
+ * // META:norender
241
236
  * function setup() {
242
- *
243
237
  * const matrix = new p5.Matrix([1, 2, 3, 4]);
244
238
  * console.log("Before set:", matrix.matrix);
245
239
  * matrix.set([5, 6, 7, 8]);
246
240
  * console.log("After set:", matrix.matrix); // Output: [5, 6, 7, 8]
247
241
  * }
248
- * </code></div>
249
242
  */
250
243
  set(inMatrix) {
251
244
  let refArray = GLMAT_ARRAY_TYPE.from([...arguments]);
@@ -279,10 +272,8 @@ class Matrix extends MatrixInterface {
279
272
  * same values as the original matrix.
280
273
  *
281
274
  * @example
282
- * // p5.js script example
283
- * <div class="norender"><code>
275
+ * // META:norender
284
276
  * function setup() {
285
- *
286
277
  * const originalMatrix = new p5.Matrix([1, 2, 3, 4]);
287
278
  * const copiedMatrix = originalMatrix.get();
288
279
  * console.log("Original Matrix:", originalMatrix.matrix); // Output: [1, 2, 3, 4]
@@ -293,7 +284,6 @@ class Matrix extends MatrixInterface {
293
284
  * console.log("Modified Copied Matrix:", copiedMatrix.matrix); // Output: [1, 2, 99, 4]
294
285
  * console.log("Original Matrix remains unchanged:", originalMatrix.matrix); // Output: [1, 2, 3, 4]
295
286
  * }
296
- * </code></div>
297
287
  */
298
288
  get() {
299
289
  return new Matrix(this.matrix); // TODO: Pass p5
@@ -311,10 +301,8 @@ class Matrix extends MatrixInterface {
311
301
  * @return {p5.Matrix} The result matrix.
312
302
  *
313
303
  * @example
314
- * // p5.js script example
315
- * <div class="norender"><code>
304
+ * // META:norender
316
305
  * function setup() {
317
- *
318
306
  * const originalMatrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
319
307
  * const copiedMatrix = originalMatrix.copy();
320
308
  * console.log("Original Matrix:", originalMatrix.matrix);
@@ -325,7 +313,6 @@ class Matrix extends MatrixInterface {
325
313
  * console.log("Modified Copied Matrix:", copiedMatrix.matrix);
326
314
  * console.log("Original Matrix remains unchanged:", originalMatrix.matrix);
327
315
  * }
328
- * </code></div>
329
316
  */
330
317
  copy() {
331
318
  return new Matrix(this.matrix);
@@ -339,10 +326,8 @@ class Matrix extends MatrixInterface {
339
326
  * @returns {Matrix} A new matrix instance that is a copy of the current matrix.
340
327
  *
341
328
  * @example
342
- * // p5.js script example
343
- * <div class="norender"><code>
329
+ * // META:norender
344
330
  * function setup() {
345
- *
346
331
  * const originalMatrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
347
332
  * const clonedMatrix = originalMatrix.clone();
348
333
  * console.log("Original Matrix:", originalMatrix.matrix);
@@ -353,7 +338,6 @@ class Matrix extends MatrixInterface {
353
338
  * console.log("Modified Cloned Matrix:", clonedMatrix.matrix);
354
339
  * console.log("Original Matrix remains unchanged:", originalMatrix.matrix);
355
340
  * }
356
- * </code></div>
357
341
  */
358
342
  clone() {
359
343
  return this.copy();
@@ -382,19 +366,18 @@ class Matrix extends MatrixInterface {
382
366
  * of the matrix in ascending order of index.
383
367
  *
384
368
  * @example
369
+ * // META:norender
385
370
  * // Extracting the diagonal elements of a matrix
386
371
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
387
372
  * const diagonal = matrix.diagonal(); // [1, 5, 9]
388
373
  *
389
- * // p5.js script example
390
- * <div class="norender"><code>
374
+ * @example
375
+ * // META:norender
391
376
  * function setup() {
392
- *
393
377
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
394
378
  * const diagonal = matrix.diagonal();
395
379
  * console.log("Diagonal elements:", diagonal); // Output: [1, 5, 9]
396
380
  * }
397
- * </code></div>
398
381
  */
399
382
  diagonal() {
400
383
  const diagonal = [];
@@ -417,19 +400,18 @@ class Matrix extends MatrixInterface {
417
400
  * @return {p5.Vector} A `p5.Vector` representing the extracted row of the matrix.
418
401
  *
419
402
  * @example
403
+ * // META:norender
420
404
  * // Extracting a row vector from a 3x3 matrix
421
405
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
422
406
  * const rowVector = matrix.row(1); // Returns a vector [2, 5, 8]
423
407
  *
424
- * // p5.js script example
425
- * <div class="norender"><code>
408
+ * @example
409
+ * // META:norender
426
410
  * function setup() {
427
- *
428
411
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
429
412
  * const rowVector = matrix.row(1); // Extract the second row (index 1)
430
413
  * console.log("Row Vector:", rowVector.toString()); // Output: Row Vector: [2, 5, 8]
431
414
  * }
432
- * </code></div>
433
415
  */
434
416
  row(columnIndex) {
435
417
  const columnVector = [];
@@ -452,19 +434,18 @@ class Matrix extends MatrixInterface {
452
434
  * @return {p5.Vector} A `p5.Vector` representing the extracted column of the matrix.
453
435
  *
454
436
  * @example
437
+ * // META:norender
455
438
  * // Extracting a column vector from a 3x3 matrix
456
439
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
457
440
  * const columnVector = matrix.column(1); // Returns a vector [4, 5, 6]
458
441
  *
459
- * // p5.js script example
460
- * <div class="norender"><code>
442
+ * @example
443
+ * // META:norender
461
444
  * function setup() {
462
- *
463
445
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
464
446
  * const columnVector = matrix.column(1); // Extract the second column (index 1)
465
447
  * console.log("Column Vector:", columnVector.toString()); // Output: Column Vector: [4, 5, 6]
466
448
  * }
467
- * </code></div>
468
449
  */
469
450
  column(rowIndex) {
470
451
  const rowVector = [];
@@ -489,6 +470,7 @@ class Matrix extends MatrixInterface {
489
470
  * @returns {Matrix} - The current instance of the Matrix class, allowing for method chaining.
490
471
  *
491
472
  * @example
473
+ * // META:norender
492
474
  * // Transposing a 3x3 matrix
493
475
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
494
476
  * matrix.transpose();
@@ -499,16 +481,14 @@ class Matrix extends MatrixInterface {
499
481
  * matrix4x4.transpose();
500
482
  * console.log(matrix4x4.matrix); // Output: Transposed 4x4 identity matrix
501
483
  *
502
- * // p5.js script example
503
- * <div class="norender"><code>
484
+ * @example
485
+ * // META:norender
504
486
  * function setup() {
505
- *
506
487
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
507
488
  * console.log("Before transpose:", matrix.matrix);
508
489
  * matrix.transpose();
509
490
  * console.log("After transpose:", matrix.matrix); // Output: [1, 4, 7, 2, 5, 8, 3, 6, 9]
510
491
  * }
511
- * </code></div>
512
492
  */
513
493
  transpose(a) {
514
494
  if (this.#sqDimention === 4) {
@@ -538,6 +518,7 @@ class Matrix extends MatrixInterface {
538
518
  * @chainable
539
519
  *
540
520
  * @example
521
+ * // META:norender
541
522
  * // Multiplying two 3x3 matrices
542
523
  * const matrix1 = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
543
524
  * const matrix2 = new p5.Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1]);
@@ -550,17 +531,15 @@ class Matrix extends MatrixInterface {
550
531
  * matrix4x4_1.mult(matrix4x4_2);
551
532
  * console.log(matrix4x4_1.matrix); // Output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1]
552
533
  *
553
- * // p5.js script example
554
- * <div class="norender"><code>
534
+ * @example
535
+ * // META:norender
555
536
  * function setup() {
556
- *
557
537
  * const matrix1 = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
558
538
  * const matrix2 = new p5.Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1]);
559
539
  * console.log("Before multiplication:", matrix1.matrix);
560
540
  * matrix1.mult(matrix2);
561
541
  * console.log("After multiplication:", matrix1.matrix); // Output: [30, 24, 18, 84, 69, 54, 138, 114, 90]
562
542
  * }
563
- * </code></div>
564
543
  */
565
544
  mult(multMatrix) {
566
545
  let _src;
@@ -595,23 +574,22 @@ class Matrix extends MatrixInterface {
595
574
  * @return {p5.Vector} - The transformed vector after applying the matrix.
596
575
  *
597
576
  * @example
577
+ * // META:norender
598
578
  * // Multiplying a 3x3 matrix with a vector
599
579
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
600
580
  * const vector = new p5.Vector(1, 2, 3);
601
581
  * const result = matrix.multiplyVec(vector);
602
582
  * console.log(result.toString()); // Output: Transformed vector
603
583
  *
604
- * // p5.js script example
605
- * <div class="norender"><code>
584
+ * @example
585
+ * // META:norender
606
586
  * function setup() {
607
- *
608
587
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
609
588
  * const vector = new p5.Vector(1, 2, 3);
610
589
  * const result = matrix.multiplyVec(vector);
611
590
  * console.log("Original Vector:", vector.toString()); // Output : Original Vector: [1, 2, 3]
612
591
  * console.log("Transformed Vector:", result.toString()); // Output : Transformed Vector: [30, 36, 42]
613
592
  * }
614
- * </code></div>
615
593
  */
616
594
  multiplyVec(multVector, target) {
617
595
  if (target === undefined) {
@@ -639,6 +617,7 @@ class Matrix extends MatrixInterface {
639
617
  * @throws {Error} - Throws an error if the matrix dimension is greater than 4.
640
618
  *
641
619
  * @example
620
+ * // META:norender
642
621
  * // Inverting a 3x3 matrix
643
622
  * const matrix = new p5.Matrix([1, 2, 3, 0, 1, 4, 5, 6, 0]);
644
623
  * const invertedMatrix = matrix.invert();
@@ -650,8 +629,8 @@ class Matrix extends MatrixInterface {
650
629
  * const invertedMatrix4x4 = matrix4x4.invert();
651
630
  * console.log(invertedMatrix4x4.matrix); // Output: Inverted 4x4 matrix
652
631
  *
653
- * // p5.js script example
654
- * <div class="norender"><code>
632
+ * @example
633
+ * // META:norender
655
634
  * function setup() {
656
635
  *
657
636
  * const matrix = new p5.Matrix([1, 2, 3, 0, 1, 4, 5, 6, 0]);
@@ -663,7 +642,6 @@ class Matrix extends MatrixInterface {
663
642
  * console.log("Matrix is singular and cannot be inverted.");
664
643
  * }
665
644
  * }
666
- * </code></div>
667
645
  */
668
646
  invert(a) {
669
647
  if (this.#sqDimention === 4) {
@@ -692,6 +670,7 @@ class Matrix extends MatrixInterface {
692
670
  * @throws {Error} If the current matrix is not 4x4.
693
671
  *
694
672
  * @example
673
+ * // META:norender
695
674
  * // Extracting a 3x3 submatrix from a 4x4 matrix
696
675
  * const matrix4x4 = new p5.Matrix(4); // Creates a 4x4 identity matrix
697
676
  * matrix4x4.scale(2, 2, 2); // Apply scaling transformation
@@ -699,10 +678,9 @@ class Matrix extends MatrixInterface {
699
678
  * console.log("Original 4x4 Matrix:", matrix4x4.matrix);
700
679
  * console.log("Extracted 3x3 Submatrix:", subMatrix3x3.matrix);
701
680
  *
702
- * // p5.js script example
703
- * <div class="norender"><code>
681
+ * @example
682
+ * // META:norender
704
683
  * function setup() {
705
- *
706
684
  * const matrix4x4 = new p5.Matrix(4); // Creates a 4x4 identity matrix
707
685
  * matrix4x4.scale(2, 2, 2); // Apply scaling transformation
708
686
  * console.log("Original 4x4 Matrix:", matrix4x4.matrix);
@@ -710,7 +688,6 @@ class Matrix extends MatrixInterface {
710
688
  * const subMatrix3x3 = matrix4x4.createSubMatrix3x3();
711
689
  * console.log("Extracted 3x3 Submatrix:", subMatrix3x3.matrix);
712
690
  * }
713
- * </code></div>
714
691
  */
715
692
  createSubMatrix3x3() {
716
693
  if (this.#sqDimention === 4) {
@@ -744,6 +721,7 @@ class Matrix extends MatrixInterface {
744
721
  * @throws {Error} If the current matrix is not 3×3.
745
722
  *
746
723
  * @example
724
+ * // META:norender
747
725
  * // Converting a 4×4 matrix to its 3×3 inverse transpose
748
726
  * const mat4 = new p5.Matrix(4); // Create a 4×4 identity matrix
749
727
  * mat4.scale(2, 2, 2); // Apply scaling transformation
@@ -751,10 +729,9 @@ class Matrix extends MatrixInterface {
751
729
  * mat3.inverseTranspose4x4(mat4);
752
730
  * console.log("Converted 3×3 Matrix:", mat3.matrix);
753
731
  *
754
- * // p5.js script example
755
- * <div class="norender"><code>
732
+ * @example
733
+ * // META:norender
756
734
  * function setup() {
757
- *
758
735
  * const mat4 = new p5.Matrix(4); // Create a 4×4 identity matrix
759
736
  * mat4.scale(2, 2, 2); // Apply scaling transformation
760
737
  * console.log("Original 4×4 Matrix:", mat4.matrix);
@@ -763,7 +740,6 @@ class Matrix extends MatrixInterface {
763
740
  * mat3.inverseTranspose4x4(mat4);
764
741
  * console.log("Converted 3×3 Matrix:", mat3.matrix);
765
742
  * }
766
- * </code></div>
767
743
  */
768
744
  inverseTranspose4x4({ mat4 }) {
769
745
  if (this.#sqDimention !== 3) {
@@ -812,20 +788,19 @@ class Matrix extends MatrixInterface {
812
788
  * @returns {Matrix} The current matrix after applying the transformation.
813
789
  *
814
790
  * @example
815
- * <div class="norender"><code>
791
+ * // META:norender
816
792
  * function setup() {
793
+ * // Assuming `matrix` is an instance of Matrix
794
+ * const anotherMatrix = new p5.Matrix(4);
795
+ * const anotherMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
796
+ * matrix.apply(anotherMatrix);
817
797
  *
818
- * // Assuming `matrix` is an instance of Matrix
819
- * const anotherMatrix = new p5.Matrix(4);
820
- * const anotherMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
821
- * matrix.apply(anotherMatrix);
798
+ * // Applying a transformation using an array
799
+ * const matrixArray = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
800
+ * matrix.apply(matrixArray);
822
801
  *
823
- * // Applying a transformation using an array
824
- * const matrixArray = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
825
- * matrix.apply(matrixArray);
826
- *
827
- * // Applying a transformation using individual arguments
828
- * matrix.apply(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
802
+ * // Applying a transformation using individual arguments
803
+ * matrix.apply(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
829
804
  *
830
805
  *
831
806
  * // Create a 4x4 identity matrix
@@ -844,7 +819,6 @@ class Matrix extends MatrixInterface {
844
819
  * matrix.apply(translationMatrix);
845
820
  * console.log("After Translation Transformation:", matrix.matrix);
846
821
  * }
847
- * </code></div>
848
822
  */
849
823
  apply(multMatrix) {
850
824
  let _src;
@@ -919,6 +893,7 @@ class Matrix extends MatrixInterface {
919
893
  * @returns {Matrix} The current instance of the Matrix class, allowing for method chaining.
920
894
  *
921
895
  * @example
896
+ * // META:norender
922
897
  * // Scaling a matrix by individual scalars
923
898
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
924
899
  * matrix.scale(2, 3, 4); // Scale by 2 along x, 3 along y, and 4 along z
@@ -934,10 +909,9 @@ class Matrix extends MatrixInterface {
934
909
  * matrix.scale(scaleArray);
935
910
  * console.log(matrix.matrix);
936
911
  *
937
- * // p5.js script example
938
- * <div class="norender"><code>
912
+ * @example
913
+ * // META:norender
939
914
  * function setup() {
940
- *
941
915
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
942
916
  * console.log("Original Matrix:", matrix.matrix);
943
917
  *
@@ -955,7 +929,6 @@ class Matrix extends MatrixInterface {
955
929
  * matrix.scale(scaleArray);
956
930
  * console.log("Scaled Matrix (Array):", matrix.matrix);
957
931
  * }
958
- * </code></div>
959
932
  */
960
933
  scale(x, y, z) {
961
934
  if (x instanceof Vector) {
@@ -1014,8 +987,7 @@ class Matrix extends MatrixInterface {
1014
987
  * inspired by Toji's gl-matrix lib, mat4 rotation
1015
988
  *
1016
989
  * @example
1017
- * // p5.js script example
1018
- * <div class="norender"><code>
990
+ * // META:norender
1019
991
  * function setup() {
1020
992
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1021
993
  * console.log("Original Matrix:", matrix.matrix.slice().toString()); // [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
@@ -1024,7 +996,6 @@ class Matrix extends MatrixInterface {
1024
996
  * matrix.rotate4x4(Math.PI, [1,0,0]);
1025
997
  * console.log("After rotation of PI degrees on vector [1,0,0]:", matrix.matrix.slice().toString()); // [1,0,0,0,0,-1,1.2246468525851679e-16,0,0,-1.2246468525851679e-16,-1,0,0,0,0,1]
1026
998
  * }
1027
- * </code></div>
1028
999
  */
1029
1000
  rotate4x4(a, x, y, z) {
1030
1001
  if (x instanceof Vector) {
@@ -1102,6 +1073,7 @@ class Matrix extends MatrixInterface {
1102
1073
  * @returns {Matrix} The current instance of the Matrix class, allowing for method chaining.
1103
1074
  *
1104
1075
  * @example
1076
+ * // META:norender
1105
1077
  * // Translating a matrix by a 3D vector
1106
1078
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1107
1079
  * matrix.translate([10, 20, 30]); // Translate by 10 units along x, 20 along y, and 30 along z
@@ -1111,8 +1083,8 @@ class Matrix extends MatrixInterface {
1111
1083
  * matrix.translate([5, 15]); // Translate by 5 units along x and 15 along y
1112
1084
  * console.log(matrix.matrix);
1113
1085
  *
1114
- * // p5.js script example
1115
- * <div class="norender"><code>
1086
+ * @example
1087
+ * // META:norender
1116
1088
  * function setup() {
1117
1089
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1118
1090
  * console.log("Original Matrix:", matrix.matrix.slice().toString()); // [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
@@ -1125,7 +1097,6 @@ class Matrix extends MatrixInterface {
1125
1097
  * matrix.translate([5, 15]);
1126
1098
  * console.log("After 2D Translation (5, 15):", matrix.matrix.slice().toString()); // [1,0,0,0,0,1,0,0,0,0,1,0,15,35,30,1]
1127
1099
  * }
1128
- * </code></div>
1129
1100
  */
1130
1101
  translate(v) {
1131
1102
  const x = v[0],
@@ -1155,15 +1126,15 @@ class Matrix extends MatrixInterface {
1155
1126
  * @param {Number} a - The angle in radians to rotate the matrix by.
1156
1127
  *
1157
1128
  * @example
1129
+ * // META:norender
1158
1130
  * // Rotating a matrix around the X-axis
1159
1131
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1160
1132
  * matrix.rotateX(Math.PI / 4); // Rotate 45 degrees around the X-axis
1161
1133
  * console.log(matrix.matrix);
1162
1134
  *
1163
- * // p5.js script example
1164
- * <div class="norender"><code>
1135
+ * @example
1136
+ * // META:norender
1165
1137
  * function setup() {
1166
- *
1167
1138
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1168
1139
  * console.log("Original Matrix:", matrix.matrix);
1169
1140
  *
@@ -1171,7 +1142,6 @@ class Matrix extends MatrixInterface {
1171
1142
  * matrix.rotateX(Math.PI / 4);
1172
1143
  * console.log("After Rotation (X-axis, 45 degrees):", matrix.matrix);
1173
1144
  * }
1174
- * </code></div>
1175
1145
  */
1176
1146
  rotateX(a) {
1177
1147
  this.rotate4x4(a, 1, 0, 0);
@@ -1192,15 +1162,15 @@ class Matrix extends MatrixInterface {
1192
1162
  * clockwise.
1193
1163
  *
1194
1164
  * @example
1165
+ * // META:norender
1195
1166
  * // Rotating a matrix around the Y-axis
1196
1167
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1197
1168
  * matrix.rotateY(Math.PI / 4); // Rotate 45 degrees around the Y-axis
1198
1169
  * console.log(matrix.matrix);
1199
1170
  *
1200
- * // p5.js script example
1201
- * <div class="norender"><code>
1171
+ * @example
1172
+ * // META:norender
1202
1173
  * function setup() {
1203
- *
1204
1174
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1205
1175
  * console.log("Original Matrix:", matrix.matrix);
1206
1176
  *
@@ -1208,7 +1178,6 @@ class Matrix extends MatrixInterface {
1208
1178
  * matrix.rotateY(Math.PI / 4);
1209
1179
  * console.log("After Rotation (Y-axis, 45 degrees):", matrix.matrix);
1210
1180
  * }
1211
- * </code></div>
1212
1181
  */
1213
1182
  rotateY(a) {
1214
1183
  this.rotate4x4(a, 0, 1, 0);
@@ -1231,15 +1200,15 @@ class Matrix extends MatrixInterface {
1231
1200
  * method chaining.
1232
1201
  *
1233
1202
  * @example
1203
+ * // META:norender
1234
1204
  * // Rotating a matrix around the Z-axis
1235
1205
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1236
1206
  * matrix.rotateZ(Math.PI / 4); // Rotate 45 degrees around the Z-axis
1237
1207
  * console.log(matrix.matrix);
1238
1208
  *
1239
- * // p5.js script example
1240
- * <div class="norender"><code>
1209
+ * @example
1210
+ * // META:norender
1241
1211
  * function setup() {
1242
- *
1243
1212
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1244
1213
  * console.log("Original Matrix:", matrix.matrix);
1245
1214
  *
@@ -1247,7 +1216,6 @@ class Matrix extends MatrixInterface {
1247
1216
  * matrix.rotateZ(Math.PI / 4);
1248
1217
  * console.log("After Rotation (Z-axis, 45 degrees):", matrix.matrix);
1249
1218
  * }
1250
- * </code></div>
1251
1219
  */
1252
1220
  rotateZ(a) {
1253
1221
  this.rotate4x4(a, 0, 0, 1);
@@ -1272,15 +1240,15 @@ class Matrix extends MatrixInterface {
1272
1240
  * @returns {Matrix} The current instance of the Matrix class, allowing for method chaining.
1273
1241
  *
1274
1242
  * @example
1243
+ * // META:norender
1275
1244
  * // Setting a perspective projection matrix
1276
1245
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1277
1246
  * matrix.perspective(Math.PI / 4, 1.5, 0.1, 100); // Set perspective projection
1278
1247
  * console.log(matrix.matrix);
1279
1248
  *
1280
- * // p5.js script example
1281
- * <div class="norender"><code>
1249
+ * @example
1250
+ * // META:norender
1282
1251
  * function setup() {
1283
- *
1284
1252
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1285
1253
  * console.log("Original Matrix:", matrix.matrix);
1286
1254
  *
@@ -1289,7 +1257,6 @@ class Matrix extends MatrixInterface {
1289
1257
  * matrix.perspective(Math.PI / 4, 1.5, 0.1, 100);
1290
1258
  * console.log("Perspective Matrix:", matrix.matrix);
1291
1259
  * }
1292
- * </code></div>
1293
1260
  */
1294
1261
  perspective(fovy, aspect, near, far) {
1295
1262
  const f = 1.0 / Math.tan(fovy / 2),
@@ -1333,7 +1300,7 @@ class Matrix extends MatrixInterface {
1333
1300
  * @returns {Matrix} The current matrix instance, updated with the orthographic projection.
1334
1301
  *
1335
1302
  * @example
1336
- * <div class="norender"><code>
1303
+ * // META:norender
1337
1304
  * // Example using p5.js to demonstrate orthographic projection
1338
1305
  * function setup() {
1339
1306
  * let orthoMatrix = new p5.Matrix(4);
@@ -1348,8 +1315,6 @@ class Matrix extends MatrixInterface {
1348
1315
  * );
1349
1316
  * console.log(orthoMatrix.matrix.toString()) // Output: [31 0.004999999888241291,0,0,0,0,0.004999999888241291,0,0,0,0,-0.0020002000965178013,0,0,0,-1.0002000331878662,1]
1350
1317
  * }
1351
- * </code></div>
1352
- *
1353
1318
  */
1354
1319
  ortho(left, right, bottom, top, near, far) {
1355
1320
  const lr = 1 / (left - right),
@@ -1390,15 +1355,15 @@ class Matrix extends MatrixInterface {
1390
1355
  * @returns {Number[]} An array containing the transformed [x, y, z, w] components.
1391
1356
  *
1392
1357
  * @example
1358
+ * // META:norender
1393
1359
  * // Applying a matrix to a 4D vector
1394
1360
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1395
1361
  * const result = matrix.multiplyVec4(1, 2, 3, 1); // Transform the vector [1, 2, 3, 1]
1396
1362
  * console.log(result); // Output: [1, 2, 3, 1] (unchanged for identity matrix)
1397
1363
  *
1398
- * // p5.js script example
1399
- * <div class="norender"><code>
1364
+ * @example
1365
+ * // META:norender
1400
1366
  * function setup() {
1401
- *
1402
1367
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1403
1368
  * console.log("Original Matrix:", matrix.matrix);
1404
1369
  *
@@ -1414,7 +1379,6 @@ class Matrix extends MatrixInterface {
1414
1379
  * const transformedResult = matrix.multiplyVec4(1, 2, 3, 1);
1415
1380
  * console.log("Transformed Vector after Translation:", transformedResult); // Output: [6, 7, 8, 1]
1416
1381
  * }
1417
- * </code></div>
1418
1382
  */
1419
1383
  multiplyVec4(x, y, z, w) {
1420
1384
  const result = new Array(4);
@@ -1445,16 +1409,16 @@ class Matrix extends MatrixInterface {
1445
1409
  * @return {p5.Vector} A new `p5.Vector` instance representing the transformed point.
1446
1410
  *
1447
1411
  * @example
1412
+ * // META:norender
1448
1413
  * // Applying a matrix to a 3D point
1449
1414
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1450
1415
  * const point = new p5.Vector(1, 2, 3); // Define a 3D point
1451
1416
  * const transformedPoint = matrix.multiplyPoint(point);
1452
1417
  * console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
1453
1418
  *
1454
- * // p5.js script example
1455
- * <div class="norender"><code>
1419
+ * @example
1420
+ * // META:norender
1456
1421
  * function setup() {
1457
- *
1458
1422
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1459
1423
  * console.log("Original Matrix:", matrix.matrix);
1460
1424
  *
@@ -1474,7 +1438,6 @@ class Matrix extends MatrixInterface {
1474
1438
  * const translatedPoint = matrix.multiplyPoint(point);
1475
1439
  * console.log("Translated Point:", translatedPoint.toString()); // Output: [6, 7, 8]
1476
1440
  * }
1477
- * </code></div>
1478
1441
  */
1479
1442
  multiplyPoint({ x, y, z }) {
1480
1443
  const array = this.multiplyVec4(x, y, z, 1);
@@ -1498,16 +1461,16 @@ class Matrix extends MatrixInterface {
1498
1461
  * @return {p5.Vector} A new `p5.Vector` instance representing the transformed and normalized point.
1499
1462
  *
1500
1463
  * @example
1464
+ * // META:norender
1501
1465
  * // Applying a matrix to a 3D point and normalizing it
1502
1466
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1503
1467
  * const point = new p5.Vector(1, 2, 3); // Define a 3D point
1504
1468
  * const transformedPoint = matrix.multiplyAndNormalizePoint(point);
1505
1469
  * console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
1506
1470
  *
1507
- * // p5.js script example
1508
- * <div class="norender"><code>
1471
+ * @example
1472
+ * // META:norender
1509
1473
  * function setup() {
1510
- *
1511
1474
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1512
1475
  * console.log("Original Matrix:", matrix.matrix);
1513
1476
  *
@@ -1527,7 +1490,6 @@ class Matrix extends MatrixInterface {
1527
1490
  * const perspectivePoint = matrix.multiplyAndNormalizePoint(point);
1528
1491
  * console.log("Point after Perspective Transformation:", perspectivePoint.toString());
1529
1492
  * }
1530
- * </code></div>
1531
1493
  */
1532
1494
  multiplyAndNormalizePoint({ x, y, z }) {
1533
1495
  const array = this.multiplyVec4(x, y, z, 1);
@@ -1553,16 +1515,16 @@ class Matrix extends MatrixInterface {
1553
1515
  * @return {p5.Vector} A new `p5.Vector` instance representing the transformed direction.
1554
1516
  *
1555
1517
  * @example
1518
+ * // META:norender
1556
1519
  * // Applying a matrix to a direction vector
1557
1520
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1558
1521
  * const direction = new p5.Vector(1, 0, 0); // Define a direction vector
1559
1522
  * const transformedDirection = matrix.multiplyDirection(direction);
1560
1523
  * console.log(transformedDirection.toString()); // Output: [1, 0, 0] (unchanged for identity matrix)
1561
1524
  *
1562
- * // p5.js script example
1563
- * <div class="norender"><code>
1525
+ * @example
1526
+ * // META:norender
1564
1527
  * function setup() {
1565
- *
1566
1528
  * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1567
1529
  * console.log("Original Matrix:", matrix.matrix);
1568
1530
  *
@@ -1582,7 +1544,6 @@ class Matrix extends MatrixInterface {
1582
1544
  * const rotatedDirection = matrix.multiplyDirection(direction);
1583
1545
  * console.log("Rotated Direction:", rotatedDirection.toString()); // Output: Rotated vector
1584
1546
  * }
1585
- * </code></div>
1586
1547
  */
1587
1548
  multiplyDirection({ x, y, z }) {
1588
1549
  const array = this.multiplyVec4(x, y, z, 0);
@@ -1606,16 +1567,16 @@ class Matrix extends MatrixInterface {
1606
1567
  * @return {p5.Vector} - The transformed vector after applying the matrix.
1607
1568
  *
1608
1569
  * @example
1570
+ * // META:norender
1609
1571
  * // Multiplying a 3x3 matrix with a vector
1610
1572
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
1611
1573
  * const vector = new p5.Vector(1, 2, 3);
1612
1574
  * const result = matrix.multiplyVec3(vector);
1613
1575
  * console.log(result.toString()); // Output: Transformed vector
1614
1576
  *
1615
- * // p5.js script example
1616
- * <div class="norender"><code>
1577
+ * @example
1578
+ * // META:norender
1617
1579
  * function setup() {
1618
- *
1619
1580
  * // Create a 3x3 matrix
1620
1581
  * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
1621
1582
  * console.log("Original Matrix:", matrix.matrix);
@@ -1636,7 +1597,6 @@ class Matrix extends MatrixInterface {
1636
1597
  * const scaledVector = matrix.multiplyVec3(vector);
1637
1598
  * console.log("Scaled Vector:", scaledVector.toString()); // Output: [60, 72, 84]
1638
1599
  * }
1639
- * </code></div>
1640
1600
  */
1641
1601
  multiplyVec3(multVector, target) {
1642
1602
  if (target === undefined) {
@@ -1682,6 +1642,7 @@ class Matrix extends MatrixInterface {
1682
1642
  * @returns {this} The current instance with the updated matrix.
1683
1643
  *
1684
1644
  * @example
1645
+ * // META:norender
1685
1646
  * // Assuming `matrix` is an instance of the Matrix class
1686
1647
  * const srcMatrix = [
1687
1648
  * 1, 0, 0, 0,