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.
- package/dist/accessibility/color_namer.js +5 -6
- package/dist/accessibility/describe.js +4 -26
- package/dist/accessibility/index.js +5 -6
- package/dist/accessibility/outputs.js +6 -38
- package/dist/app.js +5 -6
- package/dist/color/color_conversion.js +5 -6
- package/dist/color/creating_reading.js +1 -1
- package/dist/color/index.js +2 -2
- package/dist/color/p5.Color.js +1 -1
- package/dist/color/setting.js +59 -357
- package/dist/{constants-DEJVKr9Z.js → constants-DQyACdzq.js} +11 -61
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +26 -158
- package/dist/core/filterShaders.js +1 -1
- package/dist/core/friendly_errors/fes_core.js +1 -1
- package/dist/core/friendly_errors/file_errors.js +1 -1
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +1 -1
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +5 -6
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +5 -6
- package/dist/core/main.js +5 -6
- package/dist/core/p5.Graphics.js +4 -5
- package/dist/core/p5.Renderer.js +3 -4
- package/dist/core/p5.Renderer2D.js +5 -6
- package/dist/core/p5.Renderer3D.js +4 -5
- package/dist/core/rendering.js +4 -5
- package/dist/core/structure.js +13 -52
- package/dist/core/transform.js +32 -176
- package/dist/{creating_reading-CgHCHxqN.js → creating_reading-ZXzcZEsb.js} +3 -196
- package/dist/data/local_storage.js +4 -30
- package/dist/dom/dom.js +24 -159
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +31 -208
- package/dist/dom/p5.File.js +1 -32
- package/dist/dom/p5.MediaElement.js +10 -113
- package/dist/events/acceleration.js +11 -64
- package/dist/events/keyboard.js +13 -81
- package/dist/events/pointer.js +18 -160
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +4 -5
- package/dist/image/image.js +4 -5
- package/dist/image/index.js +4 -5
- package/dist/image/loading_displaying.js +4 -5
- package/dist/image/p5.Image.js +3 -4
- package/dist/image/pixels.js +17 -100
- package/dist/io/files.js +4 -5
- package/dist/io/index.js +4 -5
- package/dist/io/p5.Table.js +66 -158
- package/dist/io/p5.TableRow.js +48 -71
- package/dist/io/p5.XML.js +6 -99
- package/dist/io/utilities.js +8 -3
- package/dist/{main-_RXV5Lx8.js → main-DvN69W3f.js} +13 -42
- package/dist/math/Matrices/Matrix.js +87 -126
- package/dist/math/Matrices/MatrixNumjs.js +1 -5
- package/dist/math/calculation.js +10 -112
- package/dist/math/index.js +1 -1
- package/dist/math/math.js +2 -12
- package/dist/math/noise.js +5 -32
- package/dist/math/p5.Matrix.js +3 -3
- package/dist/math/p5.Vector.js +104 -345
- package/dist/math/random.js +5 -32
- package/dist/math/trigonometry.js +15 -105
- package/dist/{p5.Renderer-QoFcvj3f.js → p5.Renderer-D-5LdCRz.js} +25 -178
- package/dist/{rendering-CsICjEXA.js → rendering-h9unX5K0.js} +254 -1156
- package/dist/shape/2d_primitives.js +33 -194
- package/dist/shape/attributes.js +12 -73
- package/dist/shape/curves.js +30 -95
- package/dist/shape/custom_shapes.js +63 -144
- package/dist/shape/index.js +2 -2
- package/dist/shape/vertex.js +21 -106
- package/dist/strands/p5.strands.js +248 -46
- package/dist/type/index.js +3 -4
- package/dist/type/p5.Font.js +4 -49
- package/dist/type/textCore.js +5 -158
- package/dist/utilities/conversion.js +17 -104
- package/dist/utilities/time_date.js +3 -40
- package/dist/utilities/utility_functions.js +6 -48
- package/dist/webgl/3d_primitives.js +4 -5
- package/dist/webgl/GeometryBuilder.js +1 -2
- package/dist/webgl/ShapeBuilder.js +22 -2
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +4 -5
- package/dist/webgl/interaction.js +6 -33
- package/dist/webgl/light.js +4 -5
- package/dist/webgl/loading.js +12 -46
- package/dist/webgl/material.js +4 -5
- package/dist/webgl/p5.Camera.js +4 -5
- package/dist/webgl/p5.DataArray.js +0 -4
- package/dist/webgl/p5.Framebuffer.js +4 -5
- package/dist/webgl/p5.Geometry.js +12 -106
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +7 -18
- package/dist/webgl/p5.Shader.js +12 -36
- package/dist/webgl/p5.Texture.js +4 -5
- package/dist/webgl/text.js +4 -5
- package/dist/webgl/utils.js +4 -5
- package/dist/webgpu/index.js +1 -1
- package/dist/webgpu/p5.RendererWebGPU.js +529 -208
- package/dist/webgpu/shaders/color.js +32 -17
- package/dist/webgpu/shaders/filters/base.js +18 -7
- package/dist/webgpu/shaders/font.js +52 -40
- package/dist/webgpu/shaders/line.js +50 -36
- package/dist/webgpu/shaders/material.js +90 -83
- package/dist/webgpu/strands_wgslBackend.js +5 -2
- package/lib/p5.esm.js +5576 -7811
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +5576 -7811
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +786 -453
- package/lib/p5.webgpu.js +786 -453
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +13 -13
- package/types/global.d.ts +16905 -16783
- package/types/p5.d.ts +11142 -11081
|
@@ -31,7 +31,11 @@ function strands(p5, fn) {
|
|
|
31
31
|
//////////////////////////////////////////////
|
|
32
32
|
// Global Runtime
|
|
33
33
|
//////////////////////////////////////////////
|
|
34
|
-
function initStrandsContext(
|
|
34
|
+
function initStrandsContext(
|
|
35
|
+
ctx,
|
|
36
|
+
backend,
|
|
37
|
+
{ active = false, renderer = null, baseShader = null } = {},
|
|
38
|
+
) {
|
|
35
39
|
ctx.dag = createDirectedAcyclicGraph();
|
|
36
40
|
ctx.cfg = createControlFlowGraph();
|
|
37
41
|
ctx.uniforms = [];
|
|
@@ -79,11 +83,8 @@ function strands(p5, fn) {
|
|
|
79
83
|
|
|
80
84
|
const prev = {};
|
|
81
85
|
for (const key of Object.getOwnPropertyNames(fn)) {
|
|
82
|
-
const descriptor = Object.getOwnPropertyDescriptor(
|
|
83
|
-
|
|
84
|
-
key
|
|
85
|
-
);
|
|
86
|
-
if (descriptor && !descriptor.get && typeof fn[key] === 'function') {
|
|
86
|
+
const descriptor = Object.getOwnPropertyDescriptor(fn, key);
|
|
87
|
+
if (descriptor && !descriptor.get && typeof fn[key] === "function") {
|
|
87
88
|
prev[key] = window[key];
|
|
88
89
|
window[key] = fn[key].bind(pInst);
|
|
89
90
|
}
|
|
@@ -105,7 +106,10 @@ function strands(p5, fn) {
|
|
|
105
106
|
|
|
106
107
|
p5.Shader.prototype.modify = function (shaderModifier, scope = {}) {
|
|
107
108
|
try {
|
|
108
|
-
if (
|
|
109
|
+
if (
|
|
110
|
+
shaderModifier instanceof Function ||
|
|
111
|
+
typeof shaderModifier === "string"
|
|
112
|
+
) {
|
|
109
113
|
// Reset the context object every time modify is called;
|
|
110
114
|
// const backend = glslBackend;
|
|
111
115
|
initStrandsContext(strandsContext, this._renderer.strandsBackend, {
|
|
@@ -122,9 +126,10 @@ function strands(p5, fn) {
|
|
|
122
126
|
if (options.parser) {
|
|
123
127
|
// #7955 Wrap function declaration code in brackets so anonymous functions are not top level statements, which causes an error in acorn when parsing
|
|
124
128
|
// https://github.com/acornjs/acorn/issues/1385
|
|
125
|
-
const sourceString =
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
const sourceString =
|
|
130
|
+
typeof shaderModifier === "string"
|
|
131
|
+
? `(${shaderModifier})`
|
|
132
|
+
: `(${shaderModifier.toString()})`;
|
|
128
133
|
strandsCallback = transpileStrandsToJS(
|
|
129
134
|
p5,
|
|
130
135
|
sourceString,
|
|
@@ -185,8 +190,6 @@ if (typeof p5 !== "undefined") {
|
|
|
185
190
|
* - <a href="#/p5/buildStrokeShader">`buildStrokeShader()`</a>
|
|
186
191
|
*
|
|
187
192
|
* @example
|
|
188
|
-
* <div modernizr='webgl'>
|
|
189
|
-
* <code>
|
|
190
193
|
* let myShader;
|
|
191
194
|
* function setup() {
|
|
192
195
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -212,8 +215,6 @@ if (typeof p5 !== "undefined") {
|
|
|
212
215
|
* fill('red');
|
|
213
216
|
* sphere(50);
|
|
214
217
|
* }
|
|
215
|
-
* </code>
|
|
216
|
-
* </div>
|
|
217
218
|
*/
|
|
218
219
|
|
|
219
220
|
/**
|
|
@@ -238,8 +239,6 @@ if (typeof p5 !== "undefined") {
|
|
|
238
239
|
* - <a href="#/p5/buildMaterialShader">`buildMaterialShader()`</a>
|
|
239
240
|
*
|
|
240
241
|
* @example
|
|
241
|
-
* <div modernizr='webgl'>
|
|
242
|
-
* <code>
|
|
243
242
|
* let myShader;
|
|
244
243
|
* function setup() {
|
|
245
244
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -268,6 +267,98 @@ if (typeof p5 !== "undefined") {
|
|
|
268
267
|
* fill('white');
|
|
269
268
|
* sphere(50);
|
|
270
269
|
* }
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @method smoothstep
|
|
274
|
+
* @description
|
|
275
|
+
* A shader function that performs smooth Hermite interpolation between `0.0`
|
|
276
|
+
* and `1.0`.
|
|
277
|
+
*
|
|
278
|
+
* This function is equivalent to the GLSL built-in
|
|
279
|
+
* `smoothstep(edge0, edge1, x)` and is available inside p5.strands shader
|
|
280
|
+
* callbacks. It is commonly used to create soft transitions, smooth edges,
|
|
281
|
+
* fades, and anti-aliased effects.
|
|
282
|
+
*
|
|
283
|
+
* Smoothstep is useful when a threshold or cutoff is needed, but with a
|
|
284
|
+
* gradual transition instead of a hard edge.
|
|
285
|
+
*
|
|
286
|
+
* - Returns `0.0` when `x` is less than or equal to `edge0`
|
|
287
|
+
* - Returns `1.0` when `x` is greater than or equal to `edge1`
|
|
288
|
+
* - Smoothly interpolates between `0.0` and `1.0` when `x` is between them
|
|
289
|
+
*
|
|
290
|
+
* @param {Number} edge0
|
|
291
|
+
* Lower edge of the transition
|
|
292
|
+
* @param {Number} edge1
|
|
293
|
+
* Upper edge of the transition
|
|
294
|
+
* @param {Number} x
|
|
295
|
+
* Input value to interpolate
|
|
296
|
+
*
|
|
297
|
+
* @returns {Number}
|
|
298
|
+
* A value between `0.0` and `1.0`
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* <div modernizr="webgl">
|
|
302
|
+
* <code>
|
|
303
|
+
* // Example 1: A soft vertical fade using smoothstep (no uniforms)
|
|
304
|
+
*
|
|
305
|
+
* let fadeShader;
|
|
306
|
+
*
|
|
307
|
+
* function fadeCallback() {
|
|
308
|
+
* getColor((inputs) => {
|
|
309
|
+
* // x goes from 0 → 1 across the canvas
|
|
310
|
+
* let x = inputs.texCoord.x;
|
|
311
|
+
*
|
|
312
|
+
* // smoothstep creates a soft transition instead of a hard edge
|
|
313
|
+
* let t = smoothstep(0.25, 0.35, x);
|
|
314
|
+
*
|
|
315
|
+
* // Use t directly as brightness
|
|
316
|
+
* return [t, t, t, 1];
|
|
317
|
+
* });
|
|
318
|
+
* }
|
|
319
|
+
*
|
|
320
|
+
* function setup() {
|
|
321
|
+
* createCanvas(300, 200, WEBGL);
|
|
322
|
+
* fadeShader = baseFilterShader().modify(fadeCallback);
|
|
323
|
+
* }
|
|
324
|
+
*
|
|
325
|
+
* function draw() {
|
|
326
|
+
* background(0);
|
|
327
|
+
* filter(fadeShader);
|
|
328
|
+
* }
|
|
329
|
+
* </code>
|
|
330
|
+
* </div>
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* <div modernizr="webgl">
|
|
334
|
+
* <code>
|
|
335
|
+
* // Example 2: Animate the smooth transition using a uniform
|
|
336
|
+
*
|
|
337
|
+
* let animatedShader;
|
|
338
|
+
*
|
|
339
|
+
* function animatedFadeCallback() {
|
|
340
|
+
* const time = uniformFloat(() => millis() * 0.001);
|
|
341
|
+
*
|
|
342
|
+
* getColor((inputs) => {
|
|
343
|
+
* let x = inputs.texCoord.x;
|
|
344
|
+
*
|
|
345
|
+
* // Move the smoothstep band back and forth over time
|
|
346
|
+
* let center = 0.5 + 0.25 * sin(time);
|
|
347
|
+
* let t = smoothstep(center - 0.05, center + 0.05, x);
|
|
348
|
+
*
|
|
349
|
+
* return [t, t, t, 1];
|
|
350
|
+
* });
|
|
351
|
+
* }
|
|
352
|
+
*
|
|
353
|
+
* function setup() {
|
|
354
|
+
* createCanvas(300, 200, WEBGL);
|
|
355
|
+
* animatedShader = baseFilterShader().modify(animatedFadeCallback);
|
|
356
|
+
* }
|
|
357
|
+
*
|
|
358
|
+
* function draw() {
|
|
359
|
+
* background(0);
|
|
360
|
+
* filter(animatedShader);
|
|
361
|
+
* }
|
|
271
362
|
* </code>
|
|
272
363
|
* </div>
|
|
273
364
|
*/
|
|
@@ -324,8 +415,6 @@ if (typeof p5 !== "undefined") {
|
|
|
324
415
|
* A callback function which is called before each fragment is processed.
|
|
325
416
|
*
|
|
326
417
|
* @example
|
|
327
|
-
* <div modernizr='webgl'>
|
|
328
|
-
* <code>
|
|
329
418
|
* let myShader;
|
|
330
419
|
* function setup() {
|
|
331
420
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -341,6 +430,7 @@ if (typeof p5 !== "undefined") {
|
|
|
341
430
|
* });
|
|
342
431
|
* });
|
|
343
432
|
* }
|
|
433
|
+
*
|
|
344
434
|
* function draw() {
|
|
345
435
|
* background(220);
|
|
346
436
|
* shader(myShader);
|
|
@@ -348,8 +438,6 @@ if (typeof p5 !== "undefined") {
|
|
|
348
438
|
* fill('teal');
|
|
349
439
|
* box(100);
|
|
350
440
|
* }
|
|
351
|
-
* </code>
|
|
352
|
-
* </div>
|
|
353
441
|
*/
|
|
354
442
|
|
|
355
443
|
/**
|
|
@@ -382,8 +470,6 @@ if (typeof p5 !== "undefined") {
|
|
|
382
470
|
* - <a href="#/p5/buildStrokeShader">`buildStrokeShader()`</a>
|
|
383
471
|
*
|
|
384
472
|
* @example
|
|
385
|
-
* <div modernizr='webgl'>
|
|
386
|
-
* <code>
|
|
387
473
|
* let myShader;
|
|
388
474
|
* function setup() {
|
|
389
475
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -408,8 +494,6 @@ if (typeof p5 !== "undefined") {
|
|
|
408
494
|
* fill('purple');
|
|
409
495
|
* circle(0, 0, 100);
|
|
410
496
|
* }
|
|
411
|
-
* </code>
|
|
412
|
-
* </div>
|
|
413
497
|
*/
|
|
414
498
|
|
|
415
499
|
/**
|
|
@@ -428,8 +512,6 @@ if (typeof p5 !== "undefined") {
|
|
|
428
512
|
* A callback function which receives a boolean and should return a boolean.
|
|
429
513
|
*
|
|
430
514
|
* @example
|
|
431
|
-
* <div modernizr='webgl'>
|
|
432
|
-
* <code>
|
|
433
515
|
* let myShader;
|
|
434
516
|
* function setup() {
|
|
435
517
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -437,14 +519,13 @@ if (typeof p5 !== "undefined") {
|
|
|
437
519
|
* 'bool shouldDiscard': '(bool outside) { return outside; }'
|
|
438
520
|
* });
|
|
439
521
|
* }
|
|
522
|
+
*
|
|
440
523
|
* function draw() {
|
|
441
524
|
* background(255);
|
|
442
525
|
* strokeShader(myShader);
|
|
443
526
|
* strokeWeight(30);
|
|
444
527
|
* line(-width/3, 0, width/3, 0);
|
|
445
528
|
* }
|
|
446
|
-
* </code>
|
|
447
|
-
* </div>
|
|
448
529
|
*/
|
|
449
530
|
|
|
450
531
|
/**
|
|
@@ -464,8 +545,6 @@ if (typeof p5 !== "undefined") {
|
|
|
464
545
|
* - <a href="#/p5/buildStrokeShader">`buildStrokeShader()`</a>
|
|
465
546
|
*
|
|
466
547
|
* @example
|
|
467
|
-
* <div modernizr='webgl'>
|
|
468
|
-
* <code>
|
|
469
548
|
* let myShader;
|
|
470
549
|
* function setup() {
|
|
471
550
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -488,8 +567,6 @@ if (typeof p5 !== "undefined") {
|
|
|
488
567
|
* fill('green');
|
|
489
568
|
* circle(0, 0, 100);
|
|
490
569
|
* }
|
|
491
|
-
* </code>
|
|
492
|
-
* </div>
|
|
493
570
|
*/
|
|
494
571
|
|
|
495
572
|
/**
|
|
@@ -508,8 +585,6 @@ if (typeof p5 !== "undefined") {
|
|
|
508
585
|
* A callback function which is called after each fragment is processed.
|
|
509
586
|
*
|
|
510
587
|
* @example
|
|
511
|
-
* <div modernizr='webgl'>
|
|
512
|
-
* <code>
|
|
513
588
|
* let myShader;
|
|
514
589
|
* function setup() {
|
|
515
590
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -525,6 +600,7 @@ if (typeof p5 !== "undefined") {
|
|
|
525
600
|
* });
|
|
526
601
|
* });
|
|
527
602
|
* }
|
|
603
|
+
*
|
|
528
604
|
* function draw() {
|
|
529
605
|
* background(240);
|
|
530
606
|
* shader(myShader);
|
|
@@ -532,8 +608,6 @@ if (typeof p5 !== "undefined") {
|
|
|
532
608
|
* fill('purple');
|
|
533
609
|
* sphere(60);
|
|
534
610
|
* }
|
|
535
|
-
* </code>
|
|
536
|
-
* </div>
|
|
537
611
|
*/
|
|
538
612
|
|
|
539
613
|
/**
|
|
@@ -553,8 +627,6 @@ if (typeof p5 !== "undefined") {
|
|
|
553
627
|
* - <a href="#/p5/buildFilterShader">`buildFilterShader()`</a>
|
|
554
628
|
*
|
|
555
629
|
* @example
|
|
556
|
-
* <div modernizr='webgl'>
|
|
557
|
-
* <code>
|
|
558
630
|
* let myShader;
|
|
559
631
|
* function setup() {
|
|
560
632
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -579,8 +651,6 @@ if (typeof p5 !== "undefined") {
|
|
|
579
651
|
* circle(0, 0, 150);
|
|
580
652
|
* filter(myShader);
|
|
581
653
|
* }
|
|
582
|
-
* </code>
|
|
583
|
-
* </div>
|
|
584
654
|
*/
|
|
585
655
|
|
|
586
656
|
/**
|
|
@@ -601,8 +671,6 @@ if (typeof p5 !== "undefined") {
|
|
|
601
671
|
* - <a href="#/p5/buildStrokeShader">`buildStrokeShader()`</a>
|
|
602
672
|
*
|
|
603
673
|
* @example
|
|
604
|
-
* <div modernizr='webgl'>
|
|
605
|
-
* <code>
|
|
606
674
|
* let myShader;
|
|
607
675
|
* function setup() {
|
|
608
676
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -625,8 +693,6 @@ if (typeof p5 !== "undefined") {
|
|
|
625
693
|
* fill('orange');
|
|
626
694
|
* sphere(50);
|
|
627
695
|
* }
|
|
628
|
-
* </code>
|
|
629
|
-
* </div>
|
|
630
696
|
*/
|
|
631
697
|
|
|
632
698
|
/**
|
|
@@ -647,8 +713,6 @@ if (typeof p5 !== "undefined") {
|
|
|
647
713
|
* - <a href="#/p5/buildStrokeShader">`buildStrokeShader()`</a>
|
|
648
714
|
*
|
|
649
715
|
* @example
|
|
650
|
-
* <div modernizr='webgl'>
|
|
651
|
-
* <code>
|
|
652
716
|
* let myShader;
|
|
653
717
|
* function setup() {
|
|
654
718
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -673,6 +737,144 @@ if (typeof p5 !== "undefined") {
|
|
|
673
737
|
* fill('red');
|
|
674
738
|
* sphere(50);
|
|
675
739
|
* }
|
|
740
|
+
*/
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Retrieves the current color of a given texture at given coordinates.
|
|
744
|
+
*
|
|
745
|
+
* The given coordinates should be between [0, 0] representing the top-left of
|
|
746
|
+
* the texture, and [1, 1] representing the bottom-right of the texture.
|
|
747
|
+
*
|
|
748
|
+
* The given texture could be, for example:
|
|
749
|
+
* * <a href="#/p5.Image">p5.Image</a>,
|
|
750
|
+
* * a <a href="#/p5.Graphics">p5.Graphics</a>, or
|
|
751
|
+
* * a <a href="#/p5.Framebuffer">p5.Framebuffer</a>.
|
|
752
|
+
*
|
|
753
|
+
* The retrieved color that is returned will behave like a vec4, with components
|
|
754
|
+
* for red, green, blue, and alpha, each between 0.0 and 1.0.
|
|
755
|
+
*
|
|
756
|
+
* Linear interpolation is used by default. For Framebuffer sources, you can
|
|
757
|
+
* prevent this by creating the buffer with:
|
|
758
|
+
* ```js
|
|
759
|
+
* createFramebuffer({
|
|
760
|
+
* textureFiltering: NEAREST
|
|
761
|
+
* })
|
|
762
|
+
* ```
|
|
763
|
+
* This can be useful if you are using your texture to store data other than color.
|
|
764
|
+
* See <a href="#/p5/createFramebuffer/">createFramebuffer</a>.
|
|
765
|
+
*
|
|
766
|
+
* Note: The `getTexture` function is only available when using p5.strands.
|
|
767
|
+
*
|
|
768
|
+
* @method getTexture
|
|
769
|
+
* @beta
|
|
770
|
+
*
|
|
771
|
+
* @param texture The texture to sample from.
|
|
772
|
+
* (e.g. a p5.Image, p5.Graphics, or p5.Framebuffer).
|
|
773
|
+
*
|
|
774
|
+
* @param coords The 2D coordinates to sample from.
|
|
775
|
+
* This should be between [0,0] (the top-left) and [1,1] (the bottom-right)
|
|
776
|
+
* of the texture. It should be compatible with a vec2.
|
|
777
|
+
*
|
|
778
|
+
* @returns {*} The color of the given texture at the given coordinates. This
|
|
779
|
+
* will behave as a vec4 holding components r, g, b, and a (alpha), with each component being in the range 0.0 to 1.0.
|
|
780
|
+
*
|
|
781
|
+
* @example
|
|
782
|
+
* <div modernizr='webgl'>
|
|
783
|
+
* <code>
|
|
784
|
+
* // A filter shader (using p5.strands) which will
|
|
785
|
+
* // sample and invert the color of each pixel
|
|
786
|
+
* // from the canvas.
|
|
787
|
+
* function setup() {
|
|
788
|
+
* createCanvas(100, 100, WEBGL);
|
|
789
|
+
* let myShader = buildFilterShader(buildIt);
|
|
790
|
+
*
|
|
791
|
+
* background("white");
|
|
792
|
+
* fill("red");
|
|
793
|
+
* circle(0, 0, 50);
|
|
794
|
+
*
|
|
795
|
+
* filter(myShader); //Try commenting this out!
|
|
796
|
+
*
|
|
797
|
+
* describe("A cyan circle on black background");
|
|
798
|
+
* }
|
|
799
|
+
*
|
|
800
|
+
* function buildIt() {
|
|
801
|
+
* filterColor.begin();
|
|
802
|
+
*
|
|
803
|
+
* //Sample the color of the pixel from the
|
|
804
|
+
* //canvas at the same coordinate.
|
|
805
|
+
* let c = getTexture(filterColor.canvasContent,
|
|
806
|
+
* filterColor.texCoord);
|
|
807
|
+
*
|
|
808
|
+
* //Make a new color by inverting r, g, and b
|
|
809
|
+
* let newColor = [1 - c.r, 1 - c.g, 1 - c.b, c.a];
|
|
810
|
+
*
|
|
811
|
+
* //Finally, use it for this pixel!
|
|
812
|
+
* filterColor.set(newColor);
|
|
813
|
+
*
|
|
814
|
+
* filterColor.end();
|
|
815
|
+
* }
|
|
816
|
+
* </code>
|
|
817
|
+
*
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* <div modernizr='webgl'>
|
|
821
|
+
* <code>
|
|
822
|
+
* // This primitive edge-detection filter samples
|
|
823
|
+
* // and compares the colors of the current pixel
|
|
824
|
+
* // on the canvas, and a little to the right.
|
|
825
|
+
* // It marks if they differ much.
|
|
826
|
+
* let myShader;
|
|
827
|
+
*
|
|
828
|
+
* function setup() {
|
|
829
|
+
* createCanvas(100, 100, WEBGL);
|
|
830
|
+
* myShader = buildFilterShader(myShaderBuilder);
|
|
831
|
+
* describe("A rough partial outline of a square rotating around a circle");
|
|
832
|
+
* }
|
|
833
|
+
*
|
|
834
|
+
* function draw() {
|
|
835
|
+
* drawADesign();
|
|
836
|
+
*
|
|
837
|
+
* filter(myShader); // try commenting this out
|
|
838
|
+
* }
|
|
839
|
+
*
|
|
840
|
+
* function myShaderBuilder() {
|
|
841
|
+
* filterColor.begin();
|
|
842
|
+
*
|
|
843
|
+
* //The position of the current pixel...
|
|
844
|
+
* let coordHere = filterColor.texCoord;
|
|
845
|
+
* //and some small amount to the right.
|
|
846
|
+
* let coordRight = coordHere + [0.01, 0];
|
|
847
|
+
*
|
|
848
|
+
* //The canvas content is a texture.
|
|
849
|
+
* let cnvTex = filterColor.canvasContent;
|
|
850
|
+
*
|
|
851
|
+
* //Sample the colors from it at our two positions
|
|
852
|
+
* let colorHere = getTexture(cnvTex, coordHere);
|
|
853
|
+
* let colorRight = getTexture(cnvTex, coordRight);
|
|
854
|
+
*
|
|
855
|
+
* // Calculate a (very rough) color difference.
|
|
856
|
+
* let difference = length(colorHere - colorRight);
|
|
857
|
+
*
|
|
858
|
+
* //We'll use a black color by default...
|
|
859
|
+
* let resultColor = [0, 0, 0, 1];
|
|
860
|
+
* //or white if the samples were different.
|
|
861
|
+
* if (difference > 0.3) {
|
|
862
|
+
* resultColor = [1, 1, 1, 1];
|
|
863
|
+
* }
|
|
864
|
+
* filterColor.set(resultColor);
|
|
865
|
+
*
|
|
866
|
+
* filterColor.end();
|
|
867
|
+
* }
|
|
868
|
+
*
|
|
869
|
+
* //Draw a few shapes, just to test the filter with
|
|
870
|
+
* function drawADesign() {
|
|
871
|
+
* background(50);
|
|
872
|
+
* noStroke();
|
|
873
|
+
* lights();
|
|
874
|
+
* sphere(20);
|
|
875
|
+
* rotate(frameCount / 300);
|
|
876
|
+
* square(0, 0, 30);
|
|
877
|
+
* }
|
|
676
878
|
* </code>
|
|
677
879
|
* </div>
|
|
678
880
|
*/
|
package/dist/type/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import textCore from './textCore.js';
|
|
2
2
|
import font from './p5.Font.js';
|
|
3
|
-
import '../p5.Renderer-
|
|
4
|
-
import '../creating_reading-
|
|
3
|
+
import '../p5.Renderer-D-5LdCRz.js';
|
|
4
|
+
import '../creating_reading-ZXzcZEsb.js';
|
|
5
5
|
import 'colorjs.io/fn';
|
|
6
6
|
import '../color/color_spaces/hsb.js';
|
|
7
|
-
import '../constants-
|
|
7
|
+
import '../constants-DQyACdzq.js';
|
|
8
8
|
import '../image/filters.js';
|
|
9
9
|
import '../math/p5.Vector.js';
|
|
10
10
|
import '../shape/custom_shapes.js';
|
|
11
11
|
import '../core/States.js';
|
|
12
12
|
import '../io/utilities.js';
|
|
13
|
-
import 'file-saver';
|
|
14
13
|
import '@japont/unicode-range';
|
|
15
14
|
import './unicodeRanges.js';
|
|
16
15
|
import './lib/Typr.js';
|
package/dist/type/p5.Font.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { textCoreConstants } from './textCore.js';
|
|
2
|
-
import { v as CENTER, a9 as RIGHT, u as RADIUS } from '../constants-
|
|
2
|
+
import { v as CENTER, a9 as RIGHT, u as RADIUS } from '../constants-DQyACdzq.js';
|
|
3
3
|
import { UnicodeRange } from '@japont/unicode-range';
|
|
4
4
|
import { unicodeRanges } from './unicodeRanges.js';
|
|
5
5
|
import { Vector } from '../math/p5.Vector.js';
|
|
6
6
|
import Typr from './lib/Typr.js';
|
|
7
7
|
import { createFromCommands } from '@davepagurek/bezier-path';
|
|
8
|
-
import '../p5.Renderer-
|
|
9
|
-
import '../creating_reading-
|
|
8
|
+
import '../p5.Renderer-D-5LdCRz.js';
|
|
9
|
+
import '../creating_reading-ZXzcZEsb.js';
|
|
10
10
|
import 'colorjs.io/fn';
|
|
11
11
|
import '../color/color_spaces/hsb.js';
|
|
12
12
|
import '../image/filters.js';
|
|
13
13
|
import '../shape/custom_shapes.js';
|
|
14
14
|
import '../core/States.js';
|
|
15
15
|
import '../io/utilities.js';
|
|
16
|
-
import 'file-saver';
|
|
17
16
|
import 'pako';
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -90,8 +89,6 @@ class Font {
|
|
|
90
89
|
* @return {Array<Array>} A flat array of path commands.
|
|
91
90
|
*
|
|
92
91
|
* @example
|
|
93
|
-
* <div>
|
|
94
|
-
* <code>
|
|
95
92
|
* let font;
|
|
96
93
|
*
|
|
97
94
|
* async function setup() {
|
|
@@ -168,10 +165,7 @@ class Font {
|
|
|
168
165
|
* endContour();
|
|
169
166
|
* endShape();
|
|
170
167
|
* }
|
|
171
|
-
* </code>
|
|
172
|
-
* </div>
|
|
173
168
|
*/
|
|
174
|
-
|
|
175
169
|
textToPaths(str, x, y, width, height, options) {
|
|
176
170
|
|
|
177
171
|
({ width, height, options } = this._parseArgs(width, height, options));
|
|
@@ -224,8 +218,6 @@ class Font {
|
|
|
224
218
|
* @return {Array<Object>} array of point objects, each with `x`, `y`, and `alpha` (path angle) properties.
|
|
225
219
|
*
|
|
226
220
|
* @example
|
|
227
|
-
* <div>
|
|
228
|
-
* <code>
|
|
229
221
|
* let font;
|
|
230
222
|
*
|
|
231
223
|
* async function setup() {
|
|
@@ -245,8 +237,6 @@ class Font {
|
|
|
245
237
|
*
|
|
246
238
|
* describe('A set of black dots outlining the text "p5*js" on a gray background.');
|
|
247
239
|
* }
|
|
248
|
-
* </code>
|
|
249
|
-
* </div>
|
|
250
240
|
*/
|
|
251
241
|
textToPoints(str, x, y, width, height, options) {
|
|
252
242
|
// By segmenting per contour, pointAtLength becomes much faster
|
|
@@ -296,8 +286,6 @@ class Font {
|
|
|
296
286
|
* @return {Array<Array<Object>>} array of point objects, each with `x`, `y`, and `alpha` (path angle) properties.
|
|
297
287
|
*
|
|
298
288
|
* @example
|
|
299
|
-
* <div>
|
|
300
|
-
* <code>
|
|
301
289
|
* let font;
|
|
302
290
|
*
|
|
303
291
|
* async function setup() {
|
|
@@ -325,8 +313,6 @@ class Font {
|
|
|
325
313
|
*
|
|
326
314
|
* describe('The text p5*js wobbling over time');
|
|
327
315
|
* }
|
|
328
|
-
* </code>
|
|
329
|
-
* </div>
|
|
330
316
|
*/
|
|
331
317
|
textToContours(str, x = 0, y = 0, width, height, options) {
|
|
332
318
|
({ width, height, options } = this._parseArgs(width, height, options));
|
|
@@ -377,8 +363,6 @@ class Font {
|
|
|
377
363
|
* @return {p5.Geometry} A geometry object representing the 3D model of the text.
|
|
378
364
|
*
|
|
379
365
|
* @example
|
|
380
|
-
* <div modernizr='webgl'>
|
|
381
|
-
* <code>
|
|
382
366
|
* let font;
|
|
383
367
|
* let geom;
|
|
384
368
|
*
|
|
@@ -400,12 +384,8 @@ class Font {
|
|
|
400
384
|
* model(geom);
|
|
401
385
|
* describe('A red non-extruded "Hello" in Anton on white canvas, rotatable via mouse.');
|
|
402
386
|
* }
|
|
403
|
-
* </code>
|
|
404
|
-
* </div>
|
|
405
387
|
*
|
|
406
388
|
* @example
|
|
407
|
-
* <div modernizr='webgl'>
|
|
408
|
-
* <code>
|
|
409
389
|
* let font;
|
|
410
390
|
* let geom;
|
|
411
391
|
*
|
|
@@ -434,12 +414,8 @@ class Font {
|
|
|
434
414
|
* model(geom);
|
|
435
415
|
* describe('3D red extruded "Hello" in Source Serif on white, rotatable via mouse.');
|
|
436
416
|
* }
|
|
437
|
-
* </code>
|
|
438
|
-
* </div>
|
|
439
417
|
*
|
|
440
418
|
* @example
|
|
441
|
-
* <div modernizr='webgl'>
|
|
442
|
-
* <code>
|
|
443
419
|
* let geom;
|
|
444
420
|
* let activeFont;
|
|
445
421
|
* let artShader;
|
|
@@ -514,8 +490,6 @@ class Font {
|
|
|
514
490
|
* model(geom);
|
|
515
491
|
* describe('3D wavy with different color sets "Hello" in Anton on white canvas, rotatable via mouse.');
|
|
516
492
|
* }
|
|
517
|
-
* </code>
|
|
518
|
-
* </div>
|
|
519
493
|
*/
|
|
520
494
|
textToModel(str, x, y, width, height, options) {
|
|
521
495
|
({ width, height, options } = this._parseArgs(width, height, options));
|
|
@@ -1340,8 +1314,6 @@ function font(p5, fn) {
|
|
|
1340
1314
|
* object if the font fails to load.
|
|
1341
1315
|
* @return {Promise<p5.Font>} <a href="#/p5.Font">p5.Font</a> object.
|
|
1342
1316
|
* @example
|
|
1343
|
-
* <div>
|
|
1344
|
-
* <code>
|
|
1345
1317
|
* let font;
|
|
1346
1318
|
*
|
|
1347
1319
|
* async function setup() {
|
|
@@ -1354,12 +1326,8 @@ function font(p5, fn) {
|
|
|
1354
1326
|
*
|
|
1355
1327
|
* describe('The text "p5*js" written in pink on a white background.');
|
|
1356
1328
|
* }
|
|
1357
|
-
* </code>
|
|
1358
|
-
* </div>
|
|
1359
1329
|
*
|
|
1360
1330
|
* @example
|
|
1361
|
-
* <div>
|
|
1362
|
-
* <code>
|
|
1363
1331
|
* function setup() {
|
|
1364
1332
|
* createCanvas(100, 100);
|
|
1365
1333
|
* loadFont('assets/inconsolata.otf', font => {
|
|
@@ -1371,12 +1339,8 @@ function font(p5, fn) {
|
|
|
1371
1339
|
* describe('The text "p5*js" written in pink on a white background.');
|
|
1372
1340
|
* });
|
|
1373
1341
|
* }
|
|
1374
|
-
* </code>
|
|
1375
|
-
* </div>
|
|
1376
1342
|
*
|
|
1377
1343
|
* @example
|
|
1378
|
-
* <div>
|
|
1379
|
-
* <code>
|
|
1380
1344
|
* function setup() {
|
|
1381
1345
|
* createCanvas(100, 100);
|
|
1382
1346
|
* loadFont('assets/inconsolata.otf', success, failure);
|
|
@@ -1394,12 +1358,8 @@ function font(p5, fn) {
|
|
|
1394
1358
|
* function failure(event) {
|
|
1395
1359
|
* console.error('Oops!', event);
|
|
1396
1360
|
* }
|
|
1397
|
-
* </code>
|
|
1398
|
-
* </div>
|
|
1399
1361
|
*
|
|
1400
1362
|
* @example
|
|
1401
|
-
* <div>
|
|
1402
|
-
* <code>
|
|
1403
1363
|
* async function setup() {
|
|
1404
1364
|
* createCanvas(100, 100);
|
|
1405
1365
|
* await loadFont('assets/inconsolata.otf');
|
|
@@ -1411,18 +1371,13 @@ function font(p5, fn) {
|
|
|
1411
1371
|
*
|
|
1412
1372
|
* describe('The text "p5*js" written in pink on a white background.');
|
|
1413
1373
|
* }
|
|
1414
|
-
* </code>
|
|
1415
|
-
* </div>
|
|
1416
1374
|
*
|
|
1417
1375
|
* @example
|
|
1418
|
-
*
|
|
1419
|
-
* <code>
|
|
1376
|
+
* // META:norender
|
|
1420
1377
|
* // Some other forms of loading fonts:
|
|
1421
1378
|
* loadFont("https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,200..800&display=swap");
|
|
1422
1379
|
*
|
|
1423
1380
|
* loadFont('@font-face { font-family: "Bricolage Grotesque", serif; font-optical-sizing: auto; font-weight: 400; font-style: normal; font-variation-settings: "wdth" 100; }');
|
|
1424
|
-
* </code>
|
|
1425
|
-
* </div>
|
|
1426
1381
|
*/
|
|
1427
1382
|
/**
|
|
1428
1383
|
* @method loadFont
|