p5 2.3.0-rc.5 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -11
- package/dist/accessibility/color_namer.js +4 -4
- package/dist/accessibility/index.js +4 -4
- package/dist/app.js +4 -4
- package/dist/app.node.js +4 -4
- package/dist/color/color_conversion.js +4 -4
- package/dist/color/index.js +1 -1
- package/dist/color/setting.js +1 -1
- package/dist/{constants-CdA3y5zC.js → constants-Dv6ZqA6s.js} +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +1 -1
- 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 +4 -4
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +4 -4
- package/dist/core/main.js +4 -4
- package/dist/core/p5.Graphics.js +3 -3
- package/dist/core/p5.Renderer.js +2 -2
- package/dist/core/p5.Renderer2D.js +4 -4
- package/dist/core/p5.Renderer3D.js +3 -3
- package/dist/core/rendering.js +3 -3
- package/dist/dom/dom.js +1 -1
- package/dist/dom/index.js +1 -1
- package/dist/dom/p5.Element.js +1 -1
- package/dist/dom/p5.MediaElement.js +1 -1
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +3 -3
- package/dist/image/image.js +3 -3
- package/dist/image/index.js +3 -3
- package/dist/image/loading_displaying.js +3 -3
- package/dist/image/p5.Image.js +2 -2
- package/dist/io/files.js +3 -3
- package/dist/io/index.js +3 -3
- package/dist/{main-BNYJV9Kd.js → main-BR2ALC_6.js} +3 -3
- package/dist/math/Matrices/Matrix.js +1 -1
- package/dist/math/Matrices/MatrixNumjs.js +1 -1
- package/dist/math/index.js +1 -1
- package/dist/math/p5.Matrix.js +1 -1
- package/dist/math/p5.Vector.js +76 -51
- package/dist/math/patch-vector.js +20 -8
- package/dist/math/trigonometry.js +1 -1
- package/dist/{p5.Renderer-BfhR0QHl.js → p5.Renderer-XOvhEbJn.js} +1 -1
- package/dist/{rendering-mbOOQwHM.js → rendering-C5lX6zKm.js} +2 -2
- package/dist/shape/2d_primitives.js +1 -1
- package/dist/shape/attributes.js +1 -1
- package/dist/shape/custom_shapes.js +1 -1
- package/dist/shape/index.js +1 -1
- package/dist/type/index.js +2 -2
- package/dist/type/p5.Font.js +2 -2
- package/dist/type/textCore.js +2 -2
- package/dist/webgl/3d_primitives.js +3 -3
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +1 -1
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +3 -3
- package/dist/webgl/interaction.js +1 -1
- package/dist/webgl/light.js +3 -3
- package/dist/webgl/loading.js +3 -3
- package/dist/webgl/material.js +3 -3
- package/dist/webgl/p5.Camera.js +3 -3
- package/dist/webgl/p5.Framebuffer.js +3 -3
- package/dist/webgl/p5.Geometry.js +1 -1
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +3 -3
- package/dist/webgl/p5.Texture.js +3 -3
- package/dist/webgl/text.js +3 -3
- package/dist/webgl/utils.js +3 -3
- package/dist/webgpu/index.js +1 -1
- package/dist/webgpu/p5.RendererWebGPU.js +1 -1
- package/lib/p5.esm.js +96 -59
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +96 -59
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +1 -1
- package/lib/p5.webgpu.js +1 -1
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +1 -1
- package/types/global.d.ts +14 -14
- package/types/p5.d.ts +24 -31
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ad as WEBGL, ab as WEBGL2, L as LIGHTEST, D as DARKEST, S as SUBTRACT, R as REPLACE, E as EXCLUSION, a as SCREEN, M as MULTIPLY, b as REMOVE, A as ADD, B as BLEND, c as TRIANGLES, n as CORNER, U as UNSIGNED_BYTE, g as LINEAR, aG as LINEAR_MIPMAP, a7 as TEXTURE, F as FLOAT, d as UNSIGNED_INT, H as HALF_FLOAT } from '../constants-
|
|
2
|
-
import { R as Renderer3D, o as readPixelWebGL, q as readPixelsWebGL, M as MipmapTexture, h as getWebGLShaderAttributes, g as getWebGLUniformMetadata, s as setWebGLUniformValue, e as setWebGLTextureParams, j as populateGLSLHooks, u as checkWebGLCapabilities } from '../rendering-
|
|
1
|
+
import { ad as WEBGL, ab as WEBGL2, L as LIGHTEST, D as DARKEST, S as SUBTRACT, R as REPLACE, E as EXCLUSION, a as SCREEN, M as MULTIPLY, b as REMOVE, A as ADD, B as BLEND, c as TRIANGLES, n as CORNER, U as UNSIGNED_BYTE, g as LINEAR, aG as LINEAR_MIPMAP, a7 as TEXTURE, F as FLOAT, d as UNSIGNED_INT, H as HALF_FLOAT } from '../constants-Dv6ZqA6s.js';
|
|
2
|
+
import { R as Renderer3D, o as readPixelWebGL, q as readPixelsWebGL, M as MipmapTexture, h as getWebGLShaderAttributes, g as getWebGLUniformMetadata, s as setWebGLUniformValue, e as setWebGLTextureParams, j as populateGLSLHooks, u as checkWebGLCapabilities } from '../rendering-C5lX6zKm.js';
|
|
3
3
|
import { getStrokeDefs } from './enums.js';
|
|
4
4
|
import { Shader } from './p5.Shader.js';
|
|
5
5
|
import { R as RGB, h as RGBA } from '../creating_reading-DLkHH80h.js';
|
|
6
|
-
import { I as Image } from '../p5.Renderer-
|
|
6
|
+
import { I as Image } from '../p5.Renderer-XOvhEbJn.js';
|
|
7
7
|
import { g as glslBackend } from '../strands_glslBackend-D6G3UyCs.js';
|
|
8
8
|
import '../strands/ir_types.js';
|
|
9
9
|
import { getShaderHookTypes } from './shaderHookUtils.js';
|
package/dist/webgl/p5.Texture.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '../constants-
|
|
1
|
+
import '../constants-Dv6ZqA6s.js';
|
|
2
2
|
import '../dom/p5.Element.js';
|
|
3
|
-
import '../p5.Renderer-
|
|
3
|
+
import '../p5.Renderer-XOvhEbJn.js';
|
|
4
4
|
import '../dom/p5.MediaElement.js';
|
|
5
|
-
export { M as MipmapTexture, T as Texture, t as default } from '../rendering-
|
|
5
|
+
export { M as MipmapTexture, T as Texture, t as default } from '../rendering-C5lX6zKm.js';
|
|
6
6
|
import '../dom/p5.File.js';
|
|
7
7
|
import '../io/p5.XML.js';
|
|
8
8
|
import '../creating_reading-DLkHH80h.js';
|
package/dist/webgl/text.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a7 as TEXTURE, c as TRIANGLES } from '../constants-
|
|
2
|
-
import { R as Renderer3D } from '../rendering-
|
|
1
|
+
import { a7 as TEXTURE, c as TRIANGLES } from '../constants-Dv6ZqA6s.js';
|
|
2
|
+
import { R as Renderer3D } from '../rendering-C5lX6zKm.js';
|
|
3
3
|
import { Vector } from '../math/p5.Vector.js';
|
|
4
4
|
import { Geometry } from './p5.Geometry.js';
|
|
5
5
|
import { Font, arrayCommandsToObjects } from '../type/p5.Font.js';
|
|
@@ -10,7 +10,7 @@ import '../strands/ir_types.js';
|
|
|
10
10
|
import '../dom/p5.Element.js';
|
|
11
11
|
import '../dom/p5.File.js';
|
|
12
12
|
import '../io/p5.XML.js';
|
|
13
|
-
import '../p5.Renderer-
|
|
13
|
+
import '../p5.Renderer-XOvhEbJn.js';
|
|
14
14
|
import '../image/filters.js';
|
|
15
15
|
import '../shape/custom_shapes.js';
|
|
16
16
|
import '../core/States.js';
|
package/dist/webgl/utils.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import '../constants-
|
|
1
|
+
import '../constants-Dv6ZqA6s.js';
|
|
2
2
|
import '../strands/ir_types.js';
|
|
3
|
-
export { u as checkWebGLCapabilities, h as getWebGLShaderAttributes, g as getWebGLUniformMetadata, j as populateGLSLHooks, o as readPixelWebGL, q as readPixelsWebGL, e as setWebGLTextureParams, s as setWebGLUniformValue } from '../rendering-
|
|
3
|
+
export { u as checkWebGLCapabilities, h as getWebGLShaderAttributes, g as getWebGLUniformMetadata, j as populateGLSLHooks, o as readPixelWebGL, q as readPixelsWebGL, e as setWebGLTextureParams, s as setWebGLUniformValue } from '../rendering-C5lX6zKm.js';
|
|
4
4
|
import '../creating_reading-DLkHH80h.js';
|
|
5
5
|
import 'colorjs.io/fn';
|
|
6
6
|
import '../color/color_spaces/hsb.js';
|
|
7
7
|
import '../dom/p5.Element.js';
|
|
8
8
|
import '../dom/p5.File.js';
|
|
9
9
|
import '../io/p5.XML.js';
|
|
10
|
-
import '../p5.Renderer-
|
|
10
|
+
import '../p5.Renderer-XOvhEbJn.js';
|
|
11
11
|
import '../image/filters.js';
|
|
12
12
|
import '../math/p5.Vector.js';
|
|
13
13
|
import '../shape/custom_shapes.js';
|
package/dist/webgpu/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as WEBGPU, T as TRIANGLE_STRIP, L as LIGHTEST, D as DARKEST, S as SUBTRACT, R as REPLACE, E as EXCLUSION, a as SCREEN, M as MULTIPLY, b as REMOVE, A as ADD, B as BLEND, c as TRIANGLES, U as UNSIGNED_BYTE, F as FLOAT, H as HALF_FLOAT, d as UNSIGNED_INT, e as MIRROR, f as REPEAT, C as CLAMP, g as LINEAR, N as NEAREST } from '../constants-
|
|
1
|
+
import { W as WEBGPU, T as TRIANGLE_STRIP, L as LIGHTEST, D as DARKEST, S as SUBTRACT, R as REPLACE, E as EXCLUSION, a as SCREEN, M as MULTIPLY, b as REMOVE, A as ADD, B as BLEND, c as TRIANGLES, U as UNSIGNED_BYTE, F as FLOAT, H as HALF_FLOAT, d as UNSIGNED_INT, e as MIRROR, f as REPEAT, C as CLAMP, g as LINEAR, N as NEAREST } from '../constants-Dv6ZqA6s.js';
|
|
2
2
|
import { getStrokeDefs } from '../webgl/enums.js';
|
|
3
3
|
import { DataType } from '../strands/ir_types.js';
|
|
4
4
|
import { colorVertexShader, colorFragmentShader } from './shaders/color.js';
|
package/lib/p5.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! p5.js v2.3.0
|
|
1
|
+
/*! p5.js v2.3.0 May 28, 2026 */
|
|
2
2
|
/**
|
|
3
3
|
* @module Constants
|
|
4
4
|
* @submodule Constants
|
|
@@ -12,7 +12,7 @@ const _PI = Math.PI;
|
|
|
12
12
|
* @property {String} VERSION
|
|
13
13
|
* @final
|
|
14
14
|
*/
|
|
15
|
-
const VERSION = '2.3.0
|
|
15
|
+
const VERSION = '2.3.0';
|
|
16
16
|
|
|
17
17
|
// GRAPHICS RENDERER
|
|
18
18
|
/**
|
|
@@ -19791,8 +19791,14 @@ if(typeof p5 !== 'undefined'){
|
|
|
19791
19791
|
* This function is used by binary vector operations to prioritize shorter vectors,
|
|
19792
19792
|
* and to emit a warning when lengths do not match.
|
|
19793
19793
|
*/
|
|
19794
|
-
const prioritizeSmallerDimension = function(currentVectorDimension, args) {
|
|
19795
|
-
|
|
19794
|
+
const prioritizeSmallerDimension = function (currentVectorDimension, args) {
|
|
19795
|
+
const resultDimension = Math.min(currentVectorDimension, args.length);
|
|
19796
|
+
if (Array.isArray(args) && currentVectorDimension !== args.length) {
|
|
19797
|
+
console.warn(
|
|
19798
|
+
'When working with two vectors of different sizes, the smaller dimension is used. In this operation, both vector will be treated as ' + resultDimension + 'D vectors, and any additional values of the linger vector will be ignored.'
|
|
19799
|
+
);
|
|
19800
|
+
}
|
|
19801
|
+
return resultDimension;
|
|
19796
19802
|
};
|
|
19797
19803
|
|
|
19798
19804
|
/**
|
|
@@ -20086,17 +20092,12 @@ class Vector {
|
|
|
20086
20092
|
}
|
|
20087
20093
|
|
|
20088
20094
|
/**
|
|
20089
|
-
* Sets the vector
|
|
20095
|
+
* Sets the the vector to a new value.
|
|
20090
20096
|
*
|
|
20091
20097
|
* `set()` can use separate numbers, as in `v.set(1, 2, 3)`, a
|
|
20092
20098
|
* <a href="#/p5.Vector">p5.Vector</a> object, as in `v.set(v2)`, or an
|
|
20093
20099
|
* array of numbers, as in `v.set([1, 2, 3])`.
|
|
20094
20100
|
*
|
|
20095
|
-
* If a value isn't provided for a component, it will be set to 0. For
|
|
20096
|
-
* example, `v.set(4, 5)` sets `v.x` to 4, `v.y` to 5, and `v.z` to 0.
|
|
20097
|
-
* Calling `set()` with no arguments, as in `v.set()`, sets all the vector's
|
|
20098
|
-
* components to 0.
|
|
20099
|
-
*
|
|
20100
20101
|
* @param {Number} [x] x component of the vector.
|
|
20101
20102
|
* @param {Number} [y] y component of the vector.
|
|
20102
20103
|
* @param {Number} [z] z component of the vector.
|
|
@@ -20181,8 +20182,6 @@ class Vector {
|
|
|
20181
20182
|
}
|
|
20182
20183
|
}
|
|
20183
20184
|
|
|
20184
|
-
|
|
20185
|
-
|
|
20186
20185
|
/**
|
|
20187
20186
|
* Adds to a vector's components.
|
|
20188
20187
|
*
|
|
@@ -20190,11 +20189,10 @@ class Vector {
|
|
|
20190
20189
|
* another <a href="#/p5.Vector">p5.Vector</a> object, as in `v.add(v2)`, or
|
|
20191
20190
|
* an array of numbers, as in `v.add([1, 2, 3])`.
|
|
20192
20191
|
*
|
|
20193
|
-
*
|
|
20194
|
-
*
|
|
20195
|
-
*
|
|
20196
|
-
*
|
|
20197
|
-
* For example, adding `[1, 2, 3]` and `[4, 5]` will result in `[5, 7]`.
|
|
20192
|
+
* You should add vectors only when they are the same size. When two vectors
|
|
20193
|
+
* of different sizes are added, the smaller dimension will be used, any
|
|
20194
|
+
* additional values of the longer vector will be ignored. For example,
|
|
20195
|
+
* adding `[1, 2, 3]` and `[4, 5]` will result in `[5, 7]`.
|
|
20198
20196
|
*
|
|
20199
20197
|
* Calling `add()` with no arguments, as in `v.add()`, has no effect.
|
|
20200
20198
|
*
|
|
@@ -20311,7 +20309,7 @@ class Vector {
|
|
|
20311
20309
|
* @param {p5.Vector|Number[]} value The vector to add
|
|
20312
20310
|
* @chainable
|
|
20313
20311
|
*/
|
|
20314
|
-
add(
|
|
20312
|
+
add(args) {
|
|
20315
20313
|
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
20316
20314
|
shrinkToDimension(this.values, minDimension);
|
|
20317
20315
|
|
|
@@ -20322,11 +20320,8 @@ class Vector {
|
|
|
20322
20320
|
return this;
|
|
20323
20321
|
}
|
|
20324
20322
|
|
|
20325
|
-
|
|
20326
|
-
|
|
20327
20323
|
/**
|
|
20328
|
-
* Performs modulo (remainder) division with a vector's
|
|
20329
|
-
* components.
|
|
20324
|
+
* Performs modulo (remainder) division with a vector's components.
|
|
20330
20325
|
*
|
|
20331
20326
|
* `rem()` can use separate numbers, as in `v.rem(1, 2, 3)`,
|
|
20332
20327
|
* another <a href="#/p5.Vector">p5.Vector</a> object, as in `v.rem(v2)`, or
|
|
@@ -20336,8 +20331,8 @@ class Vector {
|
|
|
20336
20331
|
* will be set to their values modulo 2. Calling `rem()` with no
|
|
20337
20332
|
* arguments, as in `v.rem()`, has no effect.
|
|
20338
20333
|
*
|
|
20339
|
-
*
|
|
20340
|
-
*
|
|
20334
|
+
* You should modulo vectors only when they are the same size. When two
|
|
20335
|
+
* vectors of different sizes are used, the smaller dimension will be
|
|
20341
20336
|
* used, any additional values of the longer vector will be ignored.
|
|
20342
20337
|
* For example, taking `[3, 6, 9]` modulo `[2, 4]` will result in `[1, 2]`.
|
|
20343
20338
|
*
|
|
@@ -20435,13 +20430,20 @@ class Vector {
|
|
|
20435
20430
|
* @param {p5.Vector | Number[]} value divisor vector.
|
|
20436
20431
|
* @chainable
|
|
20437
20432
|
*/
|
|
20438
|
-
rem(
|
|
20433
|
+
rem(args) {
|
|
20439
20434
|
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
20440
20435
|
|
|
20441
20436
|
shrinkToDimension(this.values, minDimension);
|
|
20442
|
-
|
|
20443
|
-
|
|
20444
|
-
|
|
20437
|
+
|
|
20438
|
+
if(Array.isArray(args)){
|
|
20439
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
20440
|
+
if (args[i] > 0) {
|
|
20441
|
+
this.values[i] = this.values[i] % args[i];
|
|
20442
|
+
}
|
|
20443
|
+
}
|
|
20444
|
+
} else if(args > 0) {
|
|
20445
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
20446
|
+
this.values[i] = this.values[i] % args;
|
|
20445
20447
|
}
|
|
20446
20448
|
}
|
|
20447
20449
|
|
|
@@ -20449,7 +20451,7 @@ class Vector {
|
|
|
20449
20451
|
}
|
|
20450
20452
|
|
|
20451
20453
|
/**
|
|
20452
|
-
* Subtracts from a vector's
|
|
20454
|
+
* Subtracts from a vector's components.
|
|
20453
20455
|
*
|
|
20454
20456
|
* `sub()` can use separate numbers, as in `v.sub(1, 2, 3)`, another
|
|
20455
20457
|
* <a href="#/p5.Vector">p5.Vector</a> object, as in `v.sub(v2)`, or an array
|
|
@@ -20457,8 +20459,8 @@ class Vector {
|
|
|
20457
20459
|
*
|
|
20458
20460
|
* Calling `sub()` with no arguments, as in `v.sub()`, has no effect.
|
|
20459
20461
|
*
|
|
20460
|
-
*
|
|
20461
|
-
*
|
|
20462
|
+
* You should subtract vectors only when they are the same size. When two
|
|
20463
|
+
* vectors of different sizes are used, the smaller dimension will be
|
|
20462
20464
|
* used, any additional values of the longer vector will be ignored.
|
|
20463
20465
|
* For example, subtracting `[1, 2]` from `[3, 5, 7]` will result in `[2, 3]`.
|
|
20464
20466
|
*
|
|
@@ -20570,7 +20572,7 @@ class Vector {
|
|
|
20570
20572
|
* @param {p5.Vector|Number[]} value the vector to subtract
|
|
20571
20573
|
* @chainable
|
|
20572
20574
|
*/
|
|
20573
|
-
sub(
|
|
20575
|
+
sub(args) {
|
|
20574
20576
|
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
20575
20577
|
shrinkToDimension(this.values, minDimension);
|
|
20576
20578
|
|
|
@@ -20582,7 +20584,7 @@ class Vector {
|
|
|
20582
20584
|
}
|
|
20583
20585
|
|
|
20584
20586
|
/**
|
|
20585
|
-
* Multiplies a vector's
|
|
20587
|
+
* Multiplies a vector's components.
|
|
20586
20588
|
*
|
|
20587
20589
|
* `mult()` can use separate numbers, as in `v.mult(1, 2, 3)`, another
|
|
20588
20590
|
* <a href="#/p5.Vector">p5.Vector</a> object, as in `v.mult(v2)`, or an array
|
|
@@ -20592,8 +20594,8 @@ class Vector {
|
|
|
20592
20594
|
* will be multiplied by 2. Calling `mult()` with no arguments, as in `v.mult()`, has
|
|
20593
20595
|
* no effect.
|
|
20594
20596
|
*
|
|
20595
|
-
*
|
|
20596
|
-
*
|
|
20597
|
+
* You should multiply vectors only when they are the same size. When two
|
|
20598
|
+
* vectors of different sizes are multiplied, the smaller dimension will be
|
|
20597
20599
|
* used, any additional values of the longer vector will be ignored.
|
|
20598
20600
|
* For example, multiplying `[1, 2, 3]` by `[4, 5]` will result in `[4, 10]`.
|
|
20599
20601
|
*
|
|
@@ -20758,19 +20760,25 @@ class Vector {
|
|
|
20758
20760
|
* @param {p5.Vector} v vector to multiply with the components of the original vector.
|
|
20759
20761
|
* @chainable
|
|
20760
20762
|
*/
|
|
20761
|
-
mult(
|
|
20763
|
+
mult(args) {
|
|
20762
20764
|
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
20763
20765
|
shrinkToDimension(this.values, minDimension);
|
|
20764
20766
|
|
|
20765
|
-
|
|
20766
|
-
this.values
|
|
20767
|
+
if(Array.isArray(args)){
|
|
20768
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
20769
|
+
this.values[i] *= args[i];
|
|
20770
|
+
}
|
|
20771
|
+
} else {
|
|
20772
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
20773
|
+
this.values[i] *= args;
|
|
20774
|
+
}
|
|
20767
20775
|
}
|
|
20768
20776
|
|
|
20769
20777
|
return this;
|
|
20770
20778
|
}
|
|
20771
20779
|
|
|
20772
20780
|
/**
|
|
20773
|
-
* Divides a vector's
|
|
20781
|
+
* Divides a vector's components.
|
|
20774
20782
|
*
|
|
20775
20783
|
* `div()` can use separate numbers, as in `v.div(1, 2, 3)`, another
|
|
20776
20784
|
* <a href="#/p5.Vector">p5.Vector</a> object, as in `v.div(v2)`, or an array
|
|
@@ -20780,8 +20788,8 @@ class Vector {
|
|
|
20780
20788
|
* will be divided by 2. Calling `div()` with no arguments, as in `v.div()`, has
|
|
20781
20789
|
* no effect.
|
|
20782
20790
|
*
|
|
20783
|
-
*
|
|
20784
|
-
*
|
|
20791
|
+
* You should divide vectors only when they are the same size. When two
|
|
20792
|
+
* vectors of different sizes are divided, the smaller dimension will be
|
|
20785
20793
|
* used, any additional values of the longer vector will be ignored.
|
|
20786
20794
|
* For example, dividing `[8, 12, 21]` by `[2, 3]` will result in `[4, 4]`.
|
|
20787
20795
|
*
|
|
@@ -20947,24 +20955,41 @@ class Vector {
|
|
|
20947
20955
|
* @param {p5.Vector} v vector to divide the components of the original vector by.
|
|
20948
20956
|
* @chainable
|
|
20949
20957
|
*/
|
|
20950
|
-
div(
|
|
20958
|
+
div(args) {
|
|
20951
20959
|
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
20952
20960
|
|
|
20953
|
-
|
|
20954
|
-
|
|
20955
|
-
if (
|
|
20956
|
-
|
|
20957
|
-
|
|
20958
|
-
|
|
20959
|
-
|
|
20961
|
+
if (Array.isArray(args)) {
|
|
20962
|
+
for (let i = 0; i < minDimension; i++) {
|
|
20963
|
+
if ((typeof args[i] !== 'number' || args[i] === 0)) {
|
|
20964
|
+
if (!this.friendlyErrorsDisabled()) {
|
|
20965
|
+
console.warn(
|
|
20966
|
+
'p5.Vector.prototype.div',
|
|
20967
|
+
'Arguments contain components that are 0'
|
|
20968
|
+
);
|
|
20969
|
+
}
|
|
20970
|
+
return this;
|
|
20960
20971
|
}
|
|
20961
|
-
return this;
|
|
20962
20972
|
}
|
|
20973
|
+
} else if(typeof args !== 'number' || args === 0) {
|
|
20974
|
+
if (!this.friendlyErrorsDisabled()) {
|
|
20975
|
+
console.warn(
|
|
20976
|
+
'p5.Vector.prototype.div',
|
|
20977
|
+
'Arguments contain components that are 0'
|
|
20978
|
+
);
|
|
20979
|
+
}
|
|
20980
|
+
return this;
|
|
20963
20981
|
}
|
|
20964
20982
|
|
|
20965
20983
|
shrinkToDimension(this.values, minDimension);
|
|
20966
|
-
|
|
20967
|
-
|
|
20984
|
+
|
|
20985
|
+
if(Array.isArray(args)){
|
|
20986
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
20987
|
+
this.values[i] /= args[i];
|
|
20988
|
+
}
|
|
20989
|
+
} else {
|
|
20990
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
20991
|
+
this.values[i] /= args;
|
|
20992
|
+
}
|
|
20968
20993
|
}
|
|
20969
20994
|
|
|
20970
20995
|
return this;
|
|
@@ -108358,7 +108383,7 @@ if (typeof p5 !== 'undefined') {
|
|
|
108358
108383
|
function _defaultEmptyVector(target){
|
|
108359
108384
|
return function(...args){
|
|
108360
108385
|
if(args.length === 0){
|
|
108361
|
-
this._friendlyError(
|
|
108386
|
+
this.constructor._friendlyError(
|
|
108362
108387
|
'In 1.x, createVector() was a shortcut for createVector(0, 0, 0). In 2.x, p5.js has vectors of any dimension, so you must provide your desired number of zeros. Use createVector(0, 0) for a 2D vector and createVector(0, 0, 0) for a 3D vector.',
|
|
108363
108388
|
'p5.createVector'
|
|
108364
108389
|
);
|
|
@@ -108379,7 +108404,7 @@ function _defaultEmptyVector(target){
|
|
|
108379
108404
|
*/
|
|
108380
108405
|
function _validatedVectorOperation(expectsSoloNumberArgument){
|
|
108381
108406
|
return function(target){
|
|
108382
|
-
return function(...args){
|
|
108407
|
+
return function (...args) {
|
|
108383
108408
|
if (args.length === 0) {
|
|
108384
108409
|
// No arguments? No action
|
|
108385
108410
|
return this;
|
|
@@ -108389,16 +108414,18 @@ function _validatedVectorOperation(expectsSoloNumberArgument){
|
|
|
108389
108414
|
} else if (Array.isArray(args[0])) {
|
|
108390
108415
|
// First argument is an array? Great, keep it!
|
|
108391
108416
|
args = args[0];
|
|
108392
|
-
} else if (
|
|
108417
|
+
} else if (args.length === 1){
|
|
108393
108418
|
// Special case for a solo numeric arguments only applies sometimes
|
|
108394
|
-
|
|
108419
|
+
if (expectsSoloNumberArgument) {
|
|
108420
|
+
args = args[0];
|
|
108421
|
+
}
|
|
108395
108422
|
}
|
|
108396
108423
|
|
|
108397
|
-
if
|
|
108424
|
+
if(Array.isArray(args)){
|
|
108398
108425
|
for (let i = 0; i < args.length; i++) {
|
|
108399
108426
|
const v = args[i];
|
|
108400
108427
|
if (typeof v !== 'number' || !Number.isFinite(v)) {
|
|
108401
|
-
if (!
|
|
108428
|
+
if (!this.friendlyErrorsDisabled()) {
|
|
108402
108429
|
this._friendlyError(
|
|
108403
108430
|
'Arguments contain non-finite numbers',
|
|
108404
108431
|
'p5.Vector'
|
|
@@ -108407,9 +108434,19 @@ function _validatedVectorOperation(expectsSoloNumberArgument){
|
|
|
108407
108434
|
return this;
|
|
108408
108435
|
}
|
|
108409
108436
|
}
|
|
108437
|
+
} else {
|
|
108438
|
+
if (typeof args !== 'number' || !Number.isFinite(args)) {
|
|
108439
|
+
if (!this.friendlyErrorsDisabled()) {
|
|
108440
|
+
this._friendlyError(
|
|
108441
|
+
'Arguments contain non-finite numbers',
|
|
108442
|
+
'p5.Vector'
|
|
108443
|
+
);
|
|
108444
|
+
}
|
|
108445
|
+
return this;
|
|
108446
|
+
}
|
|
108410
108447
|
}
|
|
108411
108448
|
|
|
108412
|
-
return target.call(this,
|
|
108449
|
+
return target.call(this, args);
|
|
108413
108450
|
};
|
|
108414
108451
|
};
|
|
108415
108452
|
}
|