p5 2.3.0 → 2.3.1-rc.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 (103) hide show
  1. package/README.md +3 -11
  2. package/dist/accessibility/color_namer.js +7 -7
  3. package/dist/accessibility/index.js +7 -7
  4. package/dist/app.js +7 -7
  5. package/dist/app.node.js +7 -7
  6. package/dist/color/color_conversion.js +7 -7
  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 +2 -2
  11. package/dist/{constants-Dv6ZqA6s.js → constants-Bx3_xAam.js} +1 -1
  12. package/dist/core/constants.js +1 -1
  13. package/dist/core/environment.js +1 -1
  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 +7 -7
  22. package/dist/core/internationalization.js +1 -1
  23. package/dist/core/legacy.js +7 -7
  24. package/dist/core/main.js +7 -7
  25. package/dist/core/p5.Graphics.js +4 -4
  26. package/dist/core/p5.Renderer.js +3 -3
  27. package/dist/core/p5.Renderer2D.js +7 -7
  28. package/dist/core/p5.Renderer3D.js +4 -4
  29. package/dist/core/rendering.js +4 -4
  30. package/dist/{creating_reading-DLkHH80h.js → creating_reading-YUSK33h8.js} +8 -0
  31. package/dist/dom/dom.js +2 -2
  32. package/dist/dom/index.js +2 -2
  33. package/dist/dom/p5.Element.js +2 -2
  34. package/dist/dom/p5.MediaElement.js +2 -2
  35. package/dist/events/pointer.js +15 -0
  36. package/dist/image/const.js +1 -1
  37. package/dist/image/filterRenderer2D.js +6 -6
  38. package/dist/image/image.js +4 -4
  39. package/dist/image/index.js +4 -4
  40. package/dist/image/loading_displaying.js +4 -4
  41. package/dist/image/p5.Image.js +3 -3
  42. package/dist/io/files.js +4 -4
  43. package/dist/io/index.js +4 -4
  44. package/dist/{ir_builders-C8mrXj5z.js → ir_builders-CMXkjMoV.js} +34 -24
  45. package/dist/{main-BR2ALC_6.js → main-BpW7VbDr.js} +39 -208
  46. package/dist/math/Matrices/Matrix.js +1 -1
  47. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  48. package/dist/math/calculation.js +669 -84
  49. package/dist/math/index.js +1 -1
  50. package/dist/math/p5.Matrix.js +1 -1
  51. package/dist/math/p5.Vector.js +9 -1
  52. package/dist/math/patch-vector.js +3 -1
  53. package/dist/math/trigonometry.js +399 -48
  54. package/dist/{p5.Renderer-XOvhEbJn.js → p5.Renderer-op0Y1WO6.js} +2 -2
  55. package/dist/{rendering-C5lX6zKm.js → rendering-SZ71KIDM.js} +24 -9
  56. package/dist/shape/2d_primitives.js +1 -1
  57. package/dist/shape/attributes.js +4 -3
  58. package/dist/shape/custom_shapes.js +205 -3
  59. package/dist/shape/index.js +2 -2
  60. package/dist/strands/ir_builders.js +1 -1
  61. package/dist/strands/p5.strands.js +26 -9
  62. package/dist/strands/strands_FES.js +8 -1
  63. package/dist/strands/strands_api.js +316 -21
  64. package/dist/strands/strands_conditionals.js +1 -1
  65. package/dist/strands/strands_for.js +1 -1
  66. package/dist/strands/strands_node.js +1 -1
  67. package/dist/strands/strands_ternary.js +1 -1
  68. package/dist/{strands_glslBackend-D6G3UyCs.js → strands_glslBackend-DMhOnoGl.js} +2 -2
  69. package/dist/type/index.js +3 -3
  70. package/dist/type/p5.Font.js +13 -4
  71. package/dist/type/textCore.js +3 -3
  72. package/dist/webgl/3d_primitives.js +4 -4
  73. package/dist/webgl/GeometryBuilder.js +1 -1
  74. package/dist/webgl/ShapeBuilder.js +1 -1
  75. package/dist/webgl/enums.js +1 -1
  76. package/dist/webgl/index.js +6 -6
  77. package/dist/webgl/interaction.js +1 -1
  78. package/dist/webgl/light.js +4 -4
  79. package/dist/webgl/loading.js +4 -4
  80. package/dist/webgl/material.js +4 -4
  81. package/dist/webgl/p5.Camera.js +4 -4
  82. package/dist/webgl/p5.Framebuffer.js +4 -4
  83. package/dist/webgl/p5.Geometry.js +1 -1
  84. package/dist/webgl/p5.Quat.js +1 -1
  85. package/dist/webgl/p5.RendererGL.js +6 -6
  86. package/dist/webgl/p5.Shader.js +5 -1
  87. package/dist/webgl/p5.Texture.js +4 -4
  88. package/dist/webgl/strands_glslBackend.js +2 -2
  89. package/dist/webgl/text.js +4 -4
  90. package/dist/webgl/utils.js +4 -4
  91. package/dist/webgpu/index.js +2 -2
  92. package/dist/webgpu/p5.RendererWebGPU.js +2 -2
  93. package/dist/webgpu/strands_wgslBackend.js +2 -2
  94. package/lib/p5.esm.js +1765 -405
  95. package/lib/p5.esm.min.js +1 -1
  96. package/lib/p5.js +1765 -405
  97. package/lib/p5.min.js +1 -1
  98. package/lib/p5.webgpu.esm.js +34 -3
  99. package/lib/p5.webgpu.js +34 -3
  100. package/lib/p5.webgpu.min.js +1 -1
  101. package/package.json +1 -1
  102. package/types/global.d.ts +5539 -2604
  103. package/types/p5.d.ts +2917 -1432
