p5 2.0.0 → 2.0.2
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/{src → dist}/accessibility/color_namer.js +48 -3
- package/{src → dist}/accessibility/describe.js +12 -2
- package/{src → dist}/accessibility/gridOutput.js +2 -2
- package/dist/accessibility/index.js +60 -0
- package/{src → dist}/accessibility/outputs.js +23 -2
- package/{src → dist}/accessibility/textOutput.js +2 -2
- package/dist/app.js +120 -0
- package/{src → dist}/color/color_conversion.js +48 -10
- package/{src → dist}/color/color_spaces/hsb.js +3 -1
- package/dist/color/creating_reading.js +3 -0
- package/dist/color/index.js +13 -0
- package/dist/color/p5.Color.culori.js +1 -0
- package/dist/color/p5.Color.js +3 -0
- package/{src → dist}/color/setting.js +9 -6
- package/{src/core/constants.js → dist/constants-tYr0tCl8.js} +284 -132
- package/{src → dist}/core/States.js +3 -1
- package/dist/core/constants.js +1 -0
- package/{src → dist}/core/environment.js +12 -10
- package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
- package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
- package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
- package/dist/core/friendly_errors/index.js +23 -0
- package/dist/core/friendly_errors/param_validator.js +5421 -0
- package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
- package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
- package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
- package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
- package/{src → dist}/core/helpers.js +9 -6
- package/dist/core/init.js +105 -0
- package/dist/core/internationalization.js +302 -0
- package/dist/core/legacy.js +73 -0
- package/dist/core/main.js +44 -0
- package/dist/core/noop.js +3 -0
- package/dist/core/p5.Graphics.js +40 -0
- package/dist/core/p5.Renderer.js +11 -0
- package/dist/core/p5.Renderer2D.js +44 -0
- package/dist/core/reference.js +1 -0
- package/dist/core/rendering.js +40 -0
- package/{src → dist}/core/structure.js +3 -3
- package/{src → dist}/core/transform.js +2 -2
- package/{src/color/creating_reading.js → dist/creating_reading-Cr8L2Jnm.js} +841 -13
- package/{src → dist}/data/index.js +3 -1
- package/{src → dist}/data/local_storage.js +2 -8
- package/{src → dist}/dom/dom.js +19 -13
- package/dist/dom/index.js +18 -0
- package/{src → dist}/dom/p5.Element.js +14 -12
- package/{src → dist}/dom/p5.File.js +4 -4
- package/{src → dist}/dom/p5.MediaElement.js +10 -4
- package/{src → dist}/events/acceleration.js +26 -26
- package/{src → dist}/events/index.js +3 -1
- package/{src → dist}/events/keyboard.js +14 -12
- package/{src → dist}/events/pointer.js +16 -17
- package/dist/image/const.js +9 -0
- package/{src → dist}/image/filterRenderer2D.js +57 -37
- package/{src → dist}/image/filters.js +1 -3
- package/dist/image/image.js +40 -0
- package/dist/image/index.js +51 -0
- package/dist/image/loading_displaying.js +40 -0
- package/dist/image/p5.Image.js +11 -0
- package/{src → dist}/image/pixels.js +5 -3
- package/{src → dist}/io/csv.js +72 -70
- package/dist/io/files.js +40 -0
- package/dist/io/index.js +51 -0
- package/{src → dist}/io/p5.Table.js +6 -6
- package/{src → dist}/io/p5.TableRow.js +5 -6
- package/{src → dist}/io/p5.XML.js +2 -5
- package/{src → dist}/io/utilities.js +1 -1
- package/{src/core/p5.Renderer2D.js → dist/main-CAxvgiOV.js} +738 -57
- package/{src → dist}/math/Matrices/Matrix.js +10 -8
- package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
- package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
- package/{src → dist}/math/calculation.js +2 -2
- package/{src → dist}/math/index.js +6 -3
- package/{src → dist}/math/math.js +3 -3
- package/{src → dist}/math/noise.js +2 -2
- package/{src → dist}/math/p5.Matrix.js +7 -4
- package/{src → dist}/math/p5.Vector.js +6 -6
- package/{src → dist}/math/random.js +2 -2
- package/{src → dist}/math/trigonometry.js +16 -15
- package/{src/image/p5.Image.js → dist/p5.Renderer-Swjl9HQO.js} +393 -22
- package/dist/rendering-B5TRR7aY.js +24960 -0
- package/{src → dist}/shape/2d_primitives.js +18 -17
- package/{src → dist}/shape/attributes.js +18 -17
- package/{src → dist}/shape/curves.js +2 -2
- package/{src → dist}/shape/custom_shapes.js +44 -64
- package/{src → dist}/shape/index.js +10 -2
- package/{src → dist}/shape/vertex.js +2 -3
- package/dist/type/index.js +25 -0
- package/{src → dist}/type/lib/Typr.js +76 -94
- package/{src → dist}/type/p5.Font.js +37 -63
- package/{src → dist}/type/textCore.js +35 -58
- package/{src → dist}/type/unicodeRanges.js +3 -1
- package/{src → dist}/utilities/conversion.js +2 -2
- package/{src → dist}/utilities/index.js +3 -1
- package/{src → dist}/utilities/time_date.js +6 -7
- package/{src → dist}/utilities/utility_functions.js +2 -2
- package/dist/webgl/3d_primitives.js +40 -0
- package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
- package/{src → dist}/webgl/GeometryBuilder.js +12 -8
- package/{src → dist}/webgl/ShaderGenerator.js +79 -82
- package/{src → dist}/webgl/ShapeBuilder.js +26 -23
- package/dist/webgl/index.js +76 -0
- package/{src → dist}/webgl/interaction.js +7 -6
- package/dist/webgl/light.js +40 -0
- package/{src → dist}/webgl/loading.js +45 -12
- package/dist/webgl/material.js +40 -0
- package/dist/webgl/p5.Camera.js +40 -0
- package/{src → dist}/webgl/p5.DataArray.js +3 -5
- package/dist/webgl/p5.Framebuffer.js +40 -0
- package/{src → dist}/webgl/p5.Geometry.js +12 -15
- package/{src → dist}/webgl/p5.Quat.js +5 -4
- package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
- package/dist/webgl/p5.RendererGL.js +40 -0
- package/dist/webgl/p5.Shader.js +40 -0
- package/dist/webgl/p5.Texture.js +40 -0
- package/{src → dist}/webgl/text.js +78 -38
- package/lib/p5.esm.js +296 -194
- package/lib/p5.js +296 -194
- package/lib/p5.min.js +1 -1
- package/package.json +17 -17
- package/translations/dev.js +6 -6
- package/translations/index.js +1 -1
- package/types/accessibility/color_namer.d.ts +8 -0
- package/types/accessibility/describe.d.ts +184 -0
- package/types/accessibility/gridOutput.d.ts +8 -0
- package/types/accessibility/outputs.d.ts +235 -0
- package/types/accessibility/textOutput.d.ts +8 -0
- package/types/color/color_conversion.d.ts +47 -0
- package/types/color/creating_reading.d.ts +1348 -0
- package/types/color/p5.Color.d.ts +1070 -0
- package/types/color/setting.d.ts +2085 -0
- package/types/core/constants.d.ts +341 -0
- package/types/core/environment.d.ts +668 -0
- package/types/core/friendly_errors/fes_core.d.ts +8 -0
- package/types/core/friendly_errors/file_errors.d.ts +8 -0
- package/types/core/friendly_errors/param_validator.d.ts +30 -0
- package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
- package/types/core/friendly_errors/stacktrace.d.ts +11 -0
- package/types/core/friendly_errors/validate_params.d.ts +8 -0
- package/types/core/helpers.d.ts +8 -0
- package/types/core/legacy.d.ts +8 -0
- package/types/core/main.d.ts +5996 -0
- package/types/core/p5.Graphics.d.ts +484 -0
- package/types/core/p5.Renderer.d.ts +14 -0
- package/types/core/reference.d.ts +8 -0
- package/types/core/rendering.d.ts +481 -0
- package/types/core/structure.d.ts +492 -0
- package/types/core/transform.d.ts +1638 -0
- package/types/data/local_storage.d.ts +323 -0
- package/types/dom/dom.d.ts +1295 -0
- package/types/dom/p5.Element.d.ts +2011 -0
- package/types/dom/p5.File.d.ts +13 -0
- package/types/dom/p5.MediaElement.d.ts +1249 -0
- package/types/events/acceleration.d.ts +193 -0
- package/types/events/keyboard.d.ts +499 -0
- package/types/events/pointer.d.ts +782 -0
- package/types/global.d.ts +5542 -0
- package/types/image/filterRenderer2D.d.ts +54 -0
- package/types/image/image.d.ts +326 -0
- package/types/image/loading_displaying.d.ts +580 -0
- package/types/image/p5.Image.d.ts +5882 -0
- package/types/image/pixels.d.ts +832 -0
- package/types/io/files.d.ts +1447 -0
- package/types/io/p5.Table.d.ts +1247 -0
- package/types/io/p5.TableRow.d.ts +343 -0
- package/types/io/p5.XML.d.ts +1188 -0
- package/types/math/Matrices/Matrix.d.ts +1029 -0
- package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
- package/types/math/calculation.d.ts +923 -0
- package/types/math/math.d.ts +90 -0
- package/types/math/noise.d.ts +311 -0
- package/types/math/p5.Matrix.d.ts +8 -0
- package/types/math/p5.Vector.d.ts +3416 -0
- package/types/math/random.d.ts +267 -0
- package/types/math/trigonometry.d.ts +663 -0
- package/types/p5.d.ts +6663 -0
- package/types/shape/2d_primitives.d.ts +1033 -0
- package/types/shape/attributes.d.ts +466 -0
- package/types/shape/curves.d.ts +740 -0
- package/types/shape/custom_shapes.d.ts +888 -0
- package/types/shape/vertex.d.ts +1141 -0
- package/types/type/p5.Font.d.ts +575 -0
- package/types/type/textCore.d.ts +1198 -0
- package/types/utilities/conversion.d.ts +894 -0
- package/types/utilities/time_date.d.ts +295 -0
- package/types/utilities/utility_functions.d.ts +587 -0
- package/types/webgl/3d_primitives.d.ts +1432 -0
- package/types/webgl/ShaderGenerator.d.ts +8 -0
- package/types/webgl/interaction.d.ts +371 -0
- package/types/webgl/light.d.ts +1184 -0
- package/types/webgl/loading.d.ts +481 -0
- package/types/webgl/material.d.ts +2656 -0
- package/types/webgl/p5.Camera.d.ts +3023 -0
- package/types/webgl/p5.DataArray.d.ts +61 -0
- package/types/webgl/p5.Framebuffer.d.ts +760 -0
- package/types/webgl/p5.Geometry.d.ts +1191 -0
- package/types/webgl/p5.Quat.d.ts +45 -0
- package/types/webgl/p5.RendererGL.d.ts +234 -0
- package/types/webgl/p5.Shader.d.ts +660 -0
- package/types/webgl/p5.Texture.d.ts +61 -0
- package/types/webgl/text.d.ts +74 -0
- package/src/README.md +0 -27
- package/src/accessibility/index.js +0 -13
- package/src/app.js +0 -61
- package/src/color/index.js +0 -9
- package/src/color/p5.Color.culori.js +0 -66
- package/src/color/p5.Color.js +0 -851
- package/src/core/README.md +0 -91
- package/src/core/friendly_errors/index.js +0 -13
- package/src/core/friendly_errors/param_validator.js +0 -561
- package/src/core/init.js +0 -58
- package/src/core/internationalization.js +0 -195
- package/src/core/legacy.js +0 -29
- package/src/core/main.js +0 -689
- package/src/core/noop.js +0 -1
- package/src/core/p5.Graphics.js +0 -696
- package/src/core/p5.Renderer.js +0 -408
- package/src/core/reference.js +0 -2060
- package/src/core/rendering.js +0 -697
- package/src/dom/index.js +0 -11
- package/src/image/const.js +0 -6
- package/src/image/image.js +0 -731
- package/src/image/index.js +0 -15
- package/src/image/loading_displaying.js +0 -1431
- package/src/io/files.js +0 -2210
- package/src/io/index.js +0 -11
- package/src/math/README.md +0 -40
- package/src/type/index.js +0 -9
- package/src/webgl/3d_primitives.js +0 -2741
- package/src/webgl/index.js +0 -37
- package/src/webgl/light.js +0 -1851
- package/src/webgl/material.js +0 -3854
- package/src/webgl/p5.Camera.js +0 -4010
- package/src/webgl/p5.Framebuffer.js +0 -1865
- package/src/webgl/p5.RendererGL.js +0 -2867
- package/src/webgl/p5.Shader.js +0 -1505
- package/src/webgl/p5.Texture.js +0 -541
- package/src/webgl/shaders/basic.frag +0 -6
- package/src/webgl/shaders/filters/base.frag +0 -22
- package/src/webgl/shaders/filters/base.vert +0 -19
- package/src/webgl/shaders/filters/blur.frag +0 -60
- package/src/webgl/shaders/filters/default.vert +0 -18
- package/src/webgl/shaders/filters/dilate.frag +0 -39
- package/src/webgl/shaders/filters/erode.frag +0 -39
- package/src/webgl/shaders/filters/gray.frag +0 -16
- package/src/webgl/shaders/filters/invert.frag +0 -15
- package/src/webgl/shaders/filters/opaque.frag +0 -12
- package/src/webgl/shaders/filters/posterize.frag +0 -29
- package/src/webgl/shaders/filters/threshold.frag +0 -23
- package/src/webgl/shaders/font.frag +0 -216
- package/src/webgl/shaders/font.vert +0 -44
- package/src/webgl/shaders/imageLight.vert +0 -33
- package/src/webgl/shaders/imageLightDiffused.frag +0 -82
- package/src/webgl/shaders/imageLightSpecular.frag +0 -134
- package/src/webgl/shaders/light.vert +0 -37
- package/src/webgl/shaders/light_texture.frag +0 -26
- package/src/webgl/shaders/lighting.glsl +0 -227
- package/src/webgl/shaders/line.frag +0 -74
- package/src/webgl/shaders/line.vert +0 -294
- package/src/webgl/shaders/normal.frag +0 -6
- package/src/webgl/shaders/normal.vert +0 -72
- package/src/webgl/shaders/phong.frag +0 -84
- package/src/webgl/shaders/phong.vert +0 -87
- package/src/webgl/shaders/point.frag +0 -29
- package/src/webgl/shaders/point.vert +0 -19
- package/src/webgl/shaders/sphereMapping.frag +0 -26
- package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { C as Color } from './creating_reading-Cr8L2Jnm.js';
|
|
2
|
+
import { N as NORMAL, am as WORD, an as BASELINE, ao as LEFT, C as CENTER, e as CORNER, I as INCLUDE } from './constants-tYr0tCl8.js';
|
|
3
|
+
import Filters from './image/filters.js';
|
|
4
|
+
import { Vector } from './math/p5.Vector.js';
|
|
5
|
+
import { Shape } from './shape/custom_shapes.js';
|
|
6
|
+
import { States } from './core/States.js';
|
|
7
|
+
import { _checkFileExtension, downloadFile } from './io/utilities.js';
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* @module Image
|
|
3
11
|
* @submodule Image
|
|
@@ -6,13 +14,6 @@
|
|
|
6
14
|
* @requires filters
|
|
7
15
|
*/
|
|
8
16
|
|
|
9
|
-
/**
|
|
10
|
-
* This module defines the <a href="#/p5.Image">p5.Image</a> class and P5 methods for
|
|
11
|
-
* drawing images to the main display canvas.
|
|
12
|
-
*/
|
|
13
|
-
import Filters from './filters';
|
|
14
|
-
import { Renderer } from '../core/p5.Renderer';
|
|
15
|
-
import { downloadFile, _checkFileExtension } from '../io/utilities';
|
|
16
17
|
|
|
17
18
|
class Image {
|
|
18
19
|
constructor(width, height) {
|
|
@@ -48,11 +49,6 @@ class Image {
|
|
|
48
49
|
if (typeof density !== 'undefined') {
|
|
49
50
|
// Setter: set the density and handle resize
|
|
50
51
|
if (density <= 0) {
|
|
51
|
-
const errorObj = {
|
|
52
|
-
type: 'INVALID_VALUE',
|
|
53
|
-
format: { types: ['Number'] },
|
|
54
|
-
position: 1
|
|
55
|
-
};
|
|
56
52
|
|
|
57
53
|
// p5._friendlyParamError(errorObj, 'pixelDensity');
|
|
58
54
|
|
|
@@ -1637,7 +1633,7 @@ class Image {
|
|
|
1637
1633
|
*
|
|
1638
1634
|
* async function setup() {
|
|
1639
1635
|
* // Load the image.
|
|
1640
|
-
* gif = await loadImage('assets/arnott-wallace-
|
|
1636
|
+
* gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
|
|
1641
1637
|
*
|
|
1642
1638
|
* createCanvas(100, 100);
|
|
1643
1639
|
*
|
|
@@ -1677,7 +1673,7 @@ class Image {
|
|
|
1677
1673
|
*
|
|
1678
1674
|
* async function setup() {
|
|
1679
1675
|
* // Load the image.
|
|
1680
|
-
* gif = await loadImage('assets/arnott-wallace-
|
|
1676
|
+
* gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
|
|
1681
1677
|
*
|
|
1682
1678
|
* createCanvas(100, 100);
|
|
1683
1679
|
*
|
|
@@ -1733,7 +1729,7 @@ class Image {
|
|
|
1733
1729
|
*
|
|
1734
1730
|
* async function setup() {
|
|
1735
1731
|
* // Load the image.
|
|
1736
|
-
* gif = await loadImage('assets/arnott-wallace-
|
|
1732
|
+
* gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
|
|
1737
1733
|
*
|
|
1738
1734
|
* createCanvas(100, 100);
|
|
1739
1735
|
*
|
|
@@ -1926,8 +1922,7 @@ class Image {
|
|
|
1926
1922
|
}
|
|
1927
1923
|
}
|
|
1928
1924
|
}
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1925
|
+
}
|
|
1931
1926
|
function encodeAndDownloadGif(pImg, filename) {
|
|
1932
1927
|
const props = pImg.gifProperties;
|
|
1933
1928
|
|
|
@@ -2151,8 +2146,7 @@ function encodeAndDownloadGif(pImg, filename) {
|
|
|
2151
2146
|
type: 'image/gif'
|
|
2152
2147
|
});
|
|
2153
2148
|
downloadFile(blob, filename, extension);
|
|
2154
|
-
}
|
|
2155
|
-
|
|
2149
|
+
}
|
|
2156
2150
|
function image(p5, fn){
|
|
2157
2151
|
/**
|
|
2158
2152
|
* A class to describe an image.
|
|
@@ -2415,9 +2409,386 @@ function image(p5, fn){
|
|
|
2415
2409
|
*/
|
|
2416
2410
|
}
|
|
2417
2411
|
|
|
2418
|
-
export default image;
|
|
2419
|
-
export { Image };
|
|
2420
|
-
|
|
2421
2412
|
if(typeof p5 !== 'undefined'){
|
|
2422
2413
|
image(p5, p5.prototype);
|
|
2423
2414
|
}
|
|
2415
|
+
|
|
2416
|
+
/**
|
|
2417
|
+
* @module Rendering
|
|
2418
|
+
* @submodule Rendering
|
|
2419
|
+
* @for p5
|
|
2420
|
+
*/
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
class ClonableObject {
|
|
2424
|
+
constructor(obj = {}) {
|
|
2425
|
+
for (const key in obj) {
|
|
2426
|
+
this[key] = obj[key];
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
clone() {
|
|
2431
|
+
return new ClonableObject(this);
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
class Renderer {
|
|
2435
|
+
static states = {
|
|
2436
|
+
strokeColor: null,
|
|
2437
|
+
strokeSet: false,
|
|
2438
|
+
fillColor: null,
|
|
2439
|
+
fillSet: false,
|
|
2440
|
+
tint: null,
|
|
2441
|
+
|
|
2442
|
+
imageMode: CORNER,
|
|
2443
|
+
rectMode: CORNER,
|
|
2444
|
+
ellipseMode: CENTER,
|
|
2445
|
+
strokeWeight: 1,
|
|
2446
|
+
|
|
2447
|
+
textFont: { family: 'sans-serif' },
|
|
2448
|
+
textLeading: 15,
|
|
2449
|
+
leadingSet: false,
|
|
2450
|
+
textSize: 12,
|
|
2451
|
+
textAlign: LEFT,
|
|
2452
|
+
textBaseline: BASELINE,
|
|
2453
|
+
bezierOrder: 3,
|
|
2454
|
+
splineProperties: new ClonableObject({ ends: INCLUDE, tightness: 0 }),
|
|
2455
|
+
textWrap: WORD,
|
|
2456
|
+
|
|
2457
|
+
// added v2.0
|
|
2458
|
+
fontStyle: NORMAL, // v1: textStyle
|
|
2459
|
+
fontStretch: NORMAL,
|
|
2460
|
+
fontWeight: NORMAL,
|
|
2461
|
+
lineHeight: NORMAL,
|
|
2462
|
+
fontVariant: NORMAL,
|
|
2463
|
+
direction: 'inherit'
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
constructor(pInst, w, h, isMainCanvas) {
|
|
2467
|
+
this._pInst = pInst;
|
|
2468
|
+
this._isMainCanvas = isMainCanvas;
|
|
2469
|
+
this.pixels = [];
|
|
2470
|
+
this._pixelDensity = Math.ceil(window.devicePixelRatio) || 1;
|
|
2471
|
+
|
|
2472
|
+
this.width = w;
|
|
2473
|
+
this.height = h;
|
|
2474
|
+
|
|
2475
|
+
this._events = {};
|
|
2476
|
+
|
|
2477
|
+
if (isMainCanvas) {
|
|
2478
|
+
this._isMainCanvas = true;
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
// Renderer state machine
|
|
2482
|
+
this.states = new States(Renderer.states);
|
|
2483
|
+
|
|
2484
|
+
this.states.strokeColor = new Color([0, 0, 0]);
|
|
2485
|
+
this.states.fillColor = new Color([1, 1, 1]);
|
|
2486
|
+
|
|
2487
|
+
this._pushPopStack = [];
|
|
2488
|
+
// NOTE: can use the length of the push pop stack instead
|
|
2489
|
+
this._pushPopDepth = 0;
|
|
2490
|
+
|
|
2491
|
+
this._clipping = false;
|
|
2492
|
+
this._clipInvert = false;
|
|
2493
|
+
|
|
2494
|
+
this._currentShape = undefined; // Lazily generate current shape
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
get currentShape() {
|
|
2498
|
+
if (!this._currentShape) {
|
|
2499
|
+
this._currentShape = new Shape(this.getCommonVertexProperties());
|
|
2500
|
+
}
|
|
2501
|
+
return this._currentShape;
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
remove() {
|
|
2505
|
+
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
pixelDensity(val){
|
|
2509
|
+
let returnValue;
|
|
2510
|
+
if (typeof val === 'number') {
|
|
2511
|
+
if (val !== this._pixelDensity) {
|
|
2512
|
+
this._pixelDensity = val;
|
|
2513
|
+
}
|
|
2514
|
+
returnValue = this;
|
|
2515
|
+
this.resize(this.width, this.height);
|
|
2516
|
+
} else {
|
|
2517
|
+
returnValue = this._pixelDensity;
|
|
2518
|
+
}
|
|
2519
|
+
return returnValue;
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
// Makes a shallow copy of the current states
|
|
2523
|
+
// and push it into the push pop stack
|
|
2524
|
+
push() {
|
|
2525
|
+
this._pushPopDepth++;
|
|
2526
|
+
this._pushPopStack.push(this.states.getDiff());
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
// Pop the previous states out of the push pop stack and
|
|
2530
|
+
// assign it back to the current state
|
|
2531
|
+
pop() {
|
|
2532
|
+
this._pushPopDepth--;
|
|
2533
|
+
const diff = this._pushPopStack.pop() || {};
|
|
2534
|
+
const modified = this.states.getModified();
|
|
2535
|
+
this.states.applyDiff(diff);
|
|
2536
|
+
this.updateShapeVertexProperties(modified);
|
|
2537
|
+
this.updateShapeProperties(modified);
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
bezierOrder(order) {
|
|
2541
|
+
if (order === undefined) {
|
|
2542
|
+
return this.states.bezierOrder;
|
|
2543
|
+
} else {
|
|
2544
|
+
this.states.setValue('bezierOrder', order);
|
|
2545
|
+
this.updateShapeProperties();
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
bezierVertex(x, y, z = 0, u = 0, v = 0) {
|
|
2550
|
+
const position = new Vector(x, y, z);
|
|
2551
|
+
const textureCoordinates = this.getSupportedIndividualVertexProperties().textureCoordinates
|
|
2552
|
+
? new Vector(u, v)
|
|
2553
|
+
: undefined;
|
|
2554
|
+
this.currentShape.bezierVertex(position, textureCoordinates);
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
splineProperty(key, value) {
|
|
2558
|
+
if (value === undefined) {
|
|
2559
|
+
return this.states.splineProperties[key];
|
|
2560
|
+
} else {
|
|
2561
|
+
this.states.setValue('splineProperties', this.states.splineProperties.clone());
|
|
2562
|
+
this.states.splineProperties[key] = value;
|
|
2563
|
+
}
|
|
2564
|
+
this.updateShapeProperties();
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
splineProperties(values) {
|
|
2568
|
+
if (values) {
|
|
2569
|
+
for (const key in values) {
|
|
2570
|
+
this.splineProperty(key, values[key]);
|
|
2571
|
+
}
|
|
2572
|
+
} else {
|
|
2573
|
+
return { ...this.states.splineProperties };
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
splineVertex(x, y, z = 0, u = 0, v = 0) {
|
|
2578
|
+
const position = new Vector(x, y, z);
|
|
2579
|
+
const textureCoordinates = this.getSupportedIndividualVertexProperties().textureCoordinates
|
|
2580
|
+
? new Vector(u, v)
|
|
2581
|
+
: undefined;
|
|
2582
|
+
this.currentShape.splineVertex(position, textureCoordinates);
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
curveDetail(d) {
|
|
2586
|
+
if (d === undefined) {
|
|
2587
|
+
return this.states.curveDetail;
|
|
2588
|
+
} else {
|
|
2589
|
+
this.states.setValue('curveDetail', d);
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
beginShape(...args) {
|
|
2594
|
+
this.currentShape.reset();
|
|
2595
|
+
this.updateShapeVertexProperties();
|
|
2596
|
+
this.currentShape.beginShape(...args);
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
endShape(...args) {
|
|
2600
|
+
this.currentShape.endShape(...args);
|
|
2601
|
+
this.drawShape(this.currentShape);
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
beginContour(shapeKind) {
|
|
2605
|
+
this.currentShape.beginContour(shapeKind);
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
endContour(mode) {
|
|
2609
|
+
this.currentShape.endContour(mode);
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
drawShape(shape, count) {
|
|
2613
|
+
throw new Error('Unimplemented')
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
vertex(x, y, z = 0, u = 0, v = 0) {
|
|
2617
|
+
const position = new Vector(x, y, z);
|
|
2618
|
+
const textureCoordinates = this.getSupportedIndividualVertexProperties().textureCoordinates
|
|
2619
|
+
? new Vector(u, v)
|
|
2620
|
+
: undefined;
|
|
2621
|
+
this.currentShape.vertex(position, textureCoordinates);
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
bezier(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
2625
|
+
const oldOrder = this._pInst.bezierOrder();
|
|
2626
|
+
this._pInst.bezierOrder(oldOrder);
|
|
2627
|
+
this._pInst.beginShape();
|
|
2628
|
+
this._pInst.bezierVertex(x1, y1);
|
|
2629
|
+
this._pInst.bezierVertex(x2, y2);
|
|
2630
|
+
this._pInst.bezierVertex(x3, y3);
|
|
2631
|
+
this._pInst.bezierVertex(x4, y4);
|
|
2632
|
+
this._pInst.endShape();
|
|
2633
|
+
return this;
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
spline(...args) {
|
|
2637
|
+
if (args.length === 2 * 4) {
|
|
2638
|
+
const [x1, y1, x2, y2, x3, y3, x4, y4] = args;
|
|
2639
|
+
this._pInst.beginShape();
|
|
2640
|
+
this._pInst.splineVertex(x1, y1);
|
|
2641
|
+
this._pInst.splineVertex(x2, y2);
|
|
2642
|
+
this._pInst.splineVertex(x3, y3);
|
|
2643
|
+
this._pInst.splineVertex(x4, y4);
|
|
2644
|
+
this._pInst.endShape();
|
|
2645
|
+
} else if (args.length === 3 * 4) {
|
|
2646
|
+
const [x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4] = args;
|
|
2647
|
+
this._pInst.beginShape();
|
|
2648
|
+
this._pInst.splineVertex(x1, y1, z1);
|
|
2649
|
+
this._pInst.splineVertex(x2, y2, z2);
|
|
2650
|
+
this._pInst.splineVertex(x3, y3, z3);
|
|
2651
|
+
this._pInst.splineVertex(x4, y4, z4);
|
|
2652
|
+
this._pInst.endShape();
|
|
2653
|
+
}
|
|
2654
|
+
return this;
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
beginClip(options = {}) {
|
|
2658
|
+
if (this._clipping) {
|
|
2659
|
+
throw new Error("It looks like you're trying to clip while already in the middle of clipping. Did you forget to endClip()?");
|
|
2660
|
+
}
|
|
2661
|
+
this._clipping = true;
|
|
2662
|
+
this._clipInvert = options.invert;
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
endClip() {
|
|
2666
|
+
if (!this._clipping) {
|
|
2667
|
+
throw new Error("It looks like you've called endClip() without beginClip(). Did you forget to call beginClip() first?");
|
|
2668
|
+
}
|
|
2669
|
+
this._clipping = false;
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
/**
|
|
2673
|
+
* Resize our canvas element.
|
|
2674
|
+
*/
|
|
2675
|
+
resize(w, h) {
|
|
2676
|
+
this.width = w;
|
|
2677
|
+
this.height = h;
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
get(x, y, w, h) {
|
|
2681
|
+
const pd = this._pixelDensity;
|
|
2682
|
+
const canvas = this.canvas;
|
|
2683
|
+
|
|
2684
|
+
if (typeof x === 'undefined' && typeof y === 'undefined') {
|
|
2685
|
+
// get()
|
|
2686
|
+
x = y = 0;
|
|
2687
|
+
w = this.width;
|
|
2688
|
+
h = this.height;
|
|
2689
|
+
} else {
|
|
2690
|
+
x *= pd;
|
|
2691
|
+
y *= pd;
|
|
2692
|
+
|
|
2693
|
+
if (typeof w === 'undefined' && typeof h === 'undefined') {
|
|
2694
|
+
// get(x,y)
|
|
2695
|
+
if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) {
|
|
2696
|
+
return [0, 0, 0, 0];
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
return this._getPixel(x, y);
|
|
2700
|
+
}
|
|
2701
|
+
// get(x,y,w,h)
|
|
2702
|
+
}
|
|
2703
|
+
|
|
2704
|
+
const region = new Image(w*pd, h*pd);
|
|
2705
|
+
region.pixelDensity(pd);
|
|
2706
|
+
region.canvas
|
|
2707
|
+
.getContext('2d')
|
|
2708
|
+
.drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w*pd, h*pd);
|
|
2709
|
+
|
|
2710
|
+
return region;
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
scale(x, y){
|
|
2714
|
+
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
fill(...args) {
|
|
2718
|
+
this.states.setValue('fillSet', true);
|
|
2719
|
+
this.states.setValue('fillColor', this._pInst.color(...args));
|
|
2720
|
+
this.updateShapeVertexProperties();
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
noFill() {
|
|
2724
|
+
this.states.setValue('fillColor', null);
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
strokeWeight(w) {
|
|
2728
|
+
if (w === undefined) {
|
|
2729
|
+
return this.states.strokeWeight;
|
|
2730
|
+
} else {
|
|
2731
|
+
this.states.setValue('strokeWeight', w);
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
stroke(...args) {
|
|
2736
|
+
this.states.setValue('strokeSet', true);
|
|
2737
|
+
this.states.setValue('strokeColor', this._pInst.color(...args));
|
|
2738
|
+
this.updateShapeVertexProperties();
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
noStroke() {
|
|
2742
|
+
this.states.setValue('strokeColor', null);
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
getCommonVertexProperties() {
|
|
2746
|
+
return {}
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
getSupportedIndividualVertexProperties() {
|
|
2750
|
+
return {
|
|
2751
|
+
textureCoordinates: false,
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2755
|
+
updateShapeProperties(modified) {
|
|
2756
|
+
if (!modified || modified.bezierOrder || modified.splineProperties) {
|
|
2757
|
+
const shape = this.currentShape;
|
|
2758
|
+
shape.bezierOrder(this.states.bezierOrder);
|
|
2759
|
+
shape.splineProperty('ends', this.states.splineProperties.ends);
|
|
2760
|
+
shape.splineProperty('tightness', this.states.splineProperties.tightness);
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
updateShapeVertexProperties(modified) {
|
|
2765
|
+
const props = this.getCommonVertexProperties();
|
|
2766
|
+
if (!modified || Object.keys(modified).some((k) => k in props)) {
|
|
2767
|
+
const shape = this.currentShape;
|
|
2768
|
+
for (const key in props) {
|
|
2769
|
+
shape[key](props[key]);
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2774
|
+
_applyDefaults() {
|
|
2775
|
+
return this;
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
}
|
|
2779
|
+
function renderer(p5, fn){
|
|
2780
|
+
/**
|
|
2781
|
+
* Main graphics and rendering context, as well as the base API
|
|
2782
|
+
* implementation for p5.js "core". To be used as the superclass for
|
|
2783
|
+
* Renderer2D and Renderer3D classes, respectively.
|
|
2784
|
+
*
|
|
2785
|
+
* @class p5.Renderer
|
|
2786
|
+
* @param {HTMLElement} elt DOM node that is wrapped
|
|
2787
|
+
* @param {p5} [pInst] pointer to p5 instance
|
|
2788
|
+
* @param {Boolean} [isMainCanvas] whether we're using it as main canvas
|
|
2789
|
+
* @private
|
|
2790
|
+
*/
|
|
2791
|
+
p5.Renderer = Renderer;
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
export { Image as I, Renderer as R, image as i, renderer as r };
|