p5 2.2.3 → 2.3.0-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.
- package/dist/accessibility/color_namer.js +9 -11
- package/dist/accessibility/describe.js +0 -1
- package/dist/accessibility/gridOutput.js +0 -1
- package/dist/accessibility/index.js +9 -10
- package/dist/accessibility/outputs.js +0 -1
- package/dist/accessibility/textOutput.js +0 -1
- package/dist/app.js +11 -10
- package/dist/app.node.js +122 -0
- package/dist/color/color_conversion.js +9 -11
- 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 +25 -12
- package/dist/{constants-BdTiYOQI.js → constants-0wkVUfqa.js} +2 -2
- package/dist/core/States.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +28 -29
- package/dist/core/filterShaders.js +1 -1
- package/dist/core/friendly_errors/fes_core.js +9 -8
- package/dist/core/friendly_errors/file_errors.js +1 -2
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +737 -640
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/friendly_errors/stacktrace.js +0 -1
- package/dist/core/helpers.js +3 -4
- package/dist/core/init.js +24 -21
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +9 -11
- package/dist/core/main.js +9 -10
- package/dist/core/p5.Graphics.js +5 -5
- package/dist/core/p5.Renderer.js +3 -3
- package/dist/core/p5.Renderer2D.js +9 -10
- package/dist/core/p5.Renderer3D.js +5 -5
- package/dist/core/rendering.js +5 -5
- package/dist/core/structure.js +0 -1
- package/dist/core/transform.js +7 -16
- package/dist/{creating_reading-C7hu6sg1.js → creating_reading-DLkHH80h.js} +11 -8
- package/dist/data/local_storage.js +0 -1
- package/dist/dom/dom.js +2 -3
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +2 -2
- package/dist/dom/p5.MediaElement.js +2 -2
- package/dist/events/acceleration.js +5 -3
- package/dist/events/keyboard.js +0 -1
- package/dist/events/pointer.js +0 -2
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +19 -12
- package/dist/image/image.js +5 -5
- package/dist/image/index.js +5 -5
- package/dist/image/loading_displaying.js +5 -5
- package/dist/image/p5.Image.js +3 -3
- package/dist/image/pixels.js +0 -1
- package/dist/io/files.js +5 -5
- package/dist/io/index.js +5 -5
- package/dist/io/p5.Table.js +0 -1
- package/dist/io/p5.TableRow.js +0 -1
- package/dist/io/p5.XML.js +0 -1
- package/dist/{ir_builders-Cd6rU9Vm.js → ir_builders-C2ebb6Lu.js} +234 -1
- package/dist/{main-H_nu4eDs.js → main-D2kqeMXM.js} +107 -136
- package/dist/math/Matrices/Matrix.js +1 -1
- package/dist/math/Matrices/MatrixNumjs.js +1 -1
- package/dist/math/calculation.js +0 -1
- package/dist/math/index.js +3 -1
- package/dist/math/math.js +3 -17
- package/dist/math/noise.js +0 -1
- package/dist/math/p5.Matrix.js +1 -2
- package/dist/math/p5.Vector.js +237 -279
- package/dist/math/patch-vector.js +75 -0
- package/dist/math/random.js +0 -1
- package/dist/math/trigonometry.js +3 -4
- package/dist/{p5.Renderer-BmD2P6Wv.js → p5.Renderer-CQI8PO1F.js} +31 -24
- package/dist/{rendering-CC8JNTwG.js → rendering-ltTIxpF2.js} +732 -44
- package/dist/shape/2d_primitives.js +1 -4
- package/dist/shape/attributes.js +43 -8
- package/dist/shape/curves.js +0 -1
- package/dist/shape/custom_shapes.js +260 -5
- package/dist/shape/index.js +2 -2
- package/dist/shape/vertex.js +0 -2
- package/dist/strands/ir_builders.js +1 -1
- package/dist/strands/ir_types.js +5 -1
- package/dist/strands/p5.strands.js +286 -31
- package/dist/strands/strands_api.js +179 -8
- package/dist/strands/strands_codegen.js +26 -8
- package/dist/strands/strands_conditionals.js +1 -1
- package/dist/strands/strands_for.js +1 -1
- package/dist/strands/strands_node.js +1 -1
- package/dist/strands/strands_ternary.js +56 -0
- package/dist/strands/strands_transpiler.js +416 -251
- package/dist/strands_glslBackend-i-ReKgZo.js +423 -0
- package/dist/type/index.js +3 -3
- package/dist/type/lib/Typr.js +1 -1
- package/dist/type/p5.Font.js +3 -3
- package/dist/type/textCore.js +31 -24
- package/dist/utilities/conversion.js +0 -1
- package/dist/utilities/time_date.js +0 -1
- package/dist/utilities/utility_functions.js +0 -1
- package/dist/webgl/3d_primitives.js +5 -5
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +26 -1
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +8 -9
- package/dist/webgl/interaction.js +8 -4
- package/dist/webgl/light.js +5 -5
- package/dist/webgl/loading.js +60 -21
- package/dist/webgl/material.js +5 -5
- package/dist/webgl/p5.Camera.js +5 -5
- package/dist/webgl/p5.Framebuffer.js +5 -5
- package/dist/webgl/p5.Geometry.js +3 -5
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +17 -21
- package/dist/webgl/p5.Shader.js +129 -36
- package/dist/webgl/p5.Texture.js +5 -5
- package/dist/webgl/strands_glslBackend.js +5 -386
- package/dist/webgl/text.js +5 -5
- package/dist/webgl/utils.js +5 -5
- package/dist/webgl2Compatibility-DA7DLMuq.js +7 -0
- package/dist/webgpu/index.js +7 -3
- package/dist/webgpu/p5.RendererWebGPU.js +1146 -180
- package/dist/webgpu/shaders/color.js +1 -1
- package/dist/webgpu/shaders/compute.js +32 -0
- package/dist/webgpu/shaders/functions/randomComputeWGSL.js +31 -0
- package/dist/webgpu/shaders/functions/randomVertWGSL.js +30 -0
- package/dist/webgpu/shaders/functions/randomWGSL.js +30 -0
- package/dist/webgpu/shaders/line.js +1 -1
- package/dist/webgpu/shaders/material.js +3 -3
- package/dist/webgpu/strands_wgslBackend.js +137 -15
- package/lib/p5.esm.js +4092 -1950
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +4092 -1950
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +1748 -306
- package/lib/p5.webgpu.js +1747 -305
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +6 -1
- package/types/global.d.ts +4182 -2441
- package/types/p5.d.ts +2776 -1675
- package/dist/noise3DGLSL-Bwrdi4gi.js +0 -9
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as CORNER, o as TWO_PI, p as HALF_PI, q as PI } from '../constants-0wkVUfqa.js';
|
|
2
2
|
import canvas from '../core/helpers.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @module Shape
|
|
6
6
|
* @submodule 2D Primitives
|
|
7
7
|
* @for p5
|
|
8
|
-
* @requires core
|
|
9
|
-
* @requires constants
|
|
10
8
|
*/
|
|
11
9
|
|
|
12
10
|
|
|
@@ -1080,7 +1078,6 @@ function primitives(p5, fn){
|
|
|
1080
1078
|
* rect(-20, -30, 55, 55);
|
|
1081
1079
|
* }
|
|
1082
1080
|
*/
|
|
1083
|
-
|
|
1084
1081
|
/**
|
|
1085
1082
|
* @method rect
|
|
1086
1083
|
* @param {Number} x
|
package/dist/shape/attributes.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as CORNER, r as CORNERS, s as RADIUS, t as CENTER, u as ROUND, v as SQUARE, w as PROJECT, x as BEVEL, y as MITER } from '../constants-0wkVUfqa.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @module Shape
|
|
5
5
|
* @submodule Attributes
|
|
6
6
|
* @for p5
|
|
7
|
-
* @requires core
|
|
8
|
-
* @requires constants
|
|
9
7
|
*/
|
|
10
8
|
|
|
11
9
|
|
|
@@ -36,6 +34,8 @@ function attributes(p5, fn){
|
|
|
36
34
|
* the constants `CENTER`, `RADIUS`, `CORNER`, and `CORNERS` are defined this
|
|
37
35
|
* way. JavaScript is a case-sensitive language.
|
|
38
36
|
*
|
|
37
|
+
* Calling `ellipseMode()` without an argument returns the current ellipseMode, either `CENTER`, `RADIUS`, `CORNER`, or `CORNERS`.
|
|
38
|
+
*
|
|
39
39
|
* @method ellipseMode
|
|
40
40
|
* @param {(CENTER|RADIUS|CORNER|CORNERS)} mode either CENTER, RADIUS, CORNER, or CORNERS
|
|
41
41
|
* @chainable
|
|
@@ -78,8 +78,15 @@ function attributes(p5, fn){
|
|
|
78
78
|
* describe('A white circle with a gray circle at its top-left corner. Both circles have black outlines.');
|
|
79
79
|
* }
|
|
80
80
|
*/
|
|
81
|
+
/**
|
|
82
|
+
* @method ellipseMode
|
|
83
|
+
* @return {(CENTER|RADIUS|CORNER|CORNERS)} the current ellipseMode.
|
|
84
|
+
*/
|
|
81
85
|
fn.ellipseMode = function(m) {
|
|
82
86
|
// p5._validateParameters('ellipseMode', arguments);
|
|
87
|
+
if (typeof m === 'undefined') { // getter
|
|
88
|
+
return this._renderer?.states.ellipseMode;
|
|
89
|
+
}
|
|
83
90
|
if (
|
|
84
91
|
m === CORNER ||
|
|
85
92
|
m === CORNERS ||
|
|
@@ -101,8 +108,10 @@ function attributes(p5, fn){
|
|
|
101
108
|
* In WebGL mode, `noSmooth()` causes all shapes to be drawn with jagged
|
|
102
109
|
* (aliased) edges. The functions don't affect images or fonts.
|
|
103
110
|
*
|
|
111
|
+
* Note: In WebGPU mode, you must `await` this function.
|
|
112
|
+
*
|
|
104
113
|
* @method noSmooth
|
|
105
|
-
* @
|
|
114
|
+
* @return {void|Promise<void>}
|
|
106
115
|
*
|
|
107
116
|
* @example
|
|
108
117
|
* let heart;
|
|
@@ -156,10 +165,10 @@ function attributes(p5, fn){
|
|
|
156
165
|
if ('imageSmoothingEnabled' in this.drawingContext) {
|
|
157
166
|
this.drawingContext.imageSmoothingEnabled = false;
|
|
158
167
|
}
|
|
168
|
+
return this;
|
|
159
169
|
} else {
|
|
160
|
-
this.setAttributes('antialias', false);
|
|
170
|
+
return this.setAttributes('antialias', false);
|
|
161
171
|
}
|
|
162
|
-
return this;
|
|
163
172
|
};
|
|
164
173
|
|
|
165
174
|
/**
|
|
@@ -187,6 +196,8 @@ function attributes(p5, fn){
|
|
|
187
196
|
* constants `CENTER`, `RADIUS`, `CORNER`, and `CORNERS` are defined this way.
|
|
188
197
|
* JavaScript is a case-sensitive language.
|
|
189
198
|
*
|
|
199
|
+
* Calling `rectMode()` without an argument returns the current rectMode, either `CORNER`, `CORNERS`, `CENTER`, or `RADIUS`.
|
|
200
|
+
*
|
|
190
201
|
* @method rectMode
|
|
191
202
|
* @param {(CENTER|RADIUS|CORNER|CORNERS)} mode either CORNER, CORNERS, CENTER, or RADIUS
|
|
192
203
|
* @chainable
|
|
@@ -255,8 +266,15 @@ function attributes(p5, fn){
|
|
|
255
266
|
* describe('A small gray square drawn at the center of a white square.');
|
|
256
267
|
* }
|
|
257
268
|
*/
|
|
269
|
+
/**
|
|
270
|
+
* @method rectMode
|
|
271
|
+
* @return {(CENTER|RADIUS|CORNER|CORNERS)} the current rectMode.
|
|
272
|
+
*/
|
|
258
273
|
fn.rectMode = function(m) {
|
|
259
274
|
// p5._validateParameters('rectMode', arguments);
|
|
275
|
+
if (typeof m === 'undefined') { // getter
|
|
276
|
+
return this._renderer?.states.rectMode;
|
|
277
|
+
}
|
|
260
278
|
if (
|
|
261
279
|
m === CORNER ||
|
|
262
280
|
m === CORNERS ||
|
|
@@ -381,6 +399,9 @@ function attributes(p5, fn){
|
|
|
381
399
|
*/
|
|
382
400
|
fn.strokeCap = function(cap) {
|
|
383
401
|
// p5._validateParameters('strokeCap', arguments);
|
|
402
|
+
if (typeof cap === 'undefined') { // getter
|
|
403
|
+
return this._renderer.strokeCap();
|
|
404
|
+
}
|
|
384
405
|
if (
|
|
385
406
|
cap === ROUND ||
|
|
386
407
|
cap === SQUARE ||
|
|
@@ -402,6 +423,8 @@ function attributes(p5, fn){
|
|
|
402
423
|
* the constants `MITER`, `BEVEL`, and `ROUND` are defined this way.
|
|
403
424
|
* JavaScript is a case-sensitive language.
|
|
404
425
|
*
|
|
426
|
+
* Calling `strokeJoin()` without an argument returns the current stroke join style, either `MITER`, `BEVEL`, or `ROUND`.
|
|
427
|
+
*
|
|
405
428
|
* @method strokeJoin
|
|
406
429
|
* @param {(MITER|BEVEL|ROUND)} join either MITER, BEVEL, or ROUND
|
|
407
430
|
* @chainable
|
|
@@ -468,8 +491,15 @@ function attributes(p5, fn){
|
|
|
468
491
|
* describe('A right-facing arrowhead shape with a rounded tip in center of canvas.');
|
|
469
492
|
* }
|
|
470
493
|
*/
|
|
494
|
+
/**
|
|
495
|
+
* @method strokeJoin
|
|
496
|
+
* @return {(MITER|BEVEL|ROUND)} the current stroke join style.
|
|
497
|
+
*/
|
|
471
498
|
fn.strokeJoin = function(join) {
|
|
472
499
|
// p5._validateParameters('strokeJoin', arguments);
|
|
500
|
+
if (typeof join === 'undefined') { // getter
|
|
501
|
+
return this._renderer.strokeJoin();
|
|
502
|
+
}
|
|
473
503
|
if (
|
|
474
504
|
join === ROUND ||
|
|
475
505
|
join === BEVEL ||
|
|
@@ -486,6 +516,8 @@ function attributes(p5, fn){
|
|
|
486
516
|
*
|
|
487
517
|
* Note: `strokeWeight()` is affected by transformations, especially calls to
|
|
488
518
|
* <a href="#/p5/scale">scale()</a>.
|
|
519
|
+
*
|
|
520
|
+
* Calling `strokeWeight()` without an argument returns the current stroke weight as a number.
|
|
489
521
|
*
|
|
490
522
|
* @method strokeWeight
|
|
491
523
|
* @param {Number} weight the weight of the stroke (in pixels).
|
|
@@ -528,10 +560,13 @@ function attributes(p5, fn){
|
|
|
528
560
|
* describe('Two horizontal black lines. The top line is thin and the bottom is five times thicker than the top.');
|
|
529
561
|
* }
|
|
530
562
|
*/
|
|
563
|
+
/**
|
|
564
|
+
* @method strokeWeight
|
|
565
|
+
* @return {Number} the current stroke weight.
|
|
566
|
+
*/
|
|
531
567
|
fn.strokeWeight = function(w) {
|
|
532
568
|
// p5._validateParameters('strokeWeight', arguments);
|
|
533
|
-
this._renderer.strokeWeight(w);
|
|
534
|
-
return this;
|
|
569
|
+
return this._renderer.strokeWeight(w);
|
|
535
570
|
};
|
|
536
571
|
}
|
|
537
572
|
|
package/dist/shape/curves.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as Color } from '../creating_reading-
|
|
1
|
+
import { C as Color } from '../creating_reading-DLkHH80h.js';
|
|
2
2
|
import { Vector } from '../math/p5.Vector.js';
|
|
3
|
-
import {
|
|
3
|
+
import { I as INCLUDE, z as PATH, G as EMPTY_PATH, O as OPEN, J as CLOSE, K as POINTS, Q as LINES, c as TRIANGLES, V as QUADS, X as TRIANGLE_FAN, T as TRIANGLE_STRIP, Y as QUAD_STRIP, Z as EXCLUDE, _ as JOIN, $ as CHORD, a0 as PIE } from '../constants-0wkVUfqa.js';
|
|
4
4
|
import 'colorjs.io/fn';
|
|
5
5
|
import '../color/color_spaces/hsb.js';
|
|
6
6
|
|
|
@@ -8,8 +8,6 @@ import '../color/color_spaces/hsb.js';
|
|
|
8
8
|
* @module Shape
|
|
9
9
|
* @submodule Custom Shapes
|
|
10
10
|
* @for p5
|
|
11
|
-
* @requires core
|
|
12
|
-
* @requires constants
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
|
|
@@ -468,6 +466,85 @@ class Quad extends ShapePrimitive {
|
|
|
468
466
|
}
|
|
469
467
|
}
|
|
470
468
|
|
|
469
|
+
/*
|
|
470
|
+
* TODO: Future enhancement — align with arcVertex proposal (#6459)
|
|
471
|
+
* Currently stores start/stop angles and mode (OPEN/CHORD/PIE).
|
|
472
|
+
* For full SVG compatibility and arcs inside beginShape/endShape,
|
|
473
|
+
* we may want to add an arc-to-vertex variant that matches the
|
|
474
|
+
* arcVertex() API discussed in #6459.
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
class ArcPrimitive extends ShapePrimitive {
|
|
478
|
+
#x;
|
|
479
|
+
#y;
|
|
480
|
+
#w;
|
|
481
|
+
#h;
|
|
482
|
+
#start;
|
|
483
|
+
#stop;
|
|
484
|
+
#mode;
|
|
485
|
+
#vertexCapacity = 2;
|
|
486
|
+
|
|
487
|
+
constructor(startVertex, endVertex, x, y, w, h, start, stop, mode) {
|
|
488
|
+
// ShapePrimitive requires at least one vertex; pass a placeholder
|
|
489
|
+
super(startVertex, endVertex);
|
|
490
|
+
this.#x = x;
|
|
491
|
+
this.#y = y;
|
|
492
|
+
this.#w = w;
|
|
493
|
+
this.#h = h;
|
|
494
|
+
this.#start = start;
|
|
495
|
+
this.#stop = stop;
|
|
496
|
+
this.#mode = mode;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
get x() { return this.#x; }
|
|
500
|
+
get y() { return this.#y; }
|
|
501
|
+
get w() { return this.#w; }
|
|
502
|
+
get h() { return this.#h; }
|
|
503
|
+
get start() { return this.#start; }
|
|
504
|
+
get stop() { return this.#stop; }
|
|
505
|
+
get mode() { return this.#mode; }
|
|
506
|
+
get startVertex() { return this.vertices[0]; }
|
|
507
|
+
get endVertex() { return this.vertices[1]; }
|
|
508
|
+
|
|
509
|
+
get vertexCapacity() {
|
|
510
|
+
return this.#vertexCapacity;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
accept(visitor) {
|
|
514
|
+
visitor.visitArcPrimitive(this);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
class EllipsePrimitive extends ShapePrimitive {
|
|
519
|
+
#x;
|
|
520
|
+
#y;
|
|
521
|
+
#w;
|
|
522
|
+
#h;
|
|
523
|
+
#vertexCapacity = 1;
|
|
524
|
+
|
|
525
|
+
constructor(centerVertex, x, y, w, h) {
|
|
526
|
+
|
|
527
|
+
super(centerVertex);
|
|
528
|
+
this.#x = x;
|
|
529
|
+
this.#y = y;
|
|
530
|
+
this.#w = w;
|
|
531
|
+
this.#h = h;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
get x() { return this.#x; }
|
|
535
|
+
get y() { return this.#y; }
|
|
536
|
+
get w() { return this.#w; }
|
|
537
|
+
get h() { return this.#h; }
|
|
538
|
+
|
|
539
|
+
get vertexCapacity() {
|
|
540
|
+
return this.#vertexCapacity;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
accept(visitor) {
|
|
544
|
+
visitor.visitEllipsePrimitive(this);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
471
548
|
// ---- TESSELLATION PRIMITIVES ----
|
|
472
549
|
|
|
473
550
|
class TriangleFan extends ShapePrimitive {
|
|
@@ -907,6 +984,49 @@ class Shape {
|
|
|
907
984
|
this.#generalVertex('arcVertex', position, textureCoordinates);
|
|
908
985
|
}
|
|
909
986
|
|
|
987
|
+
|
|
988
|
+
arcPrimitive(x,y,w,h,start,stop,mode){
|
|
989
|
+
this.beginShape();
|
|
990
|
+
const centerX = x+w/2;
|
|
991
|
+
const centerY = y+h/2;
|
|
992
|
+
const radiusX = w / 2;
|
|
993
|
+
const radiusY = h / 2;
|
|
994
|
+
|
|
995
|
+
const startVertex = this.#createVertex(
|
|
996
|
+
new Vector(
|
|
997
|
+
centerX + radiusX * Math.cos(start),
|
|
998
|
+
centerY + radiusY * Math.sin(start)
|
|
999
|
+
)
|
|
1000
|
+
);
|
|
1001
|
+
|
|
1002
|
+
const endVertex = this.#createVertex(
|
|
1003
|
+
new Vector(
|
|
1004
|
+
centerX + radiusX * Math.cos(stop),
|
|
1005
|
+
centerY + radiusY * Math.sin(stop)
|
|
1006
|
+
)
|
|
1007
|
+
);
|
|
1008
|
+
|
|
1009
|
+
const primitive = new ArcPrimitive(
|
|
1010
|
+
startVertex,
|
|
1011
|
+
endVertex,
|
|
1012
|
+
x, y, w, h,
|
|
1013
|
+
start,
|
|
1014
|
+
stop,
|
|
1015
|
+
mode
|
|
1016
|
+
);
|
|
1017
|
+
primitive.addToShape(this);
|
|
1018
|
+
this.endShape();
|
|
1019
|
+
return this;
|
|
1020
|
+
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
ellipsePrimitive(x,y,w,h){
|
|
1024
|
+
const centerVertex = this.#createVertex(new Vector(x+w/2,y+h/2));
|
|
1025
|
+
|
|
1026
|
+
const primitive = new EllipsePrimitive(centerVertex, x, y, w, h);
|
|
1027
|
+
return primitive.addToShape(this);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
910
1030
|
beginContour(shapeKind = PATH) {
|
|
911
1031
|
if (this.at(-1)?.kind === EMPTY_PATH) {
|
|
912
1032
|
this.contours.pop();
|
|
@@ -1005,6 +1125,12 @@ class PrimitiveVisitor {
|
|
|
1005
1125
|
visitArcSegment(arcSegment) {
|
|
1006
1126
|
throw new Error('Method visitArcSegment() has not been implemented.');
|
|
1007
1127
|
}
|
|
1128
|
+
visitArcPrimitive(arc) {
|
|
1129
|
+
throw new Error('Method visitArcPrimitive() has not been implemented.');
|
|
1130
|
+
}
|
|
1131
|
+
visitEllipsePrimitive(ellipse) {
|
|
1132
|
+
throw new Error('Method visitEllipsePrimitive() has not been implemented.');
|
|
1133
|
+
}
|
|
1008
1134
|
|
|
1009
1135
|
// isolated primitives
|
|
1010
1136
|
visitPoint(point) {
|
|
@@ -1035,6 +1161,8 @@ class PrimitiveVisitor {
|
|
|
1035
1161
|
// requires testing
|
|
1036
1162
|
class PrimitiveToPath2DConverter extends PrimitiveVisitor {
|
|
1037
1163
|
path = new Path2D();
|
|
1164
|
+
strokePath = null;
|
|
1165
|
+
fillPath = null;
|
|
1038
1166
|
strokeWeight;
|
|
1039
1167
|
|
|
1040
1168
|
constructor({ strokeWeight }) {
|
|
@@ -1153,6 +1281,59 @@ class PrimitiveToPath2DConverter extends PrimitiveVisitor {
|
|
|
1153
1281
|
this.path.closePath();
|
|
1154
1282
|
}
|
|
1155
1283
|
}
|
|
1284
|
+
visitArcPrimitive(arc) {
|
|
1285
|
+
const centerX = arc.x + arc.w / 2;
|
|
1286
|
+
const centerY = arc.y + arc.h / 2;
|
|
1287
|
+
const radiusX = arc.w / 2;
|
|
1288
|
+
const radiusY = arc.h / 2;
|
|
1289
|
+
const startX = centerX + radiusX * Math.cos(arc.start);
|
|
1290
|
+
const startY = centerY + radiusY * Math.sin(arc.start);
|
|
1291
|
+
|
|
1292
|
+
const delta = arc.stop - arc.start;
|
|
1293
|
+
const isFullCircle = Math.abs(delta % (2 * Math.PI)) < 0.00001 &&
|
|
1294
|
+
Math.abs(delta) > 0.00001;
|
|
1295
|
+
|
|
1296
|
+
const createPieSlice = ! (
|
|
1297
|
+
arc.mode === CHORD ||
|
|
1298
|
+
arc.mode === OPEN ||
|
|
1299
|
+
isFullCircle
|
|
1300
|
+
);
|
|
1301
|
+
|
|
1302
|
+
if (!this.fillPath) this.fillPath = new Path2D(this.path);
|
|
1303
|
+
if (!this.strokePath) this.strokePath = new Path2D(this.path);
|
|
1304
|
+
|
|
1305
|
+
this.fillPath.moveTo(startX, startY);
|
|
1306
|
+
this.fillPath.ellipse(centerX, centerY, radiusX, radiusY,
|
|
1307
|
+
0, arc.start, arc.stop);
|
|
1308
|
+
if (createPieSlice) {
|
|
1309
|
+
this.fillPath.lineTo(centerX, centerY);
|
|
1310
|
+
}
|
|
1311
|
+
this.fillPath.closePath();
|
|
1312
|
+
|
|
1313
|
+
this.strokePath.moveTo(startX, startY);
|
|
1314
|
+
this.strokePath.ellipse(centerX, centerY, radiusX, radiusY,
|
|
1315
|
+
0, arc.start, arc.stop);
|
|
1316
|
+
if (arc.mode === PIE && createPieSlice) {
|
|
1317
|
+
this.strokePath.lineTo(centerX, centerY);
|
|
1318
|
+
}
|
|
1319
|
+
if (arc.mode === PIE || arc.mode === CHORD) {
|
|
1320
|
+
this.strokePath.closePath();
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
// Still maintain base path just in case
|
|
1324
|
+
this.path.moveTo(startX, startY);
|
|
1325
|
+
this.path.ellipse(centerX, centerY, radiusX, radiusY,
|
|
1326
|
+
0, arc.start, arc.stop);
|
|
1327
|
+
}
|
|
1328
|
+
visitEllipsePrimitive(ellipse) {
|
|
1329
|
+
const centerX = ellipse.x + ellipse.w / 2;
|
|
1330
|
+
const centerY = ellipse.y + ellipse.h / 2;
|
|
1331
|
+
const radiusX = ellipse.w / 2;
|
|
1332
|
+
const radiusY = ellipse.h / 2;
|
|
1333
|
+
|
|
1334
|
+
this.path.moveTo(centerX + radiusX, centerY);
|
|
1335
|
+
this.path.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);
|
|
1336
|
+
}
|
|
1156
1337
|
visitQuadStrip(quadStrip) {
|
|
1157
1338
|
for (let i = 0; i < quadStrip.vertices.length - 3; i += 2) {
|
|
1158
1339
|
const v0 = quadStrip.vertices[i];
|
|
@@ -1279,6 +1460,78 @@ class PrimitiveToVerticesConverter extends PrimitiveVisitor {
|
|
|
1279
1460
|
// WebGL itself interprets the vertices as a strip, no reformatting needed
|
|
1280
1461
|
this.contours.push(quadStrip.vertices.slice());
|
|
1281
1462
|
}
|
|
1463
|
+
visitArcPrimitive(arc) {
|
|
1464
|
+
const startVertex = arc.startVertex;
|
|
1465
|
+
const endVertex = arc.endVertex;
|
|
1466
|
+
const centerX = arc.x + arc.w / 2;
|
|
1467
|
+
const centerY = arc.y + arc.h / 2;
|
|
1468
|
+
const radiusX = arc.w / 2;
|
|
1469
|
+
const radiusY = arc.h / 2;
|
|
1470
|
+
const avgRadius = (radiusX + radiusY) / 2;
|
|
1471
|
+
|
|
1472
|
+
const arcLength = avgRadius * Math.abs(arc.stop - arc.start);
|
|
1473
|
+
|
|
1474
|
+
const numPoints = Math.max(3, Math.ceil(this.curveDetail * arcLength));
|
|
1475
|
+
const verts = [];
|
|
1476
|
+
const interpolateVertexProps = (v1, v2, t) => {
|
|
1477
|
+
const props = {};
|
|
1478
|
+
for (const [key, value] of Object.entries(v1)) {
|
|
1479
|
+
if (key === 'position') continue;
|
|
1480
|
+
if (typeof value === 'number' && typeof v2[key] === 'number') {
|
|
1481
|
+
props[key] = value * (1 - t) + v2[key] * t;
|
|
1482
|
+
} else {
|
|
1483
|
+
props[key] = value;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return props;
|
|
1487
|
+
};
|
|
1488
|
+
if (arc.mode === PIE) {
|
|
1489
|
+
const centerProps = interpolateVertexProps(startVertex, endVertex, 0.5);
|
|
1490
|
+
centerProps.position = new Vector(centerX, centerY);
|
|
1491
|
+
verts.push(new Vertex(centerProps));
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
for (let i = 0; i <= numPoints; i++) {
|
|
1495
|
+
const t = i / numPoints;
|
|
1496
|
+
const angle = arc.start + (arc.stop - arc.start) * t;
|
|
1497
|
+
const vertexProps = interpolateVertexProps(startVertex, endVertex, t);
|
|
1498
|
+
|
|
1499
|
+
vertexProps.position = new Vector(
|
|
1500
|
+
centerX + radiusX * Math.cos(angle),
|
|
1501
|
+
centerY + radiusY * Math.sin(angle)
|
|
1502
|
+
);
|
|
1503
|
+
|
|
1504
|
+
verts.push(new Vertex(vertexProps));
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
this.contours.push(verts);
|
|
1508
|
+
}
|
|
1509
|
+
visitEllipsePrimitive(ellipse) {
|
|
1510
|
+
const centerX = ellipse.x + ellipse.w / 2;
|
|
1511
|
+
const centerY = ellipse.y + ellipse.h / 2;
|
|
1512
|
+
const radiusX = ellipse.w / 2;
|
|
1513
|
+
const radiusY = ellipse.h / 2;
|
|
1514
|
+
const avgRadius = (radiusX + radiusY) / 2;
|
|
1515
|
+
const perimeter = 2 * Math.PI * avgRadius;
|
|
1516
|
+
const numPoints = Math.max(3, Math.ceil(this.curveDetail * perimeter));
|
|
1517
|
+
const verts = [];
|
|
1518
|
+
const centerVertex = ellipse.vertices[0];
|
|
1519
|
+
for (let i = 0; i <= numPoints; i++) {
|
|
1520
|
+
const angle = (2 * Math.PI * i) / numPoints;
|
|
1521
|
+
const vertexProps = {};
|
|
1522
|
+
for (const [key, value] of Object.entries(centerVertex)) {
|
|
1523
|
+
if (key === 'position') continue;
|
|
1524
|
+
vertexProps[key] = value;
|
|
1525
|
+
}
|
|
1526
|
+
vertexProps.position = new Vector(
|
|
1527
|
+
centerX + radiusX * Math.cos(angle),
|
|
1528
|
+
centerY + radiusY * Math.sin(angle)
|
|
1529
|
+
);
|
|
1530
|
+
verts.push(new Vertex(vertexProps));
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
this.contours.push(verts);
|
|
1534
|
+
}
|
|
1282
1535
|
}
|
|
1283
1536
|
|
|
1284
1537
|
class PointAtLengthGetter extends PrimitiveVisitor {
|
|
@@ -1613,6 +1866,8 @@ function customShapes(p5, fn) {
|
|
|
1613
1866
|
* Note: `bezierVertex()` won’t work when an argument is passed to
|
|
1614
1867
|
* <a href="#/p5/beginShape">beginShape()</a>.
|
|
1615
1868
|
*
|
|
1869
|
+
* Calling `bezierOrder()` without an argument returns the current Bézier order.
|
|
1870
|
+
*
|
|
1616
1871
|
* @method bezierOrder
|
|
1617
1872
|
* @param {Number} order The new order to set. Can be either 2 or 3, by default 3
|
|
1618
1873
|
*
|
|
@@ -2784,4 +3039,4 @@ if (typeof p5 !== 'undefined') {
|
|
|
2784
3039
|
customShapes(p5, p5.prototype);
|
|
2785
3040
|
}
|
|
2786
3041
|
|
|
2787
|
-
export { Anchor, BezierSegment, Contour, Line, LineSegment, Point, PointAtLengthGetter, PrimitiveToPath2DConverter, PrimitiveToVerticesConverter, PrimitiveVisitor, Quad, QuadStrip, Segment, Shape, ShapePrimitive, SplineSegment, Triangle, TriangleFan, TriangleStrip, Vertex, customShapes as default };
|
|
3042
|
+
export { Anchor, ArcPrimitive, BezierSegment, Contour, EllipsePrimitive, Line, LineSegment, Point, PointAtLengthGetter, PrimitiveToPath2DConverter, PrimitiveToVerticesConverter, PrimitiveVisitor, Quad, QuadStrip, Segment, Shape, ShapePrimitive, SplineSegment, Triangle, TriangleFan, TriangleStrip, Vertex, customShapes as default };
|
package/dist/shape/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import attributes from './attributes.js';
|
|
|
3
3
|
import curves from './curves.js';
|
|
4
4
|
import vertex from './vertex.js';
|
|
5
5
|
import customShapes from './custom_shapes.js';
|
|
6
|
-
import '../constants-
|
|
6
|
+
import '../constants-0wkVUfqa.js';
|
|
7
7
|
import '../core/helpers.js';
|
|
8
|
-
import '../creating_reading-
|
|
8
|
+
import '../creating_reading-DLkHH80h.js';
|
|
9
9
|
import 'colorjs.io/fn';
|
|
10
10
|
import '../color/color_spaces/hsb.js';
|
|
11
11
|
import '../math/p5.Vector.js';
|
package/dist/shape/vertex.js
CHANGED
|
@@ -2,5 +2,5 @@ import './ir_dag.js';
|
|
|
2
2
|
import './ir_cfg.js';
|
|
3
3
|
import './strands_FES.js';
|
|
4
4
|
import './ir_types.js';
|
|
5
|
-
export { b as binaryOpNode, h as castToFloat, g as constructTypeFromIDs, f as functionCallNode, m as memberAccessNode, p as primitiveConstructorNode,
|
|
5
|
+
export { k as arrayAccessNode, n as arrayAssignmentNode, b as binaryOpNode, h as castToFloat, g as constructTypeFromIDs, l as createStructArrayElementProxy, f as functionCallNode, m as memberAccessNode, p as primitiveConstructorNode, s as scalarLiteralNode, a as statementNode, e as structConstructorNode, d as structInstanceNode, i as swizzleNode, j as swizzleTrap, u as unaryOpNode, v as variableNode } from '../ir_builders-C2ebb6Lu.js';
|
|
6
6
|
import './strands_builtins.js';
|
package/dist/strands/ir_types.js
CHANGED
|
@@ -11,6 +11,7 @@ const NodeType = {
|
|
|
11
11
|
STATEMENT: 'statement',
|
|
12
12
|
ASSIGNMENT: 'assignment',
|
|
13
13
|
};
|
|
14
|
+
const INSTANCE_ID_VARYING_NAME = '_p5_instanceID';
|
|
14
15
|
const NodeTypeToName = Object.fromEntries(
|
|
15
16
|
Object.entries(NodeType).map(([key, val]) => [val, key])
|
|
16
17
|
);
|
|
@@ -120,6 +121,7 @@ const OpCode = {
|
|
|
120
121
|
LOGICAL_AND: 11,
|
|
121
122
|
LOGICAL_OR: 12,
|
|
122
123
|
MEMBER_ACCESS: 13,
|
|
124
|
+
ARRAY_ACCESS: 14,
|
|
123
125
|
},
|
|
124
126
|
Unary: {
|
|
125
127
|
LOGICAL_NOT: 100,
|
|
@@ -130,6 +132,8 @@ const OpCode = {
|
|
|
130
132
|
Nary: {
|
|
131
133
|
FUNCTION_CALL: 200,
|
|
132
134
|
CONSTRUCTOR: 201,
|
|
135
|
+
TERNARY: 202,
|
|
136
|
+
ARRAY_ASSIGNMENT: 203,
|
|
133
137
|
},
|
|
134
138
|
ControlFlow: {
|
|
135
139
|
RETURN: 300,
|
|
@@ -207,4 +211,4 @@ const BlockTypeToName = Object.fromEntries(
|
|
|
207
211
|
Object.entries(BlockType).map(([key, val]) => [val, key])
|
|
208
212
|
);
|
|
209
213
|
|
|
210
|
-
export { BasePriority, BaseType, BinarySymbolToName, BlockType, BlockTypeToName, ConstantFolding, DataType, GenType, NodeType, NodeTypeRequiredFields, NodeTypeToName, OpCode, OpCodeToSymbol, OperatorTable, StatementType, TypeInfoFromGLSLName, UnarySymbolToName, booleanOpCode, isStructType, structType, typeEquals };
|
|
214
|
+
export { BasePriority, BaseType, BinarySymbolToName, BlockType, BlockTypeToName, ConstantFolding, DataType, GenType, INSTANCE_ID_VARYING_NAME, NodeType, NodeTypeRequiredFields, NodeTypeToName, OpCode, OpCodeToSymbol, OperatorTable, StatementType, TypeInfoFromGLSLName, UnarySymbolToName, booleanOpCode, isStructType, structType, typeEquals };
|