@@ -5,7 +5,7 @@ import trigonometry from './trigonometry.js';
5
5
  import math$1 from './math.js';
6
6
  import vector from './p5.Vector.js';
7
7
  import vectorValidation from './patch-vector.js';
8
- import '../constants-Dv6ZqA6s.js';
8
+ import '../constants-Bx3_xAam.js';
9
9
 
10
10
  function math(p5){
11
11
  p5.registerAddon(calculation);
@@ -1,6 +1,6 @@
1
1
  import { Matrix } from './Matrices/Matrix.js';
2
2
  import './p5.Vector.js';
3
- import '../constants-Dv6ZqA6s.js';
3
+ import '../constants-Bx3_xAam.js';
4
4
  import './Matrices/MatrixInterface.js';
5
5
 
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { o as TWO_PI } from '../constants-Dv6ZqA6s.js';
1
+ import { o as TWO_PI } from '../constants-Bx3_xAam.js';
2
2
 
3
3
  /**
4
4
  * @module Math
@@ -3684,6 +3684,14 @@ function vector(p5, fn) {
3684
3684
  * @property z
3685
3685
  * @name z
3686
3686
  */
3687
+
3688
+ /**
3689
+ * The dimensions of the vector
3690
+ * @type {Number}
3691
+ * @for p5.Vector
3692
+ * @property dimensions
3693
+ * @name dimensions
3694
+ */
3687
3695
  }
3688
3696
 
