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.
Files changed (267) hide show
  1. package/{src → dist}/accessibility/color_namer.js +48 -3
  2. package/{src → dist}/accessibility/describe.js +12 -2
  3. package/{src → dist}/accessibility/gridOutput.js +2 -2
  4. package/dist/accessibility/index.js +60 -0
  5. package/{src → dist}/accessibility/outputs.js +23 -2
  6. package/{src → dist}/accessibility/textOutput.js +2 -2
  7. package/dist/app.js +120 -0
  8. package/{src → dist}/color/color_conversion.js +48 -10
  9. package/{src → dist}/color/color_spaces/hsb.js +3 -1
  10. package/dist/color/creating_reading.js +3 -0
  11. package/dist/color/index.js +13 -0
  12. package/dist/color/p5.Color.culori.js +1 -0
  13. package/dist/color/p5.Color.js +3 -0
  14. package/{src → dist}/color/setting.js +9 -6
  15. package/{src/core/constants.js → dist/constants-tYr0tCl8.js} +284 -132
  16. package/{src → dist}/core/States.js +3 -1
  17. package/dist/core/constants.js +1 -0
  18. package/{src → dist}/core/environment.js +12 -10
  19. package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
  20. package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
  21. package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
  22. package/dist/core/friendly_errors/index.js +23 -0
  23. package/dist/core/friendly_errors/param_validator.js +5421 -0
  24. package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
  25. package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
  26. package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
  27. package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
  28. package/{src → dist}/core/helpers.js +9 -6
  29. package/dist/core/init.js +105 -0
  30. package/dist/core/internationalization.js +302 -0
  31. package/dist/core/legacy.js +73 -0
  32. package/dist/core/main.js +44 -0
  33. package/dist/core/noop.js +3 -0
  34. package/dist/core/p5.Graphics.js +40 -0
  35. package/dist/core/p5.Renderer.js +11 -0
  36. package/dist/core/p5.Renderer2D.js +44 -0
  37. package/dist/core/reference.js +1 -0
  38. package/dist/core/rendering.js +40 -0
  39. package/{src → dist}/core/structure.js +3 -3
  40. package/{src → dist}/core/transform.js +2 -2
  41. package/{src/color/creating_reading.js → dist/creating_reading-Cr8L2Jnm.js} +841 -13
  42. package/{src → dist}/data/index.js +3 -1
  43. package/{src → dist}/data/local_storage.js +2 -8
  44. package/{src → dist}/dom/dom.js +19 -13
  45. package/dist/dom/index.js +18 -0
  46. package/{src → dist}/dom/p5.Element.js +14 -12
  47. package/{src → dist}/dom/p5.File.js +4 -4
  48. package/{src → dist}/dom/p5.MediaElement.js +10 -4
  49. package/{src → dist}/events/acceleration.js +26 -26
  50. package/{src → dist}/events/index.js +3 -1
  51. package/{src → dist}/events/keyboard.js +14 -12
  52. package/{src → dist}/events/pointer.js +16 -17
  53. package/dist/image/const.js +9 -0
  54. package/{src → dist}/image/filterRenderer2D.js +57 -37
  55. package/{src → dist}/image/filters.js +1 -3
  56. package/dist/image/image.js +40 -0
  57. package/dist/image/index.js +51 -0
  58. package/dist/image/loading_displaying.js +40 -0
  59. package/dist/image/p5.Image.js +11 -0
  60. package/{src → dist}/image/pixels.js +5 -3
  61. package/{src → dist}/io/csv.js +72 -70
  62. package/dist/io/files.js +40 -0
  63. package/dist/io/index.js +51 -0
  64. package/{src → dist}/io/p5.Table.js +6 -6
  65. package/{src → dist}/io/p5.TableRow.js +5 -6
  66. package/{src → dist}/io/p5.XML.js +2 -5
  67. package/{src → dist}/io/utilities.js +1 -1
  68. package/{src/core/p5.Renderer2D.js → dist/main-CAxvgiOV.js} +738 -57
  69. package/{src → dist}/math/Matrices/Matrix.js +10 -8
  70. package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
  71. package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
  72. package/{src → dist}/math/calculation.js +2 -2
  73. package/{src → dist}/math/index.js +6 -3
  74. package/{src → dist}/math/math.js +3 -3
  75. package/{src → dist}/math/noise.js +2 -2
  76. package/{src → dist}/math/p5.Matrix.js +7 -4
  77. package/{src → dist}/math/p5.Vector.js +6 -6
  78. package/{src → dist}/math/random.js +2 -2
  79. package/{src → dist}/math/trigonometry.js +16 -15
  80. package/{src/image/p5.Image.js → dist/p5.Renderer-Swjl9HQO.js} +393 -22
  81. package/dist/rendering-B5TRR7aY.js +24960 -0
  82. package/{src → dist}/shape/2d_primitives.js +18 -17
  83. package/{src → dist}/shape/attributes.js +18 -17
  84. package/{src → dist}/shape/curves.js +2 -2
  85. package/{src → dist}/shape/custom_shapes.js +44 -64
  86. package/{src → dist}/shape/index.js +10 -2
  87. package/{src → dist}/shape/vertex.js +2 -3
  88. package/dist/type/index.js +25 -0
  89. package/{src → dist}/type/lib/Typr.js +76 -94
  90. package/{src → dist}/type/p5.Font.js +37 -63
  91. package/{src → dist}/type/textCore.js +35 -58
  92. package/{src → dist}/type/unicodeRanges.js +3 -1
  93. package/{src → dist}/utilities/conversion.js +2 -2
  94. package/{src → dist}/utilities/index.js +3 -1
  95. package/{src → dist}/utilities/time_date.js +6 -7
  96. package/{src → dist}/utilities/utility_functions.js +2 -2
  97. package/dist/webgl/3d_primitives.js +40 -0
  98. package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
  99. package/{src → dist}/webgl/GeometryBuilder.js +12 -8
  100. package/{src → dist}/webgl/ShaderGenerator.js +79 -82
  101. package/{src → dist}/webgl/ShapeBuilder.js +26 -23
  102. package/dist/webgl/index.js +76 -0
  103. package/{src → dist}/webgl/interaction.js +7 -6
  104. package/dist/webgl/light.js +40 -0
  105. package/{src → dist}/webgl/loading.js +45 -12
  106. package/dist/webgl/material.js +40 -0
  107. package/dist/webgl/p5.Camera.js +40 -0
  108. package/{src → dist}/webgl/p5.DataArray.js +3 -5
  109. package/dist/webgl/p5.Framebuffer.js +40 -0
  110. package/{src → dist}/webgl/p5.Geometry.js +12 -15
  111. package/{src → dist}/webgl/p5.Quat.js +5 -4
  112. package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
  113. package/dist/webgl/p5.RendererGL.js +40 -0
  114. package/dist/webgl/p5.Shader.js +40 -0
  115. package/dist/webgl/p5.Texture.js +40 -0
  116. package/{src → dist}/webgl/text.js +78 -38
  117. package/lib/p5.esm.js +296 -194
  118. package/lib/p5.js +296 -194
  119. package/lib/p5.min.js +1 -1
  120. package/package.json +17 -17
  121. package/translations/dev.js +6 -6
  122. package/translations/index.js +1 -1
  123. package/types/accessibility/color_namer.d.ts +8 -0
  124. package/types/accessibility/describe.d.ts +184 -0
  125. package/types/accessibility/gridOutput.d.ts +8 -0
  126. package/types/accessibility/outputs.d.ts +235 -0
  127. package/types/accessibility/textOutput.d.ts +8 -0
  128. package/types/color/color_conversion.d.ts +47 -0
  129. package/types/color/creating_reading.d.ts +1348 -0
  130. package/types/color/p5.Color.d.ts +1070 -0
  131. package/types/color/setting.d.ts +2085 -0
  132. package/types/core/constants.d.ts +341 -0
  133. package/types/core/environment.d.ts +668 -0
  134. package/types/core/friendly_errors/fes_core.d.ts +8 -0
  135. package/types/core/friendly_errors/file_errors.d.ts +8 -0
  136. package/types/core/friendly_errors/param_validator.d.ts +30 -0
  137. package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
  138. package/types/core/friendly_errors/stacktrace.d.ts +11 -0
  139. package/types/core/friendly_errors/validate_params.d.ts +8 -0
  140. package/types/core/helpers.d.ts +8 -0
  141. package/types/core/legacy.d.ts +8 -0
  142. package/types/core/main.d.ts +5996 -0
  143. package/types/core/p5.Graphics.d.ts +484 -0
  144. package/types/core/p5.Renderer.d.ts +14 -0
  145. package/types/core/reference.d.ts +8 -0
  146. package/types/core/rendering.d.ts +481 -0
  147. package/types/core/structure.d.ts +492 -0
  148. package/types/core/transform.d.ts +1638 -0
  149. package/types/data/local_storage.d.ts +323 -0
  150. package/types/dom/dom.d.ts +1295 -0
  151. package/types/dom/p5.Element.d.ts +2011 -0
  152. package/types/dom/p5.File.d.ts +13 -0
  153. package/types/dom/p5.MediaElement.d.ts +1249 -0
  154. package/types/events/acceleration.d.ts +193 -0
  155. package/types/events/keyboard.d.ts +499 -0
  156. package/types/events/pointer.d.ts +782 -0
  157. package/types/global.d.ts +5542 -0
  158. package/types/image/filterRenderer2D.d.ts +54 -0
  159. package/types/image/image.d.ts +326 -0
  160. package/types/image/loading_displaying.d.ts +580 -0
  161. package/types/image/p5.Image.d.ts +5882 -0
  162. package/types/image/pixels.d.ts +832 -0
  163. package/types/io/files.d.ts +1447 -0
  164. package/types/io/p5.Table.d.ts +1247 -0
  165. package/types/io/p5.TableRow.d.ts +343 -0
  166. package/types/io/p5.XML.d.ts +1188 -0
  167. package/types/math/Matrices/Matrix.d.ts +1029 -0
  168. package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
  169. package/types/math/calculation.d.ts +923 -0
  170. package/types/math/math.d.ts +90 -0
  171. package/types/math/noise.d.ts +311 -0
  172. package/types/math/p5.Matrix.d.ts +8 -0
  173. package/types/math/p5.Vector.d.ts +3416 -0
  174. package/types/math/random.d.ts +267 -0
  175. package/types/math/trigonometry.d.ts +663 -0
  176. package/types/p5.d.ts +6663 -0
  177. package/types/shape/2d_primitives.d.ts +1033 -0
  178. package/types/shape/attributes.d.ts +466 -0
  179. package/types/shape/curves.d.ts +740 -0
  180. package/types/shape/custom_shapes.d.ts +888 -0
  181. package/types/shape/vertex.d.ts +1141 -0
  182. package/types/type/p5.Font.d.ts +575 -0
  183. package/types/type/textCore.d.ts +1198 -0
  184. package/types/utilities/conversion.d.ts +894 -0
  185. package/types/utilities/time_date.d.ts +295 -0
  186. package/types/utilities/utility_functions.d.ts +587 -0
  187. package/types/webgl/3d_primitives.d.ts +1432 -0
  188. package/types/webgl/ShaderGenerator.d.ts +8 -0
  189. package/types/webgl/interaction.d.ts +371 -0
  190. package/types/webgl/light.d.ts +1184 -0
  191. package/types/webgl/loading.d.ts +481 -0
  192. package/types/webgl/material.d.ts +2656 -0
  193. package/types/webgl/p5.Camera.d.ts +3023 -0
  194. package/types/webgl/p5.DataArray.d.ts +61 -0
  195. package/types/webgl/p5.Framebuffer.d.ts +760 -0
  196. package/types/webgl/p5.Geometry.d.ts +1191 -0
  197. package/types/webgl/p5.Quat.d.ts +45 -0
  198. package/types/webgl/p5.RendererGL.d.ts +234 -0
  199. package/types/webgl/p5.Shader.d.ts +660 -0
  200. package/types/webgl/p5.Texture.d.ts +61 -0
  201. package/types/webgl/text.d.ts +74 -0
  202. package/src/README.md +0 -27
  203. package/src/accessibility/index.js +0 -13
  204. package/src/app.js +0 -61
  205. package/src/color/index.js +0 -9
  206. package/src/color/p5.Color.culori.js +0 -66
  207. package/src/color/p5.Color.js +0 -851
  208. package/src/core/README.md +0 -91
  209. package/src/core/friendly_errors/index.js +0 -13
  210. package/src/core/friendly_errors/param_validator.js +0 -561
  211. package/src/core/init.js +0 -58
  212. package/src/core/internationalization.js +0 -195
  213. package/src/core/legacy.js +0 -29
  214. package/src/core/main.js +0 -689
  215. package/src/core/noop.js +0 -1
  216. package/src/core/p5.Graphics.js +0 -696
  217. package/src/core/p5.Renderer.js +0 -408
  218. package/src/core/reference.js +0 -2060
  219. package/src/core/rendering.js +0 -697
  220. package/src/dom/index.js +0 -11
  221. package/src/image/const.js +0 -6
  222. package/src/image/image.js +0 -731
  223. package/src/image/index.js +0 -15
  224. package/src/image/loading_displaying.js +0 -1431
  225. package/src/io/files.js +0 -2210
  226. package/src/io/index.js +0 -11
  227. package/src/math/README.md +0 -40
  228. package/src/type/index.js +0 -9
  229. package/src/webgl/3d_primitives.js +0 -2741
  230. package/src/webgl/index.js +0 -37
  231. package/src/webgl/light.js +0 -1851
  232. package/src/webgl/material.js +0 -3854
  233. package/src/webgl/p5.Camera.js +0 -4010
  234. package/src/webgl/p5.Framebuffer.js +0 -1865
  235. package/src/webgl/p5.RendererGL.js +0 -2867
  236. package/src/webgl/p5.Shader.js +0 -1505
  237. package/src/webgl/p5.Texture.js +0 -541
  238. package/src/webgl/shaders/basic.frag +0 -6
  239. package/src/webgl/shaders/filters/base.frag +0 -22
  240. package/src/webgl/shaders/filters/base.vert +0 -19
  241. package/src/webgl/shaders/filters/blur.frag +0 -60
  242. package/src/webgl/shaders/filters/default.vert +0 -18
  243. package/src/webgl/shaders/filters/dilate.frag +0 -39
  244. package/src/webgl/shaders/filters/erode.frag +0 -39
  245. package/src/webgl/shaders/filters/gray.frag +0 -16
  246. package/src/webgl/shaders/filters/invert.frag +0 -15
  247. package/src/webgl/shaders/filters/opaque.frag +0 -12
  248. package/src/webgl/shaders/filters/posterize.frag +0 -29
  249. package/src/webgl/shaders/filters/threshold.frag +0 -23
  250. package/src/webgl/shaders/font.frag +0 -216
  251. package/src/webgl/shaders/font.vert +0 -44
  252. package/src/webgl/shaders/imageLight.vert +0 -33
  253. package/src/webgl/shaders/imageLightDiffused.frag +0 -82
  254. package/src/webgl/shaders/imageLightSpecular.frag +0 -134
  255. package/src/webgl/shaders/light.vert +0 -37
  256. package/src/webgl/shaders/light_texture.frag +0 -26
  257. package/src/webgl/shaders/lighting.glsl +0 -227
  258. package/src/webgl/shaders/line.frag +0 -74
  259. package/src/webgl/shaders/line.vert +0 -294
  260. package/src/webgl/shaders/normal.frag +0 -6
  261. package/src/webgl/shaders/normal.vert +0 -72
  262. package/src/webgl/shaders/phong.frag +0 -84
  263. package/src/webgl/shaders/phong.vert +0 -87
  264. package/src/webgl/shaders/point.frag +0 -29
  265. package/src/webgl/shaders/point.vert +0 -19
  266. package/src/webgl/shaders/sphereMapping.frag +0 -26
  267. package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
@@ -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 };