p5 2.0.0 → 2.0.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/{src → dist}/accessibility/color_namer.js +48 -3
- package/{src → dist}/accessibility/describe.js +2 -2
- package/{src → dist}/accessibility/gridOutput.js +2 -2
- package/dist/accessibility/index.js +60 -0
- package/{src → dist}/accessibility/outputs.js +2 -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-C-g_eAdC.js} +266 -130
- package/{src → dist}/core/States.js +3 -1
- package/dist/core/constants.js +1 -0
- package/{src → dist}/core/environment.js +7 -6
- 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 +5455 -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-D4AAKRbx.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 +11 -5
- 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 +2 -2
- package/{src → dist}/events/index.js +3 -1
- package/{src → dist}/events/keyboard.js +14 -11
- 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 +4 -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 +3 -4
- 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-s72KWcUy.js} +735 -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 +2 -2
- 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-CwAYZOC2.js} +390 -19
- package/dist/rendering--aAe5aq3.js +24925 -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 -61
- package/{src → dist}/type/textCore.js +34 -57
- 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 +51 -9
- package/lib/p5.esm.js +102 -48
- package/lib/p5.js +102 -48
- package/lib/p5.min.js +1 -1
- package/package.json +17 -16
- package/translations/dev.js +6 -6
- package/translations/index.js +1 -1
- 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
package/src/core/p5.Renderer.js
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Rendering
|
|
3
|
-
* @submodule Rendering
|
|
4
|
-
* @for p5
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { Color } from '../color/p5.Color';
|
|
8
|
-
import * as constants from '../core/constants';
|
|
9
|
-
import { Image } from '../image/p5.Image';
|
|
10
|
-
import { Vector } from '../math/p5.Vector';
|
|
11
|
-
import { Shape } from '../shape/custom_shapes';
|
|
12
|
-
import { States } from './States';
|
|
13
|
-
|
|
14
|
-
class ClonableObject {
|
|
15
|
-
constructor(obj = {}) {
|
|
16
|
-
for (const key in obj) {
|
|
17
|
-
this[key] = obj[key];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
clone() {
|
|
22
|
-
return new ClonableObject(this);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
class Renderer {
|
|
27
|
-
static states = {
|
|
28
|
-
strokeColor: null,
|
|
29
|
-
strokeSet: false,
|
|
30
|
-
fillColor: null,
|
|
31
|
-
fillSet: false,
|
|
32
|
-
tint: null,
|
|
33
|
-
|
|
34
|
-
imageMode: constants.CORNER,
|
|
35
|
-
rectMode: constants.CORNER,
|
|
36
|
-
ellipseMode: constants.CENTER,
|
|
37
|
-
strokeWeight: 1,
|
|
38
|
-
|
|
39
|
-
textFont: { family: 'sans-serif' },
|
|
40
|
-
textLeading: 15,
|
|
41
|
-
leadingSet: false,
|
|
42
|
-
textSize: 12,
|
|
43
|
-
textAlign: constants.LEFT,
|
|
44
|
-
textBaseline: constants.BASELINE,
|
|
45
|
-
bezierOrder: 3,
|
|
46
|
-
splineProperties: new ClonableObject({ ends: constants.INCLUDE, tightness: 0 }),
|
|
47
|
-
textWrap: constants.WORD,
|
|
48
|
-
|
|
49
|
-
// added v2.0
|
|
50
|
-
fontStyle: constants.NORMAL, // v1: textStyle
|
|
51
|
-
fontStretch: constants.NORMAL,
|
|
52
|
-
fontWeight: constants.NORMAL,
|
|
53
|
-
lineHeight: constants.NORMAL,
|
|
54
|
-
fontVariant: constants.NORMAL,
|
|
55
|
-
direction: 'inherit'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
constructor(pInst, w, h, isMainCanvas) {
|
|
59
|
-
this._pInst = pInst;
|
|
60
|
-
this._isMainCanvas = isMainCanvas;
|
|
61
|
-
this.pixels = [];
|
|
62
|
-
this._pixelDensity = Math.ceil(window.devicePixelRatio) || 1;
|
|
63
|
-
|
|
64
|
-
this.width = w;
|
|
65
|
-
this.height = h;
|
|
66
|
-
|
|
67
|
-
this._events = {};
|
|
68
|
-
|
|
69
|
-
if (isMainCanvas) {
|
|
70
|
-
this._isMainCanvas = true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Renderer state machine
|
|
74
|
-
this.states = new States(Renderer.states);
|
|
75
|
-
|
|
76
|
-
this.states.strokeColor = new Color([0, 0, 0]);
|
|
77
|
-
this.states.fillColor = new Color([1, 1, 1]);
|
|
78
|
-
|
|
79
|
-
this._pushPopStack = [];
|
|
80
|
-
// NOTE: can use the length of the push pop stack instead
|
|
81
|
-
this._pushPopDepth = 0;
|
|
82
|
-
|
|
83
|
-
this._clipping = false;
|
|
84
|
-
this._clipInvert = false;
|
|
85
|
-
|
|
86
|
-
this._currentShape = undefined; // Lazily generate current shape
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get currentShape() {
|
|
90
|
-
if (!this._currentShape) {
|
|
91
|
-
this._currentShape = new Shape(this.getCommonVertexProperties());
|
|
92
|
-
}
|
|
93
|
-
return this._currentShape;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
remove() {
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
pixelDensity(val){
|
|
101
|
-
let returnValue;
|
|
102
|
-
if (typeof val === 'number') {
|
|
103
|
-
if (val !== this._pixelDensity) {
|
|
104
|
-
this._pixelDensity = val;
|
|
105
|
-
}
|
|
106
|
-
returnValue = this;
|
|
107
|
-
this.resize(this.width, this.height);
|
|
108
|
-
} else {
|
|
109
|
-
returnValue = this._pixelDensity;
|
|
110
|
-
}
|
|
111
|
-
return returnValue;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Makes a shallow copy of the current states
|
|
115
|
-
// and push it into the push pop stack
|
|
116
|
-
push() {
|
|
117
|
-
this._pushPopDepth++;
|
|
118
|
-
this._pushPopStack.push(this.states.getDiff());
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Pop the previous states out of the push pop stack and
|
|
122
|
-
// assign it back to the current state
|
|
123
|
-
pop() {
|
|
124
|
-
this._pushPopDepth--;
|
|
125
|
-
const diff = this._pushPopStack.pop() || {};
|
|
126
|
-
const modified = this.states.getModified();
|
|
127
|
-
this.states.applyDiff(diff);
|
|
128
|
-
this.updateShapeVertexProperties(modified);
|
|
129
|
-
this.updateShapeProperties(modified);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
bezierOrder(order) {
|
|
133
|
-
if (order === undefined) {
|
|
134
|
-
return this.states.bezierOrder;
|
|
135
|
-
} else {
|
|
136
|
-
this.states.setValue('bezierOrder', order);
|
|
137
|
-
this.updateShapeProperties();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
bezierVertex(x, y, z = 0, u = 0, v = 0) {
|
|
142
|
-
const position = new Vector(x, y, z);
|
|
143
|
-
const textureCoordinates = this.getSupportedIndividualVertexProperties().textureCoordinates
|
|
144
|
-
? new Vector(u, v)
|
|
145
|
-
: undefined;
|
|
146
|
-
this.currentShape.bezierVertex(position, textureCoordinates);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
splineProperty(key, value) {
|
|
150
|
-
if (value === undefined) {
|
|
151
|
-
return this.states.splineProperties[key];
|
|
152
|
-
} else {
|
|
153
|
-
this.states.setValue('splineProperties', this.states.splineProperties.clone());
|
|
154
|
-
this.states.splineProperties[key] = value;
|
|
155
|
-
}
|
|
156
|
-
this.updateShapeProperties();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
splineProperties(values) {
|
|
160
|
-
if (values) {
|
|
161
|
-
for (const key in values) {
|
|
162
|
-
this.splineProperty(key, values[key]);
|
|
163
|
-
}
|
|
164
|
-
} else {
|
|
165
|
-
return { ...this.states.splineProperties };
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
splineVertex(x, y, z = 0, u = 0, v = 0) {
|
|
170
|
-
const position = new Vector(x, y, z);
|
|
171
|
-
const textureCoordinates = this.getSupportedIndividualVertexProperties().textureCoordinates
|
|
172
|
-
? new Vector(u, v)
|
|
173
|
-
: undefined;
|
|
174
|
-
this.currentShape.splineVertex(position, textureCoordinates);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
curveDetail(d) {
|
|
178
|
-
if (d === undefined) {
|
|
179
|
-
return this.states.curveDetail;
|
|
180
|
-
} else {
|
|
181
|
-
this.states.setValue('curveDetail', d);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
beginShape(...args) {
|
|
186
|
-
this.currentShape.reset();
|
|
187
|
-
this.updateShapeVertexProperties();
|
|
188
|
-
this.currentShape.beginShape(...args);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
endShape(...args) {
|
|
192
|
-
this.currentShape.endShape(...args);
|
|
193
|
-
this.drawShape(this.currentShape);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
beginContour(shapeKind) {
|
|
197
|
-
this.currentShape.beginContour(shapeKind);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
endContour(mode) {
|
|
201
|
-
this.currentShape.endContour(mode);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
drawShape(shape, count) {
|
|
205
|
-
throw new Error('Unimplemented')
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
vertex(x, y, z = 0, u = 0, v = 0) {
|
|
209
|
-
const position = new Vector(x, y, z);
|
|
210
|
-
const textureCoordinates = this.getSupportedIndividualVertexProperties().textureCoordinates
|
|
211
|
-
? new Vector(u, v)
|
|
212
|
-
: undefined;
|
|
213
|
-
this.currentShape.vertex(position, textureCoordinates);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
bezier(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
217
|
-
const oldOrder = this._pInst.bezierOrder();
|
|
218
|
-
this._pInst.bezierOrder(oldOrder);
|
|
219
|
-
this._pInst.beginShape();
|
|
220
|
-
this._pInst.bezierVertex(x1, y1);
|
|
221
|
-
this._pInst.bezierVertex(x2, y2);
|
|
222
|
-
this._pInst.bezierVertex(x3, y3);
|
|
223
|
-
this._pInst.bezierVertex(x4, y4);
|
|
224
|
-
this._pInst.endShape();
|
|
225
|
-
return this;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
spline(...args) {
|
|
229
|
-
if (args.length === 2 * 4) {
|
|
230
|
-
const [x1, y1, x2, y2, x3, y3, x4, y4] = args;
|
|
231
|
-
this._pInst.beginShape();
|
|
232
|
-
this._pInst.splineVertex(x1, y1);
|
|
233
|
-
this._pInst.splineVertex(x2, y2);
|
|
234
|
-
this._pInst.splineVertex(x3, y3);
|
|
235
|
-
this._pInst.splineVertex(x4, y4);
|
|
236
|
-
this._pInst.endShape();
|
|
237
|
-
} else if (args.length === 3 * 4) {
|
|
238
|
-
const [x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4] = args;
|
|
239
|
-
this._pInst.beginShape();
|
|
240
|
-
this._pInst.splineVertex(x1, y1, z1);
|
|
241
|
-
this._pInst.splineVertex(x2, y2, z2);
|
|
242
|
-
this._pInst.splineVertex(x3, y3, z3);
|
|
243
|
-
this._pInst.splineVertex(x4, y4, z4);
|
|
244
|
-
this._pInst.endShape();
|
|
245
|
-
}
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
beginClip(options = {}) {
|
|
250
|
-
if (this._clipping) {
|
|
251
|
-
throw new Error("It looks like you're trying to clip while already in the middle of clipping. Did you forget to endClip()?");
|
|
252
|
-
}
|
|
253
|
-
this._clipping = true;
|
|
254
|
-
this._clipInvert = options.invert;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
endClip() {
|
|
258
|
-
if (!this._clipping) {
|
|
259
|
-
throw new Error("It looks like you've called endClip() without beginClip(). Did you forget to call beginClip() first?");
|
|
260
|
-
}
|
|
261
|
-
this._clipping = false;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Resize our canvas element.
|
|
266
|
-
*/
|
|
267
|
-
resize(w, h) {
|
|
268
|
-
this.width = w;
|
|
269
|
-
this.height = h;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
get(x, y, w, h) {
|
|
273
|
-
const pd = this._pixelDensity;
|
|
274
|
-
const canvas = this.canvas;
|
|
275
|
-
|
|
276
|
-
if (typeof x === 'undefined' && typeof y === 'undefined') {
|
|
277
|
-
// get()
|
|
278
|
-
x = y = 0;
|
|
279
|
-
w = this.width;
|
|
280
|
-
h = this.height;
|
|
281
|
-
} else {
|
|
282
|
-
x *= pd;
|
|
283
|
-
y *= pd;
|
|
284
|
-
|
|
285
|
-
if (typeof w === 'undefined' && typeof h === 'undefined') {
|
|
286
|
-
// get(x,y)
|
|
287
|
-
if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) {
|
|
288
|
-
return [0, 0, 0, 0];
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return this._getPixel(x, y);
|
|
292
|
-
}
|
|
293
|
-
// get(x,y,w,h)
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const region = new Image(w*pd, h*pd);
|
|
297
|
-
region.pixelDensity(pd);
|
|
298
|
-
region.canvas
|
|
299
|
-
.getContext('2d')
|
|
300
|
-
.drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w*pd, h*pd);
|
|
301
|
-
|
|
302
|
-
return region;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
scale(x, y){
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
fill(...args) {
|
|
310
|
-
this.states.setValue('fillSet', true);
|
|
311
|
-
this.states.setValue('fillColor', this._pInst.color(...args));
|
|
312
|
-
this.updateShapeVertexProperties();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
noFill() {
|
|
316
|
-
this.states.setValue('fillColor', null);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
strokeWeight(w) {
|
|
320
|
-
if (w === undefined) {
|
|
321
|
-
return this.states.strokeWeight;
|
|
322
|
-
} else {
|
|
323
|
-
this.states.setValue('strokeWeight', w);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
stroke(...args) {
|
|
328
|
-
this.states.setValue('strokeSet', true);
|
|
329
|
-
this.states.setValue('strokeColor', this._pInst.color(...args));
|
|
330
|
-
this.updateShapeVertexProperties();
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
noStroke() {
|
|
334
|
-
this.states.setValue('strokeColor', null);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
getCommonVertexProperties() {
|
|
338
|
-
return {}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
getSupportedIndividualVertexProperties() {
|
|
342
|
-
return {
|
|
343
|
-
textureCoordinates: false,
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
updateShapeProperties(modified) {
|
|
348
|
-
if (!modified || modified.bezierOrder || modified.splineProperties) {
|
|
349
|
-
const shape = this.currentShape;
|
|
350
|
-
shape.bezierOrder(this.states.bezierOrder);
|
|
351
|
-
shape.splineProperty('ends', this.states.splineProperties.ends);
|
|
352
|
-
shape.splineProperty('tightness', this.states.splineProperties.tightness);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
updateShapeVertexProperties(modified) {
|
|
357
|
-
const props = this.getCommonVertexProperties();
|
|
358
|
-
if (!modified || Object.keys(modified).some((k) => k in props)) {
|
|
359
|
-
const shape = this.currentShape;
|
|
360
|
-
for (const key in props) {
|
|
361
|
-
shape[key](props[key]);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
_applyDefaults() {
|
|
367
|
-
return this;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
function renderer(p5, fn){
|
|
373
|
-
/**
|
|
374
|
-
* Main graphics and rendering context, as well as the base API
|
|
375
|
-
* implementation for p5.js "core". To be used as the superclass for
|
|
376
|
-
* Renderer2D and Renderer3D classes, respectively.
|
|
377
|
-
*
|
|
378
|
-
* @class p5.Renderer
|
|
379
|
-
* @param {HTMLElement} elt DOM node that is wrapped
|
|
380
|
-
* @param {p5} [pInst] pointer to p5 instance
|
|
381
|
-
* @param {Boolean} [isMainCanvas] whether we're using it as main canvas
|
|
382
|
-
* @private
|
|
383
|
-
*/
|
|
384
|
-
p5.Renderer = Renderer;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Helper fxn to measure ascent and descent.
|
|
389
|
-
* Adapted from http://stackoverflow.com/a/25355178
|
|
390
|
-
* @private
|
|
391
|
-
*/
|
|
392
|
-
function calculateOffset(object) {
|
|
393
|
-
let currentLeft = 0,
|
|
394
|
-
currentTop = 0;
|
|
395
|
-
if (object.offsetParent) {
|
|
396
|
-
do {
|
|
397
|
-
currentLeft += object.offsetLeft;
|
|
398
|
-
currentTop += object.offsetTop;
|
|
399
|
-
} while ((object = object.offsetParent));
|
|
400
|
-
} else {
|
|
401
|
-
currentLeft += object.offsetLeft;
|
|
402
|
-
currentTop += object.offsetTop;
|
|
403
|
-
}
|
|
404
|
-
return [currentLeft, currentTop];
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
export default renderer;
|
|
408
|
-
export { Renderer };
|