3689
3697
  if (typeof p5 !== 'undefined') {
@@ -1,5 +1,5 @@
1
1
  import { Vector } from './p5.Vector.js';
2
- import '../constants-Dv6ZqA6s.js';
2
+ import '../constants-Bx3_xAam.js';
3
3
 
4
4
  /**
5
5
  * @private
@@ -77,6 +77,8 @@ function _validatedVectorOperation(expectsSoloNumberArgument){
77
77
  }
78
78
 
79
79
  /**
80
+ * @private
81
+ * @internal
80
82
  * Each of the following decorators validates the data on vector operations.
81
83
  * These ensure that the arguments are consistently formatted, and that
82
84
  * pre-conditions are met.
@@ -1,4 +1,4 @@
1
- import { a3 as RAD_TO_DEG, a4 as DEG_TO_RAD } from '../constants-Dv6ZqA6s.js';
1
+ import { a3 as RAD_TO_DEG, a4 as DEG_TO_RAD } from '../constants-Bx3_xAam.js';
2
2
 
3
3
  /**
4
4
  * @module Math
@@ -102,11 +102,7 @@ function trigonometry(p5, fn){
102
102
  * <a href="#/p5/angleMode">angleMode()</a> is `DEGREES`, then values are
103
103
  * returned in the range 0 to 180.
104
104
  *
105
- * @method acos
106
- * @param {Number} value value whose arc cosine is to be returned.
107
- * @return {Number} arc cosine of the given value.
108
- *
109
- * @example
105
+ * ```js example
110
106
  * function setup() {
111
107
  * createCanvas(100, 100);
112
108
  *
@@ -124,8 +120,9 @@ function trigonometry(p5, fn){
124
120
  *
125
121
  * describe('The numbers 3.142, -1, and 3.142 written on separate rows.');
126
122
  * }
123
+ * ```
127
124
  *
128
- * @example
125
+ * ```js example
129
126
  * function setup() {
130
127
  * createCanvas(100, 100);
131
128
  *
@@ -143,6 +140,52 @@ function trigonometry(p5, fn){
143
140
  *
144
141
  * describe('The numbers 3.927, -0.707, and 2.356 written on separate rows.');
145
142
  * }
143
+ * ```
144
+ *
145
+ * `acos()` can also be used in shaders with p5.strands. The following example
146
+ * uses `acos()` to create a pulsing color transition on a shape.
147
+ *
148
+ * ```js example
149
+ * let myShader;
150
+ *
151
+ * function setup() {
152
+ * createCanvas(100, 100, WEBGL);
153
+ * myShader = buildColorShader(shaderCallback);
154
+ * describe('A sphere that pulses between orange and teal.');
155
+ * }
156
+ *
157
+ * function shaderCallback() {
158
+ * // shaderCallback runs on the GPU. millis() gives ms since start; multiply by 0.001 for seconds.
159
+ * let t = millis() * 0.001;
160
+ *
161
+ * // acos(cos(t)) creates a triangle wave that goes from 0 to PI and back.
162
+ * // Dividing by PI normalizes the result to the 0 to 1 range.
163
+ * let value = acos(cos(t)) / PI;
164
+ *
165
+ * // Each color is [R, G, B, A] with values from 0 to 1.
166
+ * let orange = [1, 0.5, 0, 1];
167
+ * let teal = [0, 0.8, 0.8, 1];
168
+ *
169
+ * finalColor.begin();
170
+ *
171
+ * // mix() blends between orange (when value = 0) and teal (when value = 1).
172
+ * // acos() creates a pulsing effect by turning smooth oscillation into a triangle wave.
173
+ * finalColor.set(mix(orange, teal, value));
174
+ *
175
+ * finalColor.end();
176
+ * }
177
+ *
178
+ * function draw() {
179
+ * background(220);
180
+ * shader(myShader);
181
+ * noStroke();
182
+ * sphere(30);
183
+ * }
184
+ * ```
185
+ *
186
+ * @method acos
187
+ * @param {Number} value value whose arc cosine is to be returned.
188
+ * @return {Number} arc cosine of the given value.
146
189
  */
147
190
  fn.acos = function(ratio) {
148
191
  return this._fromRadians(Math.acos(ratio));
@@ -157,11 +200,7 @@ function trigonometry(p5, fn){
157
200
  * the <a href="#/p5/angleMode">angleMode()</a> is `DEGREES` then values are
158
201
  * returned in the range -90 to 90.
159
202
  *
160
- * @method asin
161
- * @param {Number} value value whose arc sine is to be returned.
162
- * @return {Number} arc sine of the given value.
163
- *
164
- * @example
203
+ * ```js example
165
204
  * function setup() {
166
205
  * createCanvas(100, 100);
167
206
  *
@@ -179,8 +218,9 @@ function trigonometry(p5, fn){
179
218
  *
180
219
  * describe('The numbers 1.047, 0.866, and 1.047 written on separate rows.');
181
220
  * }
221
+ * ```
182
222
  *
183
- * @example
223
+ * ```js example
184
224
  * function setup() {
185
225
  * createCanvas(100, 100);
186
226
  *
@@ -198,6 +238,52 @@ function trigonometry(p5, fn){
198
238
  *
199
239
  * describe('The numbers 4.189, -0.866, and -1.047 written on separate rows.');
200
240
  * }
241
+ * ```
242
+ *
243
+ * `asin()` can also be used in shaders with p5.strands. The following example
244
+ * uses `asin()` to create a smooth color transition on a shape.
245
+ *
246
+ * ```js example
247
+ * let myShader;
248
+ *
249
+ * function setup() {
250
+ * createCanvas(100, 100, WEBGL);
251
+ * myShader = buildColorShader(shaderCallback);
252
+ * describe('A sphere that smoothly shifts between green and purple.');
253
+ * }
254
+ *
255
+ * function shaderCallback() {
256
+ * // shaderCallback runs on the GPU. millis() gives ms since start; multiply by 0.001 for seconds.
257
+ * let t = millis() * 0.001;
258
+ *
259
+ * // asin(sin(t)) returns a value between -PI/2 and PI/2.
260
+ * // Dividing by PI/2 normalizes to -1 to 1, then adding 1 and multiplying by 0.5
261
+ * // remaps to the 0 to 1 range.
262
+ * let value = (asin(sin(t)) / (PI / 2) + 1) * 0.5;
263
+ *
264
+ * // Each color is [R, G, B, A] with values from 0 to 1.
265
+ * let green = [0, 1, 0.5, 1];
266
+ * let purple = [0.5, 0, 1, 1];
267
+ *
268
+ * finalColor.begin();
269
+ *
270
+ * // mix() blends between green (when value = 0) and purple (when value = 1).
271
+ * finalColor.set(mix(green, purple, value));
272
+ *
273
+ * finalColor.end();
274
+ * }
275
+ *
276
+ * function draw() {
277
+ * background(220);
278
+ * shader(myShader);
279
+ * noStroke();
280
+ * sphere(30);
281
+ * }
282
+ * ```
283
+ *
284
+ * @method asin
285
+ * @param {Number} value value whose arc sine is to be returned.
286
+ * @return {Number} arc sine of the given value.
201
287
  */
202
288
  fn.asin = function(ratio) {
203
289
  return this._fromRadians(Math.asin(ratio));
@@ -212,11 +298,7 @@ function trigonometry(p5, fn){
212
298
  * (about 1.57). If the <a href="#/p5/angleMode">angleMode()</a> is `DEGREES`
213
299
  * then values are returned in the range -90 to 90.
214
300
  *
215
- * @method atan
216
- * @param {Number} value value whose arc tangent is to be returned.
217
- * @return {Number} arc tangent of the given value.
218
- *
219
- * @example
301
+ * ```js example
220
302
  * function setup() {
221
303
  * createCanvas(100, 100);
222
304
  *
@@ -234,8 +316,9 @@ function trigonometry(p5, fn){
234
316
  *
235
317
  * describe('The numbers 1.047, 1.732, and 1.047 written on separate rows.');
236
318
  * }
319
+ * ```
237
320
  *
238
- * @example
321
+ * ```js example
239
322
  * function setup() {
240
323
  * createCanvas(100, 100);
241
324
  *
@@ -253,6 +336,55 @@ function trigonometry(p5, fn){
253
336
  *
254
337
  * describe('The numbers 4.189, 1.732, and 1.047 written on separate rows.');
255
338
  * }
339
+ * ```
340
+ *
341
+ * `atan()` can also be used in shaders with p5.strands. The following example
342
+ * uses `atan()` to create a soft color transition on a shape.
343
+ *
344
+ * ```js example
345
+ * let myShader;
346
+ *
347
+ * function setup() {
348
+ * createCanvas(100, 100, WEBGL);
349
+ * myShader = buildColorShader(shaderCallback);
350
+ * describe('A sphere that softly shifts between pink and lime.');
351
+ * }
352
+ *
353
+ * function shaderCallback() {
354
+ * // shaderCallback runs on the GPU. millis() gives ms since start; multiply by 0.001 for seconds.
355
+ * // sin() oscillates the input between -5 and 5, so atan() gets both positive and negative values.
356
+ * let t = sin(millis() * 0.001) * 5;
357
+ *
358
+ * // atan(t) returns values between -PI/2 and PI/2.
359
+ * // Dividing by PI/2 normalizes to -1 to 1, then adding 1 and multiplying by 0.5
360
+ * // remaps to the 0 to 1 range.
361
+ * // atan() compresses the wide range of t into a smooth S-curve (soft clipping).
362
+ * let value = (atan(t) / (PI / 2) + 1) * 0.5;
363
+ *
364
+ * // Each color is [R, G, B, A] with values from 0 to 1.
365
+ * let pink = [1, 0, 0.5, 1];
366
+ * let lime = [0.5, 1, 0, 1];
367
+ *
368
+ * finalColor.begin();
369
+ *
370
+ * // mix() blends between pink (when value = 0) and lime (when value = 1).
371
+ * // atan() creates a soft, eased transition instead of a linear blend.
372
+ * finalColor.set(mix(pink, lime, value));
373
+ *
374
+ * finalColor.end();
375
+ * }
376
+ *
377
+ * function draw() {
378
+ * background(220);
379
+ * shader(myShader);
380
+ * noStroke();
381
+ * sphere(30);
382
+ * }
383
+ * ```
384
+ *
385
+ * @method atan
386
+ * @param {Number} value value whose arc tangent is to be returned.
387
+ * @return {Number} arc tangent of the given value.
256
388
  */
257
389
  fn.atan = function(ratio) {
258
390
  return this._fromRadians(Math.atan(ratio));
@@ -336,11 +468,7 @@ function trigonometry(p5, fn){
336
468
  * calculates the cosine of an angle, using radians by default, or according
337
469
  * to if <a href="#/p5/angleMode">angleMode()</a> setting (RADIANS or DEGREES).
338
470
  *
339
- * @method cos
340
- * @param {Number} angle the angle, in radians by default, or according to if <a href="/reference/p5/angleMode/">angleMode()</a> setting (RADIANS or DEGREES).
341
- * @return {Number} cosine of the angle.
342
- *
343
- * @example
471
+ * ```js example
344
472
  * function setup() {
345
473
  * createCanvas(100, 100);
346
474
  *
@@ -358,8 +486,9 @@ function trigonometry(p5, fn){
358
486
  * line(50, y, x, y);
359
487
  * circle(x, y, 20);
360
488
  * }
489
+ * ```
361
490
  *
362
- * @example
491
+ * ```js example
363
492
  * function setup() {
364
493
  * createCanvas(100, 100);
365
494
  *
@@ -376,8 +505,9 @@ function trigonometry(p5, fn){
376
505
  * // Draw the point.
377
506
  * point(x, y);
378
507
  * }
508
+ * ```
379
509
  *
380
- * @example
510
+ * ```js example
381
511
  * function setup() {
382
512
  * createCanvas(100, 100);
383
513
  *
@@ -394,6 +524,51 @@ function trigonometry(p5, fn){
394
524
  * // Draw the point.
395
525
  * point(x, y);
396
526
  * }
527
+ * ```
528
+ *
529
+ * `cos()` can also be used in shaders with p5.strands. The following example
530
+ * uses `cos()` to smoothly oscillate the color of a shape over time.
531
+ *
532
+ * ```js example
533
+ * let myShader;
534
+ *
535
+ * function setup() {
536
+ * createCanvas(100, 100, WEBGL);
537
+ * myShader = buildColorShader(shaderCallback);
538
+ * describe('A sphere that fades between yellow and blue.');
539
+ * }
540
+ *
541
+ * function shaderCallback() {
542
+ * // shaderCallback runs on the GPU. millis() gives ms since start; multiply by 0.001 for seconds.
543
+ * let t = millis() * 0.001;
544
+ *
545
+ * // cos(t) oscillates between -1 and 1.
546
+ * // 0.5 + 0.5 * cos(t) remaps this to the 0 to 1 range.
547
+ * let value = 0.5 + 0.5 * cos(t);
548
+ *
549
+ * // Each color is [R, G, B, A] with values from 0 to 1.
550
+ * let yellow = [1, 1, 0, 1];
551
+ * let blue = [0, 0, 1, 1];
552
+ *
553
+ * finalColor.begin();
554
+ *
555
+ * // mix() blends between yellow (when value = 0) and blue (when value = 1).
556
+ * finalColor.set(mix(yellow, blue, value));
557
+ *
558
+ * finalColor.end();
559
+ * }
560
+ *
561
+ * function draw() {
562
+ * background(220);
563
+ * shader(myShader);
564
+ * noStroke();
565
+ * sphere(30);
566
+ * }
567
+ * ```
568
+ *
569
+ * @method cos
570
+ * @param {Number} angle the angle, in radians by default, or according to if <a href="/reference/p5/angleMode/">angleMode()</a> setting (RADIANS or DEGREES).
571
+ * @return {Number} cosine of the angle.
397
572
  */
398
573
  fn.cos = function(angle) {
399
574
  return Math.cos(this._toRadians(angle));
@@ -407,11 +582,7 @@ function trigonometry(p5, fn){
407
582
  * calculates the sine of an angle, using radians by default, or according to
408
583
  * if <a href="#/p5/angleMode">angleMode()</a> setting (RADIANS or DEGREES).
409
584
  *
410
- * @method sin
411
- * @param {Number} angle the angle, in radians by default, or according to if <a href="/reference/p5/angleMode/">angleMode()</a> setting (RADIANS or DEGREES).
412
- * @return {Number} sine of the angle.
413
- *
414
- * @example
585
+ * ```js example
415
586
  * function setup() {
416
587
  * createCanvas(100, 100);
417
588
  *
@@ -429,8 +600,9 @@ function trigonometry(p5, fn){
429
600
  * line(50, y, x, y);
430
601
  * circle(x, y, 20);
431
602
  * }
603
+ * ```
432
604
  *
433
- * @example
605
+ * ```js example
434
606
  * function setup() {
435
607
  * createCanvas(100, 100);
436
608
  *
@@ -447,8 +619,9 @@ function trigonometry(p5, fn){
447
619
  * // Draw the point.
448
620
  * point(x, y);
449
621
  * }
622
+ * ```
450
623
  *
451
- * @example
624
+ * ```js example
452
625
  * function setup() {
453
626
  * createCanvas(100, 100);
454
627
  *
@@ -465,6 +638,51 @@ function trigonometry(p5, fn){
465
638
  * // Draw the point.
466
639
  * point(x, y);
467
640
  * }
641
+ * ```
642
+ *
643
+ * `sin()` can also be used in shaders with p5.strands. The following example
644
+ * uses `sin()` to oscillate the color of a shape over time.
645
+ *
646
+ * ```js example
647
+ * let myShader;
648
+ *
649
+ * function setup() {
650
+ * createCanvas(100, 100, WEBGL);
651
+ * myShader = buildColorShader(shaderCallback);
652
+ * describe('A sphere that pulses between cyan and magenta.');
653
+ * }
654
+ *
655
+ * function shaderCallback() {
656
+ * // shaderCallback runs on the GPU. millis() gives ms since start; multiply by 0.001 for seconds.
657
+ * let t = millis() * 0.001;
658
+ *
659
+ * // sin(t) oscillates between -1 and 1.
660
+ * // 0.5 + 0.5 * sin(t) remaps this to the 0 to 1 range.
661
+ * let value = 0.5 + 0.5 * sin(t);
662
+ *
663
+ * // Each color is [R, G, B, A] with values from 0 to 1.
664
+ * let cyan = [0, 1, 1, 1];
665
+ * let magenta = [1, 0, 1, 1];
666
+ *
667
+ * finalColor.begin();
668
+ *
669
+ * // mix() blends between cyan (when value = 0) and magenta (when value = 1).
670
+ * finalColor.set(mix(cyan, magenta, value));
671
+ *
672
+ * finalColor.end();
673
+ * }
674
+ *
675
+ * function draw() {
676
+ * background(220);
677
+ * shader(myShader);
678
+ * noStroke();
679
+ * sphere(30);
680
+ * }
681
+ * ```
682
+ *
683
+ * @method sin
684
+ * @param {Number} angle the angle, in radians by default, or according to if <a href="/reference/p5/angleMode/">angleMode()</a> setting (RADIANS or DEGREES).
685
+ * @return {Number} sine of the angle.
468
686
  */
469
687
  fn.sin = function(angle) {
470
688
  return Math.sin(this._toRadians(angle));
@@ -479,11 +697,7 @@ function trigonometry(p5, fn){
479
697
  * by default, or according to
480
698
  * if <a href="#/p5/angleMode">angleMode()</a> setting (RADIANS or DEGREES).
481
699
  *
482
- * @method tan
483
- * @param {Number} angle the angle, in radians by default, or according to if <a href="/reference/p5/angleMode/">angleMode()</a> setting (RADIANS or DEGREES).
484
- * @return {Number} tangent of the angle.
485
- *
486
- * @example
700
+ * ```js example
487
701
  * function setup() {
488
702
  * createCanvas(100, 100);
489
703
  *
@@ -500,6 +714,53 @@ function trigonometry(p5, fn){
500
714
  * // Draw the point.
501
715
  * point(x, y);
502
716
  * }
717
+ * ```
718
+ *
719
+ * `tan()` can also be used in shaders with p5.strands. The following example
720
+ * uses `tan()` to create rapid color transitions on a shape.
721
+ *
722
+ * ```js example
723
+ * let myShader;
724
+ *
725
+ * function setup() {
726
+ * createCanvas(100, 100, WEBGL);
727
+ * myShader = buildColorShader(shaderCallback);
728
+ * describe('A sphere with rapidly shifting colors.');
729
+ * }
730
+ *
731
+ * function shaderCallback() {
732
+ * // shaderCallback runs on the GPU. millis() gives ms since start; multiply by 0.0005 to slow it down.
733
+ * let t = millis() * 0.0005;
734
+ *
735
+ * // tan(t) can grow to very large values (even infinity) at certain angles.
736
+ * // 0.5 + 0.5 * tan(t) shifts the range but can still go way past 0 or 1.
737
+ * // min(max(..., 0), 1) clamps the result to the 0 to 1 range.
738
+ * let value = min(max(0.5 + 0.5 * tan(t), 0), 1);
739
+ *
740
+ * // Each color is [R, G, B, A] with values from 0 to 1.
741
+ * let orange = [1, 0.5, 0, 1];
742
+ * let blue = [0, 0.5, 1, 1];
743
+ *
744
+ * finalColor.begin();
745
+ *
746
+ * // mix() blends between orange (when value = 0) and blue (when value = 1).
747
+ * // tan() creates rapid, dramatic color shifts as it spikes and resets.
748
+ * finalColor.set(mix(orange, blue, value));
749
+ *
750
+ * finalColor.end();
751
+ * }
752
+ *
753
+ * function draw() {
754
+ * background(220);
755
+ * shader(myShader);
756
+ * noStroke();
757
+ * sphere(30);
758
+ * }
759
+ * ```
760
+ *
761
+ * @method tan
762
+ * @param {Number} angle the angle, in radians by default, or according to if <a href="/reference/p5/angleMode/">angleMode()</a> setting (RADIANS or DEGREES).
763
+ * @return {Number} tangent of the angle.
503
764
  */
504
765
  fn.tan = function(angle) {
505
766
  return Math.tan(this._toRadians(angle));
@@ -515,11 +776,7 @@ function trigonometry(p5, fn){
515
776
  * quarter of a full rotation. The same angle is 2 &times; &pi; &divide; 4
516
777
  * (about 1.57) radians.
517
778
  *
518
- * @method degrees
519
- * @param {Number} radians radians value to convert to degrees.
520
- * @return {Number} converted angle.
521
- *
522
- * @example
779
+ * ```js example
523
780
  * function setup() {
524
781
  * createCanvas(100, 100);
525
782
  *
@@ -534,6 +791,54 @@ function trigonometry(p5, fn){
534
791
  *
535
792
  * describe('The text "0.79 rad = 45˚".');
536
793
  * }
794
+ * ```
795
+ *
796
+ * `degrees()` can also be used in shaders with p5.strands. The following example
797
+ * uses `degrees()` to convert a radian value to degrees inside a shader.
798
+ *
799
+ * ```js example
800
+ * let myShader;
801
+ *
802
+ * function setup() {
803
+ * createCanvas(100, 100, WEBGL);
804
+ * myShader = buildColorShader(shaderCallback);
805
+ * describe('A sphere that cycles through warm colors.');
806
+ * }
807
+ *
808
+ * function shaderCallback() {
809
+ * // shaderCallback runs on the GPU. millis() gives ms since start; multiply by 0.001 for seconds.
810
+ * let t = millis() * 0.001;
811
+ *
812
+ * // degrees() converts the radian value t to degrees.
813
+ * // (deg % 360) wraps the degrees into a 0-360 range.
814
+ * // Dividing by 360 normalizes to the 0 to 1 range.
815
+ * let deg = degrees(t);
816
+ * let value = (deg % 360) / 360;
817
+ *
818
+ * // Each color is [R, G, B, A] with values from 0 to 1.
819
+ * let red = [1, 0, 0, 1];
820
+ * let yellow = [1, 1, 0, 1];
821
+ *
822
+ * finalColor.begin();
823
+ *
824
+ * // mix() blends between red (when value = 0) and yellow (when value = 1).
825
+ * // degrees() creates a cycling sawtooth pattern as time increases.
826
+ * finalColor.set(mix(red, yellow, value));
827
+ *
828
+ * finalColor.end();
829
+ * }
830
+ *
831
+ * function draw() {
832
+ * background(220);
833
+ * shader(myShader);
834
+ * noStroke();
835
+ * sphere(30);
836
+ * }
837
+ * ```
838
+ *
839
+ * @method degrees
840
+ * @param {Number} radians radians value to convert to degrees.
841
+ * @return {Number} converted angle.
537
842
  */
538
843
  fn.degrees = angle => angle * RAD_TO_DEG;
539
844
 
@@ -547,11 +852,7 @@ function trigonometry(p5, fn){
547
852
  * quarter of a full rotation. The same angle is 2 &times; &pi; &divide; 4
548
853
  * (about 1.57) radians.
549
854
  *
550
- * @method radians
551
- * @param {Number} degrees degree value to convert to radians.
552
- * @return {Number} converted angle.
553
- *
554
- * @example
855
+ * ```js example
555
856
  * function setup() {
556
857
  * createCanvas(100, 100);
557
858
  *
@@ -566,6 +867,56 @@ function trigonometry(p5, fn){
566
867
  *
567
868
  * describe('The text "45˚ = 0.785 rad".');
568
869
  * }
870
+ * ```
871
+ *
872
+ * `radians()` can also be used in shaders with p5.strands. The following example
873
+ * uses `radians()` to convert degrees to radians inside a shader.
874
+ *
875
+ * ```js example
876
+ * let myShader;
877
+ *
878
+ * function setup() {
879
+ * createCanvas(100, 100, WEBGL);
880
+ * myShader = buildColorShader(shaderCallback);
881
+ * describe('A sphere that fades between red and white.');
882
+ * }
883
+ *
884
+ * function shaderCallback() {
885
+ * // shaderCallback runs on the GPU. millis() gives ms since start.
886
+ * // Multiply by 0.05 and mod 360 to cycle through 0-360 degrees over time.
887
+ * let deg = (millis() * 0.05) % 360;
888
+ *
889
+ * // radians() converts degrees to radians so sin() can use them.
890
+ * let rad = radians(deg);
891
+ *
892
+ * // sin(rad) oscillates between -1 and 1.
893
+ * // 0.5 + 0.5 * sin(rad) remaps this to the 0 to 1 range.
894
+ * let value = 0.5 + 0.5 * sin(rad);
895
+ *
896
+ * // Each color is [R, G, B, A] with values from 0 to 1.
897
+ * let red = [1, 0, 0, 1];
898
+ * let white = [1, 1, 1, 1];
899
+ *
900
+ * finalColor.begin();
901
+ *
902
+ * // mix() blends between red (when value = 0) and white (when value = 1).
903
+ * // radians() converts the degree input so sin() can produce smooth oscillation.
904
+ * finalColor.set(mix(red, white, value));
905
+ *
906
+ * finalColor.end();
907
+ * }
908
+ *
909
+ * function draw() {
910
+ * background(220);
911
+ * shader(myShader);
912
+ * noStroke();
913
+ * sphere(30);
914
+ * }
915
+ * ```
916
+ *
917
+ * @method radians
918
+ * @param {Number} degrees degree value to convert to radians.
919
+ * @return {Number} converted angle.
569
920
  */
570
921
  fn.radians = angle => angle * DEG_TO_RAD;
571
922
 
@@ -1,5 +1,5 @@
1
- import { C as Color } from './creating_reading-DLkHH80h.js';
2
- import { a1 as NORMAL, aA as WORD, ax as BASELINE, av as LEFT, t as CENTER, n as CORNER, I as INCLUDE } from './constants-Dv6ZqA6s.js';
1
+ import { C as Color } from './creating_reading-YUSK33h8.js';
2
+ import { a1 as NORMAL, aA as WORD, ax as BASELINE, av as LEFT, t as CENTER, n as CORNER, I as INCLUDE } from './constants-Bx3_xAam.js';
3
3
  import Filters from './image/filters.js';
4
4
  import { Vector } from './math/p5.Vector.js';
5
5
  import { Shape } from './shape/custom_shapes.js';