p5 2.0.1 → 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/dist/accessibility/color_namer.js +5 -5
- package/dist/accessibility/describe.js +10 -0
- package/dist/accessibility/index.js +5 -5
- package/dist/accessibility/outputs.js +21 -0
- package/dist/app.js +5 -5
- package/dist/color/color_conversion.js +5 -5
- package/dist/color/creating_reading.js +1 -1
- package/dist/color/index.js +2 -2
- package/dist/color/p5.Color.js +1 -1
- package/dist/color/setting.js +2 -2
- package/dist/{constants-C-g_eAdC.js → constants-tYr0tCl8.js} +19 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +6 -5
- package/dist/core/friendly_errors/fes_core.js +1 -1
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +41 -75
- package/dist/core/friendly_errors/sketch_reader.js +5 -5
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/friendly_errors/validate_params.js +5 -5
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +5 -5
- package/dist/core/legacy.js +5 -5
- package/dist/core/main.js +5 -5
- package/dist/core/p5.Graphics.js +4 -4
- package/dist/core/p5.Renderer.js +3 -3
- package/dist/core/p5.Renderer2D.js +5 -5
- package/dist/core/rendering.js +4 -4
- package/dist/{creating_reading-D4AAKRbx.js → creating_reading-Cr8L2Jnm.js} +2 -2
- package/dist/dom/dom.js +10 -10
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +2 -2
- package/dist/dom/p5.MediaElement.js +2 -2
- package/dist/events/acceleration.js +24 -24
- package/dist/events/keyboard.js +1 -2
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +4 -4
- package/dist/image/image.js +4 -4
- package/dist/image/index.js +4 -4
- package/dist/image/loading_displaying.js +4 -4
- package/dist/image/p5.Image.js +3 -3
- package/dist/image/pixels.js +1 -0
- package/dist/io/files.js +4 -4
- package/dist/io/index.js +4 -4
- package/dist/io/p5.TableRow.js +2 -2
- package/dist/{main-s72KWcUy.js → main-CAxvgiOV.js} +12 -9
- 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/math.js +1 -1
- package/dist/math/p5.Matrix.js +1 -1
- package/dist/math/p5.Vector.js +1 -1
- package/dist/math/trigonometry.js +1 -1
- package/dist/{p5.Renderer-CwAYZOC2.js → p5.Renderer-Swjl9HQO.js} +5 -5
- package/dist/{rendering--aAe5aq3.js → rendering-B5TRR7aY.js} +101 -66
- package/dist/shape/2d_primitives.js +1 -1
- package/dist/shape/attributes.js +1 -1
- package/dist/shape/custom_shapes.js +2 -2
- package/dist/shape/index.js +2 -2
- package/dist/type/index.js +3 -3
- package/dist/type/p5.Font.js +3 -5
- package/dist/type/textCore.js +4 -4
- package/dist/webgl/3d_primitives.js +4 -4
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +1 -1
- package/dist/webgl/index.js +4 -4
- package/dist/webgl/interaction.js +1 -1
- package/dist/webgl/light.js +4 -4
- package/dist/webgl/loading.js +4 -4
- package/dist/webgl/material.js +4 -4
- package/dist/webgl/p5.Camera.js +4 -4
- package/dist/webgl/p5.Framebuffer.js +4 -4
- package/dist/webgl/p5.Geometry.js +1 -1
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +4 -4
- package/dist/webgl/p5.Shader.js +4 -4
- package/dist/webgl/p5.Texture.js +4 -4
- package/dist/webgl/text.js +32 -34
- package/lib/p5.esm.js +273 -225
- package/lib/p5.js +273 -225
- package/lib/p5.min.js +1 -1
- package/package.json +1 -2
- 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
|
@@ -0,0 +1,832 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
import { Color } from '../color/p5.Color';
|
|
5
|
+
|
|
6
|
+
declare module 'p5' {
|
|
7
|
+
/**
|
|
8
|
+
* An array containing the color of each pixel on the canvas.Colors are stored as numbers representing red, green, blue, and alpha
|
|
9
|
+
* (RGBA) values. `pixels` is a one-dimensional array for performance reasons.Each pixel occupies four elements in the `pixels` array, one for each RGBA
|
|
10
|
+
* value. For example, the pixel at coordinates (0, 0) stores its RGBA values
|
|
11
|
+
* at `pixels[0]`, `pixels[1]`, `pixels[2]`, and `pixels[3]`, respectively.
|
|
12
|
+
* The next pixel at coordinates (1, 0) stores its RGBA values at `pixels[4]`,
|
|
13
|
+
* `pixels[5]`, `pixels[6]`, and `pixels[7]`. And so on. The `pixels` array
|
|
14
|
+
* for a 100×100 canvas has 100 × 100 × 4 = 40,000 elements.Some displays use several smaller pixels to set the color at a single
|
|
15
|
+
* point. The pixelDensity() function returns
|
|
16
|
+
* the pixel density of the canvas. High density displays often have a
|
|
17
|
+
* pixelDensity() of 2. On such a display, the
|
|
18
|
+
* `pixels` array for a 100×100 canvas has 200 × 200 × 4 =
|
|
19
|
+
* 160,000 elements.Accessing the RGBA values for a point on the canvas requires a little math
|
|
20
|
+
* as shown below. The loadPixels() function
|
|
21
|
+
* must be called before accessing the `pixels` array. The
|
|
22
|
+
* updatePixels() function must be called
|
|
23
|
+
* after any changes are made.
|
|
24
|
+
*
|
|
25
|
+
* @example <div>
|
|
26
|
+
* <code>
|
|
27
|
+
* function setup() {
|
|
28
|
+
* createCanvas(100, 100);
|
|
29
|
+
* background(128);
|
|
30
|
+
*
|
|
31
|
+
* // Load the pixels array.
|
|
32
|
+
* loadPixels();
|
|
33
|
+
*
|
|
34
|
+
* // Set the dot's coordinates.
|
|
35
|
+
* let x = 50;
|
|
36
|
+
* let y = 50;
|
|
37
|
+
*
|
|
38
|
+
* // Get the pixel density.
|
|
39
|
+
* let d = pixelDensity();
|
|
40
|
+
*
|
|
41
|
+
* // Set the pixel(s) at the center of the canvas black.
|
|
42
|
+
* for (let i = 0; i < d; i += 1) {
|
|
43
|
+
* for (let j = 0; j < d; j += 1) {
|
|
44
|
+
* let index = 4 * ((y * d + j) * width * d + (x * d + i));
|
|
45
|
+
* // Red.
|
|
46
|
+
* pixels[index] = 0;
|
|
47
|
+
* // Green.
|
|
48
|
+
* pixels[index + 1] = 0;
|
|
49
|
+
* // Blue.
|
|
50
|
+
* pixels[index + 2] = 0;
|
|
51
|
+
* // Alpha.
|
|
52
|
+
* pixels[index + 3] = 255;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* // Update the canvas.
|
|
57
|
+
* updatePixels();
|
|
58
|
+
*
|
|
59
|
+
* describe('A black dot in the middle of a gray rectangle.');
|
|
60
|
+
* }
|
|
61
|
+
* </code>
|
|
62
|
+
* </div>
|
|
63
|
+
*
|
|
64
|
+
* <div>
|
|
65
|
+
* <code>
|
|
66
|
+
* function setup() {
|
|
67
|
+
* createCanvas(100, 100);
|
|
68
|
+
*
|
|
69
|
+
* // Load the pixels array.
|
|
70
|
+
* loadPixels();
|
|
71
|
+
*
|
|
72
|
+
* // Get the pixel density.
|
|
73
|
+
* let d = pixelDensity();
|
|
74
|
+
*
|
|
75
|
+
* // Calculate the halfway index in the pixels array.
|
|
76
|
+
* let halfImage = 4 * (d * width) * (d * height / 2);
|
|
77
|
+
*
|
|
78
|
+
* // Make the top half of the canvas red.
|
|
79
|
+
* for (let i = 0; i < halfImage; i += 4) {
|
|
80
|
+
* // Red.
|
|
81
|
+
* pixels[i] = 255;
|
|
82
|
+
* // Green.
|
|
83
|
+
* pixels[i + 1] = 0;
|
|
84
|
+
* // Blue.
|
|
85
|
+
* pixels[i + 2] = 0;
|
|
86
|
+
* // Alpha.
|
|
87
|
+
* pixels[i + 3] = 255;
|
|
88
|
+
* }
|
|
89
|
+
*
|
|
90
|
+
* // Update the canvas.
|
|
91
|
+
* updatePixels();
|
|
92
|
+
*
|
|
93
|
+
* describe('A red rectangle drawn above a gray rectangle.');
|
|
94
|
+
* }
|
|
95
|
+
* </code>
|
|
96
|
+
* </div>
|
|
97
|
+
*
|
|
98
|
+
* <div>
|
|
99
|
+
* <code>
|
|
100
|
+
* function setup() {
|
|
101
|
+
* createCanvas(100, 100);
|
|
102
|
+
*
|
|
103
|
+
* // Create a p5.Color object.
|
|
104
|
+
* let pink = color(255, 102, 204);
|
|
105
|
+
*
|
|
106
|
+
* // Load the pixels array.
|
|
107
|
+
* loadPixels();
|
|
108
|
+
*
|
|
109
|
+
* // Get the pixel density.
|
|
110
|
+
* let d = pixelDensity();
|
|
111
|
+
*
|
|
112
|
+
* // Calculate the halfway index in the pixels array.
|
|
113
|
+
* let halfImage = 4 * (d * width) * (d * height / 2);
|
|
114
|
+
*
|
|
115
|
+
* // Make the top half of the canvas red.
|
|
116
|
+
* for (let i = 0; i < halfImage; i += 4) {
|
|
117
|
+
* pixels[i] = red(pink);
|
|
118
|
+
* pixels[i + 1] = green(pink);
|
|
119
|
+
* pixels[i + 2] = blue(pink);
|
|
120
|
+
* pixels[i + 3] = alpha(pink);
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* // Update the canvas.
|
|
124
|
+
* updatePixels();
|
|
125
|
+
*
|
|
126
|
+
* describe('A pink rectangle drawn above a gray rectangle.');
|
|
127
|
+
* }
|
|
128
|
+
* </code>
|
|
129
|
+
* </div>
|
|
130
|
+
*/
|
|
131
|
+
function blend(...args: any[]): void;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Copies a region of pixels from one image to another.The first parameter, `srcImage`, is the
|
|
135
|
+
* p5.Image object to blend.The next four parameters, `sx`, `sy`, `sw`, and `sh` determine the region
|
|
136
|
+
* to blend from the source image. `(sx, sy)` is the top-left corner of the
|
|
137
|
+
* region. `sw` and `sh` are the regions width and height.The next four parameters, `dx`, `dy`, `dw`, and `dh` determine the region
|
|
138
|
+
* of the canvas to blend into. `(dx, dy)` is the top-left corner of the
|
|
139
|
+
* region. `dw` and `dh` are the regions width and height.The tenth parameter, `blendMode`, sets the effect used to blend the images'
|
|
140
|
+
* colors. The options are `BLEND`, `DARKEST`, `LIGHTEST`, `DIFFERENCE`,
|
|
141
|
+
* `MULTIPLY`, `EXCLUSION`, `SCREEN`, `REPLACE`, `OVERLAY`, `HARD_LIGHT`,
|
|
142
|
+
* `SOFT_LIGHT`, `DODGE`, `BURN`, `ADD`, or `NORMAL`
|
|
143
|
+
*
|
|
144
|
+
* @param source image.
|
|
145
|
+
* @param x-coordinate of the source's upper-left corner.
|
|
146
|
+
* @param y-coordinate of the source's upper-left corner.
|
|
147
|
+
* @param source image width.
|
|
148
|
+
* @param source image height.
|
|
149
|
+
* @param x-coordinate of the destination's upper-left corner.
|
|
150
|
+
* @param y-coordinate of the destination's upper-left corner.
|
|
151
|
+
* @param destination image width.
|
|
152
|
+
* @param destination image height.
|
|
153
|
+
* @param the blend mode. either
|
|
154
|
+
* BLEND, DARKEST, LIGHTEST, DIFFERENCE,
|
|
155
|
+
* MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,
|
|
156
|
+
* SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.
|
|
157
|
+
* @example <div>
|
|
158
|
+
* <code>
|
|
159
|
+
* let img0;
|
|
160
|
+
* let img1;
|
|
161
|
+
*
|
|
162
|
+
* async function setup() {
|
|
163
|
+
* // Load the images.
|
|
164
|
+
* img0 = await loadImage('assets/rockies.jpg');
|
|
165
|
+
* img1 = await loadImage('assets/bricks_third.jpg');
|
|
166
|
+
*
|
|
167
|
+
* createCanvas(100, 100);
|
|
168
|
+
*
|
|
169
|
+
* // Use the mountains as the background.
|
|
170
|
+
* background(img0);
|
|
171
|
+
*
|
|
172
|
+
* // Display the bricks.
|
|
173
|
+
* image(img1, 0, 0);
|
|
174
|
+
*
|
|
175
|
+
* // Display the bricks faded into the landscape.
|
|
176
|
+
* blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
|
|
177
|
+
*
|
|
178
|
+
* describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears faded on the right of the image.');
|
|
179
|
+
* }
|
|
180
|
+
* </code>
|
|
181
|
+
* </div>
|
|
182
|
+
*
|
|
183
|
+
* <div>
|
|
184
|
+
* <code>
|
|
185
|
+
* let img0;
|
|
186
|
+
* let img1;
|
|
187
|
+
*
|
|
188
|
+
* async function setup() {
|
|
189
|
+
* // Load the images.
|
|
190
|
+
* img0 = await loadImage('assets/rockies.jpg');
|
|
191
|
+
* img1 = await loadImage('assets/bricks_third.jpg');
|
|
192
|
+
*
|
|
193
|
+
* createCanvas(100, 100);
|
|
194
|
+
*
|
|
195
|
+
* // Use the mountains as the background.
|
|
196
|
+
* background(img0);
|
|
197
|
+
*
|
|
198
|
+
* // Display the bricks.
|
|
199
|
+
* image(img1, 0, 0);
|
|
200
|
+
*
|
|
201
|
+
* // Display the bricks partially transparent.
|
|
202
|
+
* blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
|
|
203
|
+
*
|
|
204
|
+
* describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears transparent on the right of the image.');
|
|
205
|
+
* }
|
|
206
|
+
* </code>
|
|
207
|
+
* </div>
|
|
208
|
+
*
|
|
209
|
+
* <div>
|
|
210
|
+
* <code>
|
|
211
|
+
* let img0;
|
|
212
|
+
* let img1;
|
|
213
|
+
*
|
|
214
|
+
* async function setup() {
|
|
215
|
+
* // Load the images.
|
|
216
|
+
* img0 = await loadImage('assets/rockies.jpg');
|
|
217
|
+
* img1 = await loadImage('assets/bricks_third.jpg');
|
|
218
|
+
*
|
|
219
|
+
* createCanvas(100, 100);
|
|
220
|
+
*
|
|
221
|
+
* // Use the mountains as the background.
|
|
222
|
+
* background(img0);
|
|
223
|
+
*
|
|
224
|
+
* // Display the bricks.
|
|
225
|
+
* image(img1, 0, 0);
|
|
226
|
+
*
|
|
227
|
+
* // Display the bricks washed out into the landscape.
|
|
228
|
+
* blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
|
|
229
|
+
*
|
|
230
|
+
* describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears washed out on the right of the image.');
|
|
231
|
+
* }
|
|
232
|
+
* </code>
|
|
233
|
+
* </div>
|
|
234
|
+
*/
|
|
235
|
+
function blend(srcImage: p5.Image, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number, blendMode: BLEND | DARKEST | LIGHTEST | DIFFERENCE | MULTIPLY | EXCLUSION | SCREEN | REPLACE | OVERLAY | HARD_LIGHT | SOFT_LIGHT | DODGE | BURN | ADD | NORMAL): void;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
*/
|
|
239
|
+
function blend(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number, blendMode: BLEND | DARKEST | LIGHTEST | DIFFERENCE | MULTIPLY | EXCLUSION | SCREEN | REPLACE | OVERLAY | HARD_LIGHT | SOFT_LIGHT | DODGE | BURN | ADD | NORMAL): void;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Copies pixels from a source image to a region of the canvas.The first parameter, `srcImage`, is the
|
|
243
|
+
* p5.Image object to blend. The source image can be
|
|
244
|
+
* the canvas itself or a
|
|
245
|
+
* p5.Image object. `copy()` will scale pixels from
|
|
246
|
+
* the source region if it isn't the same size as the destination region.The next four parameters, `sx`, `sy`, `sw`, and `sh` determine the region
|
|
247
|
+
* to copy from the source image. `(sx, sy)` is the top-left corner of the
|
|
248
|
+
* region. `sw` and `sh` are the region's width and height.The next four parameters, `dx`, `dy`, `dw`, and `dh` determine the region
|
|
249
|
+
* of the canvas to copy into. `(dx, dy)` is the top-left corner of the
|
|
250
|
+
* region. `dw` and `dh` are the region's width and height.
|
|
251
|
+
*
|
|
252
|
+
* @param source image.
|
|
253
|
+
* @param x-coordinate of the source's upper-left corner.
|
|
254
|
+
* @param y-coordinate of the source's upper-left corner.
|
|
255
|
+
* @param source image width.
|
|
256
|
+
* @param source image height.
|
|
257
|
+
* @param x-coordinate of the destination's upper-left corner.
|
|
258
|
+
* @param y-coordinate of the destination's upper-left corner.
|
|
259
|
+
* @param destination image width.
|
|
260
|
+
* @param destination image height.
|
|
261
|
+
* @example <div>
|
|
262
|
+
* <code>
|
|
263
|
+
* let img;
|
|
264
|
+
*
|
|
265
|
+
* async function setup() {
|
|
266
|
+
* // Load the image.
|
|
267
|
+
* img = await loadImage('assets/rockies.jpg');
|
|
268
|
+
*
|
|
269
|
+
* createCanvas(100, 100);
|
|
270
|
+
*
|
|
271
|
+
* // Use the mountains as the background.
|
|
272
|
+
* background(img);
|
|
273
|
+
*
|
|
274
|
+
* // Copy a region of pixels to another spot.
|
|
275
|
+
* copy(img, 7, 22, 10, 10, 35, 25, 50, 50);
|
|
276
|
+
*
|
|
277
|
+
* // Outline the copied region.
|
|
278
|
+
* stroke(255);
|
|
279
|
+
* noFill();
|
|
280
|
+
* square(7, 22, 10);
|
|
281
|
+
*
|
|
282
|
+
* describe('An image of a mountain landscape. A square region is outlined in white. A larger square contains a pixelated view of the outlined region.');
|
|
283
|
+
* }
|
|
284
|
+
* </code>
|
|
285
|
+
* </div>
|
|
286
|
+
*/
|
|
287
|
+
function copy(srcImage: p5.Image | p5.Element, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
*/
|
|
291
|
+
function copy(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Applies an image filter to the canvas.The preset options are:`INVERT`
|
|
295
|
+
* Inverts the colors in the image. No parameter is used.`GRAY`
|
|
296
|
+
* Converts the image to grayscale. No parameter is used.`THRESHOLD`
|
|
297
|
+
* Converts the image to black and white. Pixels with a grayscale value
|
|
298
|
+
* above a given threshold are converted to white. The rest are converted to
|
|
299
|
+
* black. The threshold must be between 0.0 (black) and 1.0 (white). If no
|
|
300
|
+
* value is specified, 0.5 is used.`OPAQUE`
|
|
301
|
+
* Sets the alpha channel to entirely opaque. No parameter is used.`POSTERIZE`
|
|
302
|
+
* Limits the number of colors in the image. Each color channel is limited to
|
|
303
|
+
* the number of colors specified. Values between 2 and 255 are valid, but
|
|
304
|
+
* results are most noticeable with lower values. The default value is 4.`BLUR`
|
|
305
|
+
* Blurs the image. The level of blurring is specified by a blur radius. Larger
|
|
306
|
+
* values increase the blur. The default value is 4. A gaussian blur is used
|
|
307
|
+
* in `P2D` mode. A box blur is used in `WEBGL` mode.`ERODE`
|
|
308
|
+
* Reduces the light areas. No parameter is used.`DILATE`
|
|
309
|
+
* Increases the light areas. No parameter is used.`filter()` uses WebGL in the background by default because it's faster.
|
|
310
|
+
* This can be disabled in `P2D` mode by adding a `false` argument, as in
|
|
311
|
+
* `filter(BLUR, false)`. This may be useful to keep computation off the GPU
|
|
312
|
+
* or to work around a lack of WebGL support.In WebgL mode, `filter()` can also use custom shaders. See
|
|
313
|
+
* createFilterShader() for more
|
|
314
|
+
* information.
|
|
315
|
+
*
|
|
316
|
+
* @param either THRESHOLD, GRAY, OPAQUE, INVERT,
|
|
317
|
+
* POSTERIZE, BLUR, ERODE, DILATE or BLUR.
|
|
318
|
+
* @param parameter unique to each filter.
|
|
319
|
+
* @param flag to control whether to use fast
|
|
320
|
+
* WebGL filters (GPU) or original image
|
|
321
|
+
* filters (CPU); defaults to `true`.
|
|
322
|
+
* @example <div>
|
|
323
|
+
* <code>
|
|
324
|
+
* let img;
|
|
325
|
+
*
|
|
326
|
+
* async function setup() {
|
|
327
|
+
* // Load the image.
|
|
328
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
329
|
+
*
|
|
330
|
+
* createCanvas(100, 100);
|
|
331
|
+
*
|
|
332
|
+
* // Display the image.
|
|
333
|
+
* image(img, 0, 0);
|
|
334
|
+
*
|
|
335
|
+
* // Apply the INVERT filter.
|
|
336
|
+
* filter(INVERT);
|
|
337
|
+
*
|
|
338
|
+
* describe('A blue brick wall.');
|
|
339
|
+
* }
|
|
340
|
+
* </code>
|
|
341
|
+
* </div>
|
|
342
|
+
*
|
|
343
|
+
* <div>
|
|
344
|
+
* <code>
|
|
345
|
+
* let img;
|
|
346
|
+
*
|
|
347
|
+
* async function setup() {
|
|
348
|
+
* // Load the image.
|
|
349
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
350
|
+
*
|
|
351
|
+
* createCanvas(100, 100);
|
|
352
|
+
*
|
|
353
|
+
* // Display the image.
|
|
354
|
+
* image(img, 0, 0);
|
|
355
|
+
*
|
|
356
|
+
* // Apply the GRAY filter.
|
|
357
|
+
* filter(GRAY);
|
|
358
|
+
*
|
|
359
|
+
* describe('A brick wall drawn in grayscale.');
|
|
360
|
+
* }
|
|
361
|
+
* </code>
|
|
362
|
+
* </div>
|
|
363
|
+
*
|
|
364
|
+
* <div>
|
|
365
|
+
* <code>
|
|
366
|
+
* let img;
|
|
367
|
+
*
|
|
368
|
+
* async function setup() {
|
|
369
|
+
* // Load the image.
|
|
370
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
371
|
+
*
|
|
372
|
+
* createCanvas(100, 100);
|
|
373
|
+
*
|
|
374
|
+
* // Display the image.
|
|
375
|
+
* image(img, 0, 0);
|
|
376
|
+
*
|
|
377
|
+
* // Apply the THRESHOLD filter.
|
|
378
|
+
* filter(THRESHOLD);
|
|
379
|
+
*
|
|
380
|
+
* describe('A brick wall drawn in black and white.');
|
|
381
|
+
* }
|
|
382
|
+
* </code>
|
|
383
|
+
* </div>
|
|
384
|
+
*
|
|
385
|
+
* <div>
|
|
386
|
+
* <code>
|
|
387
|
+
* let img;
|
|
388
|
+
*
|
|
389
|
+
* async function setup() {
|
|
390
|
+
* // Load the image.
|
|
391
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
392
|
+
*
|
|
393
|
+
* createCanvas(100, 100);
|
|
394
|
+
*
|
|
395
|
+
* // Display the image.
|
|
396
|
+
* image(img, 0, 0);
|
|
397
|
+
*
|
|
398
|
+
* // Apply the OPAQUE filter.
|
|
399
|
+
* filter(OPAQUE);
|
|
400
|
+
*
|
|
401
|
+
* describe('A red brick wall.');
|
|
402
|
+
* }
|
|
403
|
+
* </code>
|
|
404
|
+
* </div>
|
|
405
|
+
*
|
|
406
|
+
* <div>
|
|
407
|
+
* <code>
|
|
408
|
+
* let img;
|
|
409
|
+
*
|
|
410
|
+
* async function setup() {
|
|
411
|
+
* // Load the image.
|
|
412
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
413
|
+
*
|
|
414
|
+
* createCanvas(100, 100);
|
|
415
|
+
*
|
|
416
|
+
* // Display the image.
|
|
417
|
+
* image(img, 0, 0);
|
|
418
|
+
*
|
|
419
|
+
* // Apply the POSTERIZE filter.
|
|
420
|
+
* filter(POSTERIZE, 3);
|
|
421
|
+
*
|
|
422
|
+
* describe('An image of a red brick wall drawn with limited color palette.');
|
|
423
|
+
* }
|
|
424
|
+
* </code>
|
|
425
|
+
* </div>
|
|
426
|
+
*
|
|
427
|
+
* <div>
|
|
428
|
+
* <code>
|
|
429
|
+
* let img;
|
|
430
|
+
*
|
|
431
|
+
* async function setup() {
|
|
432
|
+
* // Load the image.
|
|
433
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
434
|
+
*
|
|
435
|
+
* createCanvas(100, 100);
|
|
436
|
+
*
|
|
437
|
+
* // Display the image.
|
|
438
|
+
* image(img, 0, 0);
|
|
439
|
+
*
|
|
440
|
+
* // Apply the BLUR filter.
|
|
441
|
+
* filter(BLUR, 3);
|
|
442
|
+
*
|
|
443
|
+
* describe('A blurry image of a red brick wall.');
|
|
444
|
+
* }
|
|
445
|
+
* </code>
|
|
446
|
+
* </div>
|
|
447
|
+
*
|
|
448
|
+
* <div>
|
|
449
|
+
* <code>
|
|
450
|
+
* let img;
|
|
451
|
+
*
|
|
452
|
+
* async function setup() {
|
|
453
|
+
* // Load the image.
|
|
454
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
455
|
+
*
|
|
456
|
+
* createCanvas(100, 100);
|
|
457
|
+
*
|
|
458
|
+
* // Display the image.
|
|
459
|
+
* image(img, 0, 0);
|
|
460
|
+
*
|
|
461
|
+
* // Apply the DILATE filter.
|
|
462
|
+
* filter(DILATE);
|
|
463
|
+
*
|
|
464
|
+
* describe('A red brick wall with bright lines between each brick.');
|
|
465
|
+
* }
|
|
466
|
+
* </code>
|
|
467
|
+
* </div>
|
|
468
|
+
*
|
|
469
|
+
* <div>
|
|
470
|
+
* <code>
|
|
471
|
+
* let img;
|
|
472
|
+
*
|
|
473
|
+
* async function setup() {
|
|
474
|
+
* // Load the image.
|
|
475
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
476
|
+
*
|
|
477
|
+
* createCanvas(100, 100);
|
|
478
|
+
*
|
|
479
|
+
* // Display the image.
|
|
480
|
+
* image(img, 0, 0);
|
|
481
|
+
*
|
|
482
|
+
* // Apply the ERODE filter.
|
|
483
|
+
* filter(ERODE);
|
|
484
|
+
*
|
|
485
|
+
* describe('A red brick wall with faint lines between each brick.');
|
|
486
|
+
* }
|
|
487
|
+
* </code>
|
|
488
|
+
* </div>
|
|
489
|
+
*
|
|
490
|
+
* <div>
|
|
491
|
+
* <code>
|
|
492
|
+
* let img;
|
|
493
|
+
*
|
|
494
|
+
* async function setup() {
|
|
495
|
+
* // Load the image.
|
|
496
|
+
* img = await loadImage('assets/bricks.jpg');
|
|
497
|
+
*
|
|
498
|
+
* createCanvas(100, 100);
|
|
499
|
+
*
|
|
500
|
+
* // Display the image.
|
|
501
|
+
* image(img, 0, 0);
|
|
502
|
+
*
|
|
503
|
+
* // Apply the BLUR filter.
|
|
504
|
+
* // Don't use WebGL.
|
|
505
|
+
* filter(BLUR, 3, false);
|
|
506
|
+
*
|
|
507
|
+
* describe('A blurry image of a red brick wall.');
|
|
508
|
+
* }
|
|
509
|
+
* </code>
|
|
510
|
+
* </div>
|
|
511
|
+
*/
|
|
512
|
+
function filter(filterType: THRESHOLD | GRAY | OPAQUE | INVERT | POSTERIZE | BLUR | ERODE | DILATE | BLUR, filterParam?: number, useWebGL: boolean): void;
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
*/
|
|
516
|
+
function filter(filterType: THRESHOLD | GRAY | OPAQUE | INVERT | POSTERIZE | BLUR | ERODE | DILATE | BLUR, filterParam?: number, useWebGL: boolean): void;
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* @param shader that's been loaded, with the
|
|
520
|
+
* frag shader using a `tex0` uniform.
|
|
521
|
+
*/
|
|
522
|
+
function filter(shaderFilter: p5.Shader): void;
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Gets a pixel or a region of pixels from the canvas.`get()` is easy to use but it's not as fast as
|
|
526
|
+
* pixels. Use pixels
|
|
527
|
+
* to read many pixel values.The version of `get()` with no parameters returns the entire canvas.The version of `get()` with two parameters interprets them as
|
|
528
|
+
* coordinates. It returns an array with the `[R, G, B, A]` values of the
|
|
529
|
+
* pixel at the given point.The version of `get()` with four parameters interprets them as coordinates
|
|
530
|
+
* and dimensions. It returns a subsection of the canvas as a
|
|
531
|
+
* p5.Image object. The first two parameters are the
|
|
532
|
+
* coordinates for the upper-left corner of the subsection. The last two
|
|
533
|
+
* parameters are the width and height of the subsection.Use p5.Image.get() to work directly with
|
|
534
|
+
* p5.Image objects.
|
|
535
|
+
*
|
|
536
|
+
* @param x-coordinate of the pixel.
|
|
537
|
+
* @param y-coordinate of the pixel.
|
|
538
|
+
* @param width of the subsection to be returned.
|
|
539
|
+
* @param height of the subsection to be returned.
|
|
540
|
+
* @return subsection as a <a href="#/p5.Image">p5.Image</a> object.
|
|
541
|
+
* @example <div>
|
|
542
|
+
* <code>
|
|
543
|
+
* let img;
|
|
544
|
+
*
|
|
545
|
+
* async function setup() {
|
|
546
|
+
* // Load the image.
|
|
547
|
+
* img = await loadImage('assets/rockies.jpg');
|
|
548
|
+
*
|
|
549
|
+
* createCanvas(100, 100);
|
|
550
|
+
*
|
|
551
|
+
* // Display the image.
|
|
552
|
+
* image(img, 0, 0);
|
|
553
|
+
*
|
|
554
|
+
* // Get the entire canvas.
|
|
555
|
+
* let c = get();
|
|
556
|
+
*
|
|
557
|
+
* // Display half the canvas.
|
|
558
|
+
* image(c, 50, 0);
|
|
559
|
+
*
|
|
560
|
+
* describe('Two identical mountain landscapes shown side-by-side.');
|
|
561
|
+
* }
|
|
562
|
+
* </code>
|
|
563
|
+
* </div>
|
|
564
|
+
*
|
|
565
|
+
* <div>
|
|
566
|
+
* <code>
|
|
567
|
+
* let img;
|
|
568
|
+
*
|
|
569
|
+
* async function setup() {
|
|
570
|
+
* // Load the image.
|
|
571
|
+
* img = await loadImage('assets/rockies.jpg');
|
|
572
|
+
*
|
|
573
|
+
* createCanvas(100, 100);
|
|
574
|
+
*
|
|
575
|
+
* // Display the image.
|
|
576
|
+
* image(img, 0, 0);
|
|
577
|
+
*
|
|
578
|
+
* // Get the color of a pixel.
|
|
579
|
+
* let c = get(50, 90);
|
|
580
|
+
*
|
|
581
|
+
* // Style the square with the pixel's color.
|
|
582
|
+
* fill(c);
|
|
583
|
+
* noStroke();
|
|
584
|
+
*
|
|
585
|
+
* // Display the square.
|
|
586
|
+
* square(25, 25, 50);
|
|
587
|
+
*
|
|
588
|
+
* describe('A mountain landscape with an olive green square in its center.');
|
|
589
|
+
* }
|
|
590
|
+
* </code>
|
|
591
|
+
* </div>
|
|
592
|
+
*
|
|
593
|
+
* <div>
|
|
594
|
+
* <code>
|
|
595
|
+
* let img;
|
|
596
|
+
*
|
|
597
|
+
* async function setup() {
|
|
598
|
+
* // Load the image.
|
|
599
|
+
* img = await loadImage('assets/rockies.jpg');
|
|
600
|
+
*
|
|
601
|
+
* createCanvas(100, 100);
|
|
602
|
+
*
|
|
603
|
+
* // Display the image.
|
|
604
|
+
* image(img, 0, 0);
|
|
605
|
+
*
|
|
606
|
+
* // Get a region of the image.
|
|
607
|
+
* let c = get(0, 0, 50, 50);
|
|
608
|
+
*
|
|
609
|
+
* // Display the region.
|
|
610
|
+
* image(c, 50, 50);
|
|
611
|
+
*
|
|
612
|
+
* describe('A mountain landscape drawn on top of another mountain landscape.');
|
|
613
|
+
* }
|
|
614
|
+
* </code>
|
|
615
|
+
* </div>
|
|
616
|
+
*/
|
|
617
|
+
function get(x: number, y: number, w: number, h: number): p5.Image;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* @return whole canvas as a <a href="#/p5.Image">p5.Image</a>.
|
|
621
|
+
*/
|
|
622
|
+
function get(): p5.Image;
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* @return color of the pixel at (x, y) in array format `[R, G, B, A]`.
|
|
626
|
+
*/
|
|
627
|
+
function get(x: number, y: number): number[];
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Loads the current value of each pixel on the canvas into the
|
|
631
|
+
* pixels array.`loadPixels()` must be called before reading from or writing to
|
|
632
|
+
* pixels.
|
|
633
|
+
*
|
|
634
|
+
* @example <div>
|
|
635
|
+
* <code>
|
|
636
|
+
* let img;
|
|
637
|
+
*
|
|
638
|
+
* async function setup() {
|
|
639
|
+
* // Load the image.
|
|
640
|
+
* img = await loadImage('assets/rockies.jpg');
|
|
641
|
+
*
|
|
642
|
+
* createCanvas(100, 100);
|
|
643
|
+
*
|
|
644
|
+
* // Display the image.
|
|
645
|
+
* image(img, 0, 0, 100, 100);
|
|
646
|
+
*
|
|
647
|
+
* // Get the pixel density.
|
|
648
|
+
* let d = pixelDensity();
|
|
649
|
+
*
|
|
650
|
+
* // Calculate the halfway index in the pixels array.
|
|
651
|
+
* let halfImage = 4 * (d * width) * (d * height / 2);
|
|
652
|
+
*
|
|
653
|
+
* // Load the pixels array.
|
|
654
|
+
* loadPixels();
|
|
655
|
+
*
|
|
656
|
+
* // Copy the top half of the canvas to the bottom.
|
|
657
|
+
* for (let i = 0; i < halfImage; i += 1) {
|
|
658
|
+
* pixels[i + halfImage] = pixels[i];
|
|
659
|
+
* }
|
|
660
|
+
*
|
|
661
|
+
* // Update the canvas.
|
|
662
|
+
* updatePixels();
|
|
663
|
+
*
|
|
664
|
+
* describe('Two identical images of mountain landscapes, one on top of the other.');
|
|
665
|
+
* }
|
|
666
|
+
* </code>
|
|
667
|
+
* </div>
|
|
668
|
+
*/
|
|
669
|
+
function loadPixels(): void;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Sets the color of a pixel or draws an image to the canvas.`set()` is easy to use but it's not as fast as
|
|
673
|
+
* pixels. Use pixels
|
|
674
|
+
* to set many pixel values.`set()` interprets the first two parameters as x- and y-coordinates. It
|
|
675
|
+
* interprets the last parameter as a grayscale value, a `[R, G, B, A]` pixel
|
|
676
|
+
* array, a p5.Color object, or a
|
|
677
|
+
* p5.Image object. If an image is passed, the first
|
|
678
|
+
* two parameters set the coordinates for the image's upper-left corner,
|
|
679
|
+
* regardless of the current imageMode().updatePixels() must be called after using
|
|
680
|
+
* `set()` for changes to appear.
|
|
681
|
+
*
|
|
682
|
+
* @param x-coordinate of the pixel.
|
|
683
|
+
* @param y-coordinate of the pixel.
|
|
684
|
+
* @param grayscale value | pixel array |
|
|
685
|
+
* <a href="#/p5.Color">p5.Color</a> object | <a href="#/p5.Image">p5.Image</a> to copy.
|
|
686
|
+
* @example <div>
|
|
687
|
+
* <code>
|
|
688
|
+
* function setup() {
|
|
689
|
+
* createCanvas(100, 100);
|
|
690
|
+
*
|
|
691
|
+
* background(200);
|
|
692
|
+
*
|
|
693
|
+
* // Set four pixels to black.
|
|
694
|
+
* set(30, 20, 0);
|
|
695
|
+
* set(85, 20, 0);
|
|
696
|
+
* set(85, 75, 0);
|
|
697
|
+
* set(30, 75, 0);
|
|
698
|
+
*
|
|
699
|
+
* // Update the canvas.
|
|
700
|
+
* updatePixels();
|
|
701
|
+
*
|
|
702
|
+
* describe('Four black dots arranged in a square drawn on a gray background.');
|
|
703
|
+
* }
|
|
704
|
+
* </code>
|
|
705
|
+
* </div>
|
|
706
|
+
*
|
|
707
|
+
* <div>
|
|
708
|
+
* <code>
|
|
709
|
+
* function setup() {
|
|
710
|
+
* createCanvas(100, 100);
|
|
711
|
+
*
|
|
712
|
+
* background(200);
|
|
713
|
+
*
|
|
714
|
+
* // Create a p5.Color object.
|
|
715
|
+
* let black = color(0);
|
|
716
|
+
*
|
|
717
|
+
* // Set four pixels to black.
|
|
718
|
+
* set(30, 20, black);
|
|
719
|
+
* set(85, 20, black);
|
|
720
|
+
* set(85, 75, black);
|
|
721
|
+
* set(30, 75, black);
|
|
722
|
+
*
|
|
723
|
+
* // Update the canvas.
|
|
724
|
+
* updatePixels();
|
|
725
|
+
*
|
|
726
|
+
* describe('Four black dots arranged in a square drawn on a gray background.');
|
|
727
|
+
* }
|
|
728
|
+
* </code>
|
|
729
|
+
* </div>
|
|
730
|
+
*
|
|
731
|
+
* <div>
|
|
732
|
+
* <code>
|
|
733
|
+
* function setup() {
|
|
734
|
+
* createCanvas(100, 100);
|
|
735
|
+
*
|
|
736
|
+
* background(255);
|
|
737
|
+
*
|
|
738
|
+
* // Draw a horizontal color gradient.
|
|
739
|
+
* for (let x = 0; x < 100; x += 1) {
|
|
740
|
+
* for (let y = 0; y < 100; y += 1) {
|
|
741
|
+
* // Calculate the grayscale value.
|
|
742
|
+
* let c = map(x, 0, 100, 0, 255);
|
|
743
|
+
*
|
|
744
|
+
* // Set the pixel using the grayscale value.
|
|
745
|
+
* set(x, y, c);
|
|
746
|
+
* }
|
|
747
|
+
* }
|
|
748
|
+
*
|
|
749
|
+
* // Update the canvas.
|
|
750
|
+
* updatePixels();
|
|
751
|
+
*
|
|
752
|
+
* describe('A horiztonal color gradient from black to white.');
|
|
753
|
+
* }
|
|
754
|
+
* </code>
|
|
755
|
+
* </div>
|
|
756
|
+
*
|
|
757
|
+
* <div>
|
|
758
|
+
* <code>
|
|
759
|
+
* let img;
|
|
760
|
+
*
|
|
761
|
+
* async function setup() {
|
|
762
|
+
* // Load the image.
|
|
763
|
+
* img = await loadImage('assets/rockies.jpg');
|
|
764
|
+
*
|
|
765
|
+
* createCanvas(100, 100);
|
|
766
|
+
*
|
|
767
|
+
* // Use the image to set all pixels.
|
|
768
|
+
* set(0, 0, img);
|
|
769
|
+
*
|
|
770
|
+
* // Update the canvas.
|
|
771
|
+
* updatePixels();
|
|
772
|
+
*
|
|
773
|
+
* describe('An image of a mountain landscape.');
|
|
774
|
+
* }
|
|
775
|
+
* </code>
|
|
776
|
+
* </div>
|
|
777
|
+
*/
|
|
778
|
+
function set(x: number, y: number, c: number | number[] | object): void;
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Updates the canvas with the RGBA values in the
|
|
782
|
+
* pixels array.`updatePixels()` only needs to be called after changing values in the
|
|
783
|
+
* pixels array. Such changes can be made directly
|
|
784
|
+
* after calling loadPixels() or by calling
|
|
785
|
+
* set().
|
|
786
|
+
*
|
|
787
|
+
* @param x-coordinate of the upper-left corner of region
|
|
788
|
+
* to update.
|
|
789
|
+
* @param y-coordinate of the upper-left corner of region
|
|
790
|
+
* to update.
|
|
791
|
+
* @param width of region to update.
|
|
792
|
+
* @param height of region to update.
|
|
793
|
+
* @example <div>
|
|
794
|
+
* <code>
|
|
795
|
+
* let img;
|
|
796
|
+
*
|
|
797
|
+
* async function setup() {
|
|
798
|
+
* // Load the image.
|
|
799
|
+
* img = await loadImage('assets/rockies.jpg');
|
|
800
|
+
*
|
|
801
|
+
* createCanvas(100, 100);
|
|
802
|
+
*
|
|
803
|
+
* // Display the image.
|
|
804
|
+
* image(img, 0, 0, 100, 100);
|
|
805
|
+
*
|
|
806
|
+
* // Get the pixel density.
|
|
807
|
+
* let d = pixelDensity();
|
|
808
|
+
*
|
|
809
|
+
* // Calculate the halfway index in the pixels array.
|
|
810
|
+
* let halfImage = 4 * (d * width) * (d * height / 2);
|
|
811
|
+
*
|
|
812
|
+
* // Load the pixels array.
|
|
813
|
+
* loadPixels();
|
|
814
|
+
*
|
|
815
|
+
* // Copy the top half of the canvas to the bottom.
|
|
816
|
+
* for (let i = 0; i < halfImage; i += 1) {
|
|
817
|
+
* pixels[i + halfImage] = pixels[i];
|
|
818
|
+
* }
|
|
819
|
+
*
|
|
820
|
+
* // Update the canvas.
|
|
821
|
+
* updatePixels();
|
|
822
|
+
*
|
|
823
|
+
* describe('Two identical images of mountain landscapes, one on top of the other.');
|
|
824
|
+
* }
|
|
825
|
+
* </code>
|
|
826
|
+
* </div>
|
|
827
|
+
*/
|
|
828
|
+
function updatePixels(x?: number, y?: number, w?: number, h?: number): void;
|
|
829
|
+
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
export default function pixels(p5: any, fn: any): void;
|