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
|
@@ -0,0 +1,760 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
|
|
5
|
+
declare module 'p5' {
|
|
6
|
+
class Framebuffer {
|
|
7
|
+
constructor(target: p5.Graphics | p5, settings?: object);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Resizes the framebuffer to a given width and height.The parameters, `width` and `height`, set the dimensions of the
|
|
11
|
+
* framebuffer. For example, calling `myBuffer.resize(300, 500)` resizes
|
|
12
|
+
* the framebuffer to 300×500 pixels, then sets `myBuffer.width` to 300
|
|
13
|
+
* and `myBuffer.height` 500.
|
|
14
|
+
*
|
|
15
|
+
* @param
|
|
16
|
+
* @param
|
|
17
|
+
*/
|
|
18
|
+
resize(width: number, height: number): void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Sets the framebuffer's pixel density or returns its current density.Computer displays are grids of little lights called pixels. A display's
|
|
22
|
+
* pixel density describes how many pixels it packs into an area. Displays
|
|
23
|
+
* with smaller pixels have a higher pixel density and create sharper
|
|
24
|
+
* images.The parameter, `density`, is optional. If a number is passed, as in
|
|
25
|
+
* `myBuffer.pixelDensity(1)`, it sets the framebuffer's pixel density. By
|
|
26
|
+
* default, the framebuffer's pixel density will match that of the canvas
|
|
27
|
+
* where it was created. All canvases default to match the display's pixel
|
|
28
|
+
* density.Calling `myBuffer.pixelDensity()` without an argument returns its current
|
|
29
|
+
* pixel density.
|
|
30
|
+
*
|
|
31
|
+
* @param
|
|
32
|
+
*/
|
|
33
|
+
pixelDensity(density: number): number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Toggles the framebuffer's autosizing mode or returns the current mode.By default, the framebuffer automatically resizes to match the canvas
|
|
37
|
+
* that created it. Calling `myBuffer.autoSized(false)` disables this
|
|
38
|
+
* behavior and calling `myBuffer.autoSized(true)` re-enables it.Calling `myBuffer.autoSized()` without an argument returns `true` if
|
|
39
|
+
* the framebuffer automatically resizes and `false` if not.
|
|
40
|
+
*
|
|
41
|
+
* @param
|
|
42
|
+
*/
|
|
43
|
+
autoSized(autoSized: boolean): boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new
|
|
47
|
+
* p5.Camera object to use with the framebuffer.The new camera is initialized with a default position `(0, 0, 800)` and a
|
|
48
|
+
* default perspective projection. Its properties can be controlled with
|
|
49
|
+
* p5.Camera methods such as `myCamera.lookAt(0, 0, 0)`.Framebuffer cameras should be created between calls to
|
|
50
|
+
* myBuffer.begin() and
|
|
51
|
+
* myBuffer.end() like so:`let myCamera;
|
|
52
|
+
*
|
|
53
|
+
* myBuffer.begin();
|
|
54
|
+
*
|
|
55
|
+
* // Create the camera for the framebuffer.
|
|
56
|
+
* myCamera = myBuffer.createCamera();
|
|
57
|
+
*
|
|
58
|
+
* myBuffer.end();`Calling setCamera() updates the
|
|
59
|
+
* framebuffer's projection using the camera.
|
|
60
|
+
* resetMatrix() must also be called for the
|
|
61
|
+
* view to change properly:`myBuffer.begin();
|
|
62
|
+
*
|
|
63
|
+
* // Set the camera for the framebuffer.
|
|
64
|
+
* setCamera(myCamera);
|
|
65
|
+
*
|
|
66
|
+
* // Reset all transformations.
|
|
67
|
+
* resetMatrix();
|
|
68
|
+
*
|
|
69
|
+
* // Draw stuff...
|
|
70
|
+
*
|
|
71
|
+
* myBuffer.end();`
|
|
72
|
+
*/
|
|
73
|
+
createCamera(): p5.Camera;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Deletes the framebuffer from GPU memory.Calling `myBuffer.remove()` frees the GPU memory used by the framebuffer.
|
|
77
|
+
* The framebuffer also uses a bit of memory on the CPU which can be freed
|
|
78
|
+
* like so:`// Delete the framebuffer from GPU memory.
|
|
79
|
+
* myBuffer.remove();
|
|
80
|
+
*
|
|
81
|
+
* // Delete the framebuffer from CPU memory.
|
|
82
|
+
* myBuffer = undefined;`Note: All variables that reference the framebuffer must be assigned
|
|
83
|
+
* the value `undefined` to delete the framebuffer from CPU memory. If any
|
|
84
|
+
* variable still refers to the framebuffer, then it won't be garbage
|
|
85
|
+
* collected.
|
|
86
|
+
*/
|
|
87
|
+
remove(): void;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Begins drawing shapes to the framebuffer.`myBuffer.begin()` and myBuffer.end()
|
|
91
|
+
* allow shapes to be drawn to the framebuffer. `myBuffer.begin()` begins
|
|
92
|
+
* drawing to the framebuffer and
|
|
93
|
+
* myBuffer.end() stops drawing to the
|
|
94
|
+
* framebuffer. Changes won't be visible until the framebuffer is displayed
|
|
95
|
+
* as an image or texture.
|
|
96
|
+
*/
|
|
97
|
+
begin(): void;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Stops drawing shapes to the framebuffer.myBuffer.begin() and `myBuffer.end()`
|
|
101
|
+
* allow shapes to be drawn to the framebuffer.
|
|
102
|
+
* myBuffer.begin() begins drawing to
|
|
103
|
+
* the framebuffer and `myBuffer.end()` stops drawing to the framebuffer.
|
|
104
|
+
* Changes won't be visible until the framebuffer is displayed as an image
|
|
105
|
+
* or texture.
|
|
106
|
+
*/
|
|
107
|
+
end(): void;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Draws to the framebuffer by calling a function that contains drawing
|
|
111
|
+
* instructions.The parameter, `callback`, is a function with the drawing instructions
|
|
112
|
+
* for the framebuffer. For example, calling `myBuffer.draw(myFunction)`
|
|
113
|
+
* will call a function named `myFunction()` to draw to the framebuffer.
|
|
114
|
+
* Doing so has the same effect as the following:`myBuffer.begin();
|
|
115
|
+
* myFunction();
|
|
116
|
+
* myBuffer.end();`
|
|
117
|
+
*
|
|
118
|
+
* @param
|
|
119
|
+
*/
|
|
120
|
+
draw(callback: Function): void;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Gets a pixel or a region of pixels from the framebuffer.`myBuffer.get()` is easy to use but it's not as fast as
|
|
124
|
+
* myBuffer.pixels. Use
|
|
125
|
+
* myBuffer.pixels to read many pixel
|
|
126
|
+
* values.The version of `myBuffer.get()` with no parameters returns the entire
|
|
127
|
+
* framebuffer as a a p5.Image object.The version of `myBuffer.get()` with two parameters interprets them as
|
|
128
|
+
* coordinates. It returns an array with the `[R, G, B, A]` values of the
|
|
129
|
+
* pixel at the given point.The version of `myBuffer.get()` with four parameters interprets them as
|
|
130
|
+
* coordinates and dimensions. It returns a subsection of the framebuffer as
|
|
131
|
+
* a p5.Image object. The first two parameters are
|
|
132
|
+
* the coordinates for the upper-left corner of the subsection. The last two
|
|
133
|
+
* parameters are the width and height of the subsection.
|
|
134
|
+
*
|
|
135
|
+
* @param
|
|
136
|
+
* @param
|
|
137
|
+
* @param
|
|
138
|
+
* @param
|
|
139
|
+
*/
|
|
140
|
+
get(x: number, y: number, w: number, h: number): p5.Image;
|
|
141
|
+
|
|
142
|
+
get(x: any, y: any, w: any, h: any): p5.Image;
|
|
143
|
+
|
|
144
|
+
get(x: number, y: number, w: any, h: any): number[];
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Loads the current value of each pixel in the framebuffer into its
|
|
150
|
+
* pixels array.`myBuffer.loadPixels()` must be called before reading from or writing to
|
|
151
|
+
* myBuffer.pixels.
|
|
152
|
+
*
|
|
153
|
+
* @example <div>
|
|
154
|
+
* <code>
|
|
155
|
+
* function setup() {
|
|
156
|
+
* createCanvas(100, 100, WEBGL);
|
|
157
|
+
*
|
|
158
|
+
* background(200);
|
|
159
|
+
*
|
|
160
|
+
* // Create a p5.Framebuffer object.
|
|
161
|
+
* let myBuffer = createFramebuffer();
|
|
162
|
+
*
|
|
163
|
+
* // Load the pixels array.
|
|
164
|
+
* myBuffer.loadPixels();
|
|
165
|
+
*
|
|
166
|
+
* // Get the number of pixels in the
|
|
167
|
+
* // top half of the framebuffer.
|
|
168
|
+
* let numPixels = myBuffer.pixels.length / 2;
|
|
169
|
+
*
|
|
170
|
+
* // Set the framebuffer's top half to pink.
|
|
171
|
+
* for (let i = 0; i < numPixels; i += 4) {
|
|
172
|
+
* myBuffer.pixels[i] = 255;
|
|
173
|
+
* myBuffer.pixels[i + 1] = 102;
|
|
174
|
+
* myBuffer.pixels[i + 2] = 204;
|
|
175
|
+
* myBuffer.pixels[i + 3] = 255;
|
|
176
|
+
* }
|
|
177
|
+
*
|
|
178
|
+
* // Update the pixels array.
|
|
179
|
+
* myBuffer.updatePixels();
|
|
180
|
+
*
|
|
181
|
+
* // Draw the p5.Framebuffer object to the canvas.
|
|
182
|
+
* image(myBuffer, -50, -50);
|
|
183
|
+
*
|
|
184
|
+
* describe('A pink rectangle above a gray rectangle.');
|
|
185
|
+
* }
|
|
186
|
+
* </code>
|
|
187
|
+
* </div>
|
|
188
|
+
*/
|
|
189
|
+
function loadPixels(): void;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Updates the framebuffer with the RGBA values in the
|
|
193
|
+
* pixels array.`myBuffer.updatePixels()` only needs to be called after changing values
|
|
194
|
+
* in the myBuffer.pixels array. Such
|
|
195
|
+
* changes can be made directly after calling
|
|
196
|
+
* myBuffer.loadPixels().
|
|
197
|
+
*
|
|
198
|
+
* @example <div>
|
|
199
|
+
* <code>
|
|
200
|
+
* function setup() {
|
|
201
|
+
* createCanvas(100, 100, WEBGL);
|
|
202
|
+
*
|
|
203
|
+
* background(200);
|
|
204
|
+
*
|
|
205
|
+
* // Create a p5.Framebuffer object.
|
|
206
|
+
* let myBuffer = createFramebuffer();
|
|
207
|
+
*
|
|
208
|
+
* // Load the pixels array.
|
|
209
|
+
* myBuffer.loadPixels();
|
|
210
|
+
*
|
|
211
|
+
* // Get the number of pixels in the
|
|
212
|
+
* // top half of the framebuffer.
|
|
213
|
+
* let numPixels = myBuffer.pixels.length / 2;
|
|
214
|
+
*
|
|
215
|
+
* // Set the framebuffer's top half to pink.
|
|
216
|
+
* for (let i = 0; i < numPixels; i += 4) {
|
|
217
|
+
* myBuffer.pixels[i] = 255;
|
|
218
|
+
* myBuffer.pixels[i + 1] = 102;
|
|
219
|
+
* myBuffer.pixels[i + 2] = 204;
|
|
220
|
+
* myBuffer.pixels[i + 3] = 255;
|
|
221
|
+
* }
|
|
222
|
+
*
|
|
223
|
+
* // Update the pixels array.
|
|
224
|
+
* myBuffer.updatePixels();
|
|
225
|
+
*
|
|
226
|
+
* // Draw the p5.Framebuffer object to the canvas.
|
|
227
|
+
* image(myBuffer, -50, -50);
|
|
228
|
+
*
|
|
229
|
+
* describe('A pink rectangle above a gray rectangle.');
|
|
230
|
+
* }
|
|
231
|
+
* </code>
|
|
232
|
+
* </div>
|
|
233
|
+
*/
|
|
234
|
+
function updatePixels(): void;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Resizes the framebuffer to a given width and height.The parameters, `width` and `height`, set the dimensions of the
|
|
238
|
+
* framebuffer. For example, calling `myBuffer.resize(300, 500)` resizes
|
|
239
|
+
* the framebuffer to 300×500 pixels, then sets `myBuffer.width` to 300
|
|
240
|
+
* and `myBuffer.height` 500.
|
|
241
|
+
*
|
|
242
|
+
* @param width of the framebuffer.
|
|
243
|
+
* @param height of the framebuffer.
|
|
244
|
+
* @example <div>
|
|
245
|
+
* <code>
|
|
246
|
+
* let myBuffer;
|
|
247
|
+
*
|
|
248
|
+
* function setup() {
|
|
249
|
+
* createCanvas(100, 100, WEBGL);
|
|
250
|
+
*
|
|
251
|
+
* // Create a p5.Framebuffer object.
|
|
252
|
+
* myBuffer = createFramebuffer();
|
|
253
|
+
*
|
|
254
|
+
* describe('A multicolor sphere on a white surface. The image grows larger or smaller when the user moves the mouse, revealing a gray background.');
|
|
255
|
+
* }
|
|
256
|
+
*
|
|
257
|
+
* function draw() {
|
|
258
|
+
* background(200);
|
|
259
|
+
*
|
|
260
|
+
* // Draw to the p5.Framebuffer object.
|
|
261
|
+
* myBuffer.begin();
|
|
262
|
+
* background(255);
|
|
263
|
+
* normalMaterial();
|
|
264
|
+
* sphere(20);
|
|
265
|
+
* myBuffer.end();
|
|
266
|
+
*
|
|
267
|
+
* // Display the p5.Framebuffer object.
|
|
268
|
+
* image(myBuffer, -50, -50);
|
|
269
|
+
* }
|
|
270
|
+
*
|
|
271
|
+
* // Resize the p5.Framebuffer object when the
|
|
272
|
+
* // user moves the mouse.
|
|
273
|
+
* function mouseMoved() {
|
|
274
|
+
* myBuffer.resize(mouseX, mouseY);
|
|
275
|
+
* }
|
|
276
|
+
* </code>
|
|
277
|
+
* </div>
|
|
278
|
+
*/
|
|
279
|
+
function resize(width: number, height: number): void;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Sets the framebuffer's pixel density or returns its current density.Computer displays are grids of little lights called pixels. A display's
|
|
283
|
+
* pixel density describes how many pixels it packs into an area. Displays
|
|
284
|
+
* with smaller pixels have a higher pixel density and create sharper
|
|
285
|
+
* images.The parameter, `density`, is optional. If a number is passed, as in
|
|
286
|
+
* `myBuffer.pixelDensity(1)`, it sets the framebuffer's pixel density. By
|
|
287
|
+
* default, the framebuffer's pixel density will match that of the canvas
|
|
288
|
+
* where it was created. All canvases default to match the display's pixel
|
|
289
|
+
* density.Calling `myBuffer.pixelDensity()` without an argument returns its current
|
|
290
|
+
* pixel density.
|
|
291
|
+
*
|
|
292
|
+
* @param pixel density to set.
|
|
293
|
+
* @returns current pixel density.
|
|
294
|
+
* @example <div>
|
|
295
|
+
* <code>
|
|
296
|
+
* let myBuffer;
|
|
297
|
+
*
|
|
298
|
+
* function setup() {
|
|
299
|
+
* createCanvas(100, 100, WEBGL);
|
|
300
|
+
*
|
|
301
|
+
* // Create a p5.Framebuffer object.
|
|
302
|
+
* myBuffer = createFramebuffer();
|
|
303
|
+
*
|
|
304
|
+
* describe("A white circle on a gray canvas. The circle's edge become fuzzy while the user presses and holds the mouse.");
|
|
305
|
+
* }
|
|
306
|
+
*
|
|
307
|
+
* function draw() {
|
|
308
|
+
* // Draw to the p5.Framebuffer object.
|
|
309
|
+
* myBuffer.begin();
|
|
310
|
+
* background(200);
|
|
311
|
+
* circle(0, 0, 40);
|
|
312
|
+
* myBuffer.end();
|
|
313
|
+
*
|
|
314
|
+
* // Display the p5.Framebuffer object.
|
|
315
|
+
* image(myBuffer, -50, -50);
|
|
316
|
+
* }
|
|
317
|
+
*
|
|
318
|
+
* // Decrease the pixel density when the user
|
|
319
|
+
* // presses the mouse.
|
|
320
|
+
* function mousePressed() {
|
|
321
|
+
* myBuffer.pixelDensity(1);
|
|
322
|
+
* }
|
|
323
|
+
*
|
|
324
|
+
* // Increase the pixel density when the user
|
|
325
|
+
* // releases the mouse.
|
|
326
|
+
* function mouseReleased() {
|
|
327
|
+
* myBuffer.pixelDensity(2);
|
|
328
|
+
* }
|
|
329
|
+
* </code>
|
|
330
|
+
* </div>
|
|
331
|
+
*
|
|
332
|
+
* <div>
|
|
333
|
+
* <code>
|
|
334
|
+
* let myBuffer;
|
|
335
|
+
* let myFont;
|
|
336
|
+
*
|
|
337
|
+
* async function setup() {
|
|
338
|
+
* // Load a font and create a p5.Font object.
|
|
339
|
+
* myFont = await loadFont('assets/inconsolata.otf');
|
|
340
|
+
*
|
|
341
|
+
* createCanvas(100, 100, WEBGL);
|
|
342
|
+
*
|
|
343
|
+
* background(200);
|
|
344
|
+
*
|
|
345
|
+
* // Create a p5.Framebuffer object.
|
|
346
|
+
* myBuffer = createFramebuffer();
|
|
347
|
+
*
|
|
348
|
+
* // Get the p5.Framebuffer object's pixel density.
|
|
349
|
+
* let d = myBuffer.pixelDensity();
|
|
350
|
+
*
|
|
351
|
+
* // Style the text.
|
|
352
|
+
* textAlign(CENTER, CENTER);
|
|
353
|
+
* textFont(myFont);
|
|
354
|
+
* textSize(16);
|
|
355
|
+
* fill(0);
|
|
356
|
+
*
|
|
357
|
+
* // Display the pixel density.
|
|
358
|
+
* text(`Density: ${d}`, 0, 0);
|
|
359
|
+
*
|
|
360
|
+
* describe(`The text "Density: ${d}" written in black on a gray background.`);
|
|
361
|
+
* }
|
|
362
|
+
* </code>
|
|
363
|
+
* </div>
|
|
364
|
+
*/
|
|
365
|
+
function pixelDensity(density?: number): number;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Toggles the framebuffer's autosizing mode or returns the current mode.By default, the framebuffer automatically resizes to match the canvas
|
|
369
|
+
* that created it. Calling `myBuffer.autoSized(false)` disables this
|
|
370
|
+
* behavior and calling `myBuffer.autoSized(true)` re-enables it.Calling `myBuffer.autoSized()` without an argument returns `true` if
|
|
371
|
+
* the framebuffer automatically resizes and `false` if not.
|
|
372
|
+
*
|
|
373
|
+
* @param whether to automatically resize the framebuffer to match the canvas.
|
|
374
|
+
* @returns current autosize setting.
|
|
375
|
+
* @example <div>
|
|
376
|
+
* <code>
|
|
377
|
+
* // Double-click to toggle the autosizing mode.
|
|
378
|
+
*
|
|
379
|
+
* let myBuffer;
|
|
380
|
+
*
|
|
381
|
+
* function setup() {
|
|
382
|
+
* createCanvas(100, 100, WEBGL);
|
|
383
|
+
*
|
|
384
|
+
* // Create a p5.Framebuffer object.
|
|
385
|
+
* myBuffer = createFramebuffer();
|
|
386
|
+
*
|
|
387
|
+
* describe('A multicolor sphere on a gray background. The image resizes when the user moves the mouse.');
|
|
388
|
+
* }
|
|
389
|
+
*
|
|
390
|
+
* function draw() {
|
|
391
|
+
* background(50);
|
|
392
|
+
*
|
|
393
|
+
* // Draw to the p5.Framebuffer object.
|
|
394
|
+
* myBuffer.begin();
|
|
395
|
+
* background(200);
|
|
396
|
+
* normalMaterial();
|
|
397
|
+
* sphere(width / 4);
|
|
398
|
+
* myBuffer.end();
|
|
399
|
+
*
|
|
400
|
+
* // Display the p5.Framebuffer object.
|
|
401
|
+
* image(myBuffer, -width / 2, -height / 2);
|
|
402
|
+
* }
|
|
403
|
+
*
|
|
404
|
+
* // Resize the canvas when the user moves the mouse.
|
|
405
|
+
* function mouseMoved() {
|
|
406
|
+
* let w = constrain(mouseX, 0, 100);
|
|
407
|
+
* let h = constrain(mouseY, 0, 100);
|
|
408
|
+
* resizeCanvas(w, h);
|
|
409
|
+
* }
|
|
410
|
+
*
|
|
411
|
+
* // Toggle autoSizing when the user double-clicks.
|
|
412
|
+
* // Note: opened an issue to fix(?) this.
|
|
413
|
+
* function doubleClicked() {
|
|
414
|
+
* let isAuto = myBuffer.autoSized();
|
|
415
|
+
* myBuffer.autoSized(!isAuto);
|
|
416
|
+
* }
|
|
417
|
+
* </code>
|
|
418
|
+
* </div>
|
|
419
|
+
*/
|
|
420
|
+
function autoSized(autoSized?: boolean): boolean;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Creates a new
|
|
424
|
+
* p5.Camera object to use with the framebuffer.The new camera is initialized with a default position `(0, 0, 800)` and a
|
|
425
|
+
* default perspective projection. Its properties can be controlled with
|
|
426
|
+
* p5.Camera methods such as `myCamera.lookAt(0, 0, 0)`.Framebuffer cameras should be created between calls to
|
|
427
|
+
* myBuffer.begin() and
|
|
428
|
+
* myBuffer.end() like so:`let myCamera;
|
|
429
|
+
*
|
|
430
|
+
* myBuffer.begin();
|
|
431
|
+
*
|
|
432
|
+
* // Create the camera for the framebuffer.
|
|
433
|
+
* myCamera = myBuffer.createCamera();
|
|
434
|
+
*
|
|
435
|
+
* myBuffer.end();`Calling setCamera() updates the
|
|
436
|
+
* framebuffer's projection using the camera.
|
|
437
|
+
* resetMatrix() must also be called for the
|
|
438
|
+
* view to change properly:`myBuffer.begin();
|
|
439
|
+
*
|
|
440
|
+
* // Set the camera for the framebuffer.
|
|
441
|
+
* setCamera(myCamera);
|
|
442
|
+
*
|
|
443
|
+
* // Reset all transformations.
|
|
444
|
+
* resetMatrix();
|
|
445
|
+
*
|
|
446
|
+
* // Draw stuff...
|
|
447
|
+
*
|
|
448
|
+
* myBuffer.end();`
|
|
449
|
+
*
|
|
450
|
+
* @returns new camera.
|
|
451
|
+
* @example <div>
|
|
452
|
+
* <code>
|
|
453
|
+
* // Double-click to toggle between cameras.
|
|
454
|
+
*
|
|
455
|
+
* let myBuffer;
|
|
456
|
+
* let cam1;
|
|
457
|
+
* let cam2;
|
|
458
|
+
* let usingCam1 = true;
|
|
459
|
+
*
|
|
460
|
+
* function setup() {
|
|
461
|
+
* createCanvas(100, 100, WEBGL);
|
|
462
|
+
*
|
|
463
|
+
* // Create a p5.Framebuffer object.
|
|
464
|
+
* myBuffer = createFramebuffer();
|
|
465
|
+
*
|
|
466
|
+
* // Create the cameras between begin() and end().
|
|
467
|
+
* myBuffer.begin();
|
|
468
|
+
*
|
|
469
|
+
* // Create the first camera.
|
|
470
|
+
* // Keep its default settings.
|
|
471
|
+
* cam1 = myBuffer.createCamera();
|
|
472
|
+
*
|
|
473
|
+
* // Create the second camera.
|
|
474
|
+
* // Place it at the top-left.
|
|
475
|
+
* // Point it at the origin.
|
|
476
|
+
* cam2 = myBuffer.createCamera();
|
|
477
|
+
* cam2.setPosition(400, -400, 800);
|
|
478
|
+
* cam2.lookAt(0, 0, 0);
|
|
479
|
+
*
|
|
480
|
+
* myBuffer.end();
|
|
481
|
+
*
|
|
482
|
+
* describe(
|
|
483
|
+
* 'A white cube on a gray background. The camera toggles between frontal and aerial views when the user double-clicks.'
|
|
484
|
+
* );
|
|
485
|
+
* }
|
|
486
|
+
*
|
|
487
|
+
* function draw() {
|
|
488
|
+
* // Draw to the p5.Framebuffer object.
|
|
489
|
+
* myBuffer.begin();
|
|
490
|
+
* background(200);
|
|
491
|
+
*
|
|
492
|
+
* // Set the camera.
|
|
493
|
+
* if (usingCam1 === true) {
|
|
494
|
+
* setCamera(cam1);
|
|
495
|
+
* } else {
|
|
496
|
+
* setCamera(cam2);
|
|
497
|
+
* }
|
|
498
|
+
*
|
|
499
|
+
* // Reset all transformations.
|
|
500
|
+
* resetMatrix();
|
|
501
|
+
*
|
|
502
|
+
* // Draw the box.
|
|
503
|
+
* box();
|
|
504
|
+
*
|
|
505
|
+
* myBuffer.end();
|
|
506
|
+
*
|
|
507
|
+
* // Display the p5.Framebuffer object.
|
|
508
|
+
* image(myBuffer, -50, -50);
|
|
509
|
+
* }
|
|
510
|
+
*
|
|
511
|
+
* // Toggle the current camera when the user double-clicks.
|
|
512
|
+
* function doubleClicked() {
|
|
513
|
+
* if (usingCam1 === true) {
|
|
514
|
+
* usingCam1 = false;
|
|
515
|
+
* } else {
|
|
516
|
+
* usingCam1 = true;
|
|
517
|
+
* }
|
|
518
|
+
* }
|
|
519
|
+
* </code>
|
|
520
|
+
* </div>
|
|
521
|
+
*/
|
|
522
|
+
function createCamera(): p5.Camera;
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Deletes the framebuffer from GPU memory.Calling `myBuffer.remove()` frees the GPU memory used by the framebuffer.
|
|
526
|
+
* The framebuffer also uses a bit of memory on the CPU which can be freed
|
|
527
|
+
* like so:`// Delete the framebuffer from GPU memory.
|
|
528
|
+
* myBuffer.remove();
|
|
529
|
+
*
|
|
530
|
+
* // Delete the framebuffer from CPU memory.
|
|
531
|
+
* myBuffer = undefined;`Note: All variables that reference the framebuffer must be assigned
|
|
532
|
+
* the value `undefined` to delete the framebuffer from CPU memory. If any
|
|
533
|
+
* variable still refers to the framebuffer, then it won't be garbage
|
|
534
|
+
* collected.
|
|
535
|
+
*
|
|
536
|
+
* @example <div>
|
|
537
|
+
* <code>
|
|
538
|
+
* // Double-click to remove the p5.Framebuffer object.
|
|
539
|
+
*
|
|
540
|
+
* let myBuffer;
|
|
541
|
+
*
|
|
542
|
+
* function setup() {
|
|
543
|
+
* createCanvas(100, 100, WEBGL);
|
|
544
|
+
*
|
|
545
|
+
* // Create an options object.
|
|
546
|
+
* let options = { width: 60, height: 60 };
|
|
547
|
+
*
|
|
548
|
+
* // Create a p5.Framebuffer object and
|
|
549
|
+
* // configure it using options.
|
|
550
|
+
* myBuffer = createFramebuffer(options);
|
|
551
|
+
*
|
|
552
|
+
* describe('A white circle at the center of a dark gray square disappears when the user double-clicks.');
|
|
553
|
+
* }
|
|
554
|
+
*
|
|
555
|
+
* function draw() {
|
|
556
|
+
* background(200);
|
|
557
|
+
*
|
|
558
|
+
* // Display the p5.Framebuffer object if
|
|
559
|
+
* // it's available.
|
|
560
|
+
* if (myBuffer) {
|
|
561
|
+
* // Draw to the p5.Framebuffer object.
|
|
562
|
+
* myBuffer.begin();
|
|
563
|
+
* background(100);
|
|
564
|
+
* circle(0, 0, 20);
|
|
565
|
+
* myBuffer.end();
|
|
566
|
+
*
|
|
567
|
+
* image(myBuffer, -30, -30);
|
|
568
|
+
* }
|
|
569
|
+
* }
|
|
570
|
+
*
|
|
571
|
+
* // Remove the p5.Framebuffer object when the
|
|
572
|
+
* // the user double-clicks.
|
|
573
|
+
* function doubleClicked() {
|
|
574
|
+
* // Delete the framebuffer from GPU memory.
|
|
575
|
+
* myBuffer.remove();
|
|
576
|
+
*
|
|
577
|
+
* // Delete the framebuffer from CPU memory.
|
|
578
|
+
* myBuffer = undefined;
|
|
579
|
+
* }
|
|
580
|
+
* </code>
|
|
581
|
+
* </div>
|
|
582
|
+
*/
|
|
583
|
+
function remove(): void;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Begins drawing shapes to the framebuffer.`myBuffer.begin()` and myBuffer.end()
|
|
587
|
+
* allow shapes to be drawn to the framebuffer. `myBuffer.begin()` begins
|
|
588
|
+
* drawing to the framebuffer and
|
|
589
|
+
* myBuffer.end() stops drawing to the
|
|
590
|
+
* framebuffer. Changes won't be visible until the framebuffer is displayed
|
|
591
|
+
* as an image or texture.
|
|
592
|
+
*
|
|
593
|
+
* @example <div>
|
|
594
|
+
* <code>
|
|
595
|
+
* let myBuffer;
|
|
596
|
+
*
|
|
597
|
+
* function setup() {
|
|
598
|
+
* createCanvas(100, 100, WEBGL);
|
|
599
|
+
*
|
|
600
|
+
* // Create a p5.Framebuffer object.
|
|
601
|
+
* myBuffer = createFramebuffer();
|
|
602
|
+
*
|
|
603
|
+
* describe('An empty gray canvas. The canvas gets darker and a rotating, multicolor torus appears while the user presses and holds the mouse.');
|
|
604
|
+
* }
|
|
605
|
+
*
|
|
606
|
+
* function draw() {
|
|
607
|
+
* background(200);
|
|
608
|
+
*
|
|
609
|
+
* // Start drawing to the p5.Framebuffer object.
|
|
610
|
+
* myBuffer.begin();
|
|
611
|
+
*
|
|
612
|
+
* background(50);
|
|
613
|
+
* rotateY(frameCount * 0.01);
|
|
614
|
+
* normalMaterial();
|
|
615
|
+
* torus(30);
|
|
616
|
+
*
|
|
617
|
+
* // Stop drawing to the p5.Framebuffer object.
|
|
618
|
+
* myBuffer.end();
|
|
619
|
+
*
|
|
620
|
+
* // Display the p5.Framebuffer object while
|
|
621
|
+
* // the user presses the mouse.
|
|
622
|
+
* if (mouseIsPressed === true) {
|
|
623
|
+
* image(myBuffer, -50, -50);
|
|
624
|
+
* }
|
|
625
|
+
* }
|
|
626
|
+
* </code>
|
|
627
|
+
* </div>
|
|
628
|
+
*/
|
|
629
|
+
function begin(): void;
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Stops drawing shapes to the framebuffer.myBuffer.begin() and `myBuffer.end()`
|
|
633
|
+
* allow shapes to be drawn to the framebuffer.
|
|
634
|
+
* myBuffer.begin() begins drawing to
|
|
635
|
+
* the framebuffer and `myBuffer.end()` stops drawing to the framebuffer.
|
|
636
|
+
* Changes won't be visible until the framebuffer is displayed as an image
|
|
637
|
+
* or texture.
|
|
638
|
+
*
|
|
639
|
+
* @example <div>
|
|
640
|
+
* <code>
|
|
641
|
+
* let myBuffer;
|
|
642
|
+
*
|
|
643
|
+
* function setup() {
|
|
644
|
+
* createCanvas(100, 100, WEBGL);
|
|
645
|
+
*
|
|
646
|
+
* // Create a p5.Framebuffer object.
|
|
647
|
+
* myBuffer = createFramebuffer();
|
|
648
|
+
*
|
|
649
|
+
* describe('An empty gray canvas. The canvas gets darker and a rotating, multicolor torus appears while the user presses and holds the mouse.');
|
|
650
|
+
* }
|
|
651
|
+
*
|
|
652
|
+
* function draw() {
|
|
653
|
+
* background(200);
|
|
654
|
+
*
|
|
655
|
+
* // Start drawing to the p5.Framebuffer object.
|
|
656
|
+
* myBuffer.begin();
|
|
657
|
+
*
|
|
658
|
+
* background(50);
|
|
659
|
+
* rotateY(frameCount * 0.01);
|
|
660
|
+
* normalMaterial();
|
|
661
|
+
* torus(30);
|
|
662
|
+
*
|
|
663
|
+
* // Stop drawing to the p5.Framebuffer object.
|
|
664
|
+
* myBuffer.end();
|
|
665
|
+
*
|
|
666
|
+
* // Display the p5.Framebuffer object while
|
|
667
|
+
* // the user presses the mouse.
|
|
668
|
+
* if (mouseIsPressed === true) {
|
|
669
|
+
* image(myBuffer, -50, -50);
|
|
670
|
+
* }
|
|
671
|
+
* }
|
|
672
|
+
* </code>
|
|
673
|
+
* </div>
|
|
674
|
+
*/
|
|
675
|
+
function end(): void;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Draws to the framebuffer by calling a function that contains drawing
|
|
679
|
+
* instructions.The parameter, `callback`, is a function with the drawing instructions
|
|
680
|
+
* for the framebuffer. For example, calling `myBuffer.draw(myFunction)`
|
|
681
|
+
* will call a function named `myFunction()` to draw to the framebuffer.
|
|
682
|
+
* Doing so has the same effect as the following:`myBuffer.begin();
|
|
683
|
+
* myFunction();
|
|
684
|
+
* myBuffer.end();`
|
|
685
|
+
*
|
|
686
|
+
* @param function that draws to the framebuffer.
|
|
687
|
+
* @example <div>
|
|
688
|
+
* <code>
|
|
689
|
+
* // Click the canvas to display the framebuffer.
|
|
690
|
+
*
|
|
691
|
+
* let myBuffer;
|
|
692
|
+
*
|
|
693
|
+
* function setup() {
|
|
694
|
+
* createCanvas(100, 100, WEBGL);
|
|
695
|
+
*
|
|
696
|
+
* // Create a p5.Framebuffer object.
|
|
697
|
+
* myBuffer = createFramebuffer();
|
|
698
|
+
*
|
|
699
|
+
* describe('An empty gray canvas. The canvas gets darker and a rotating, multicolor torus appears while the user presses and holds the mouse.');
|
|
700
|
+
* }
|
|
701
|
+
*
|
|
702
|
+
* function draw() {
|
|
703
|
+
* background(200);
|
|
704
|
+
*
|
|
705
|
+
* // Draw to the p5.Framebuffer object.
|
|
706
|
+
* myBuffer.draw(bagel);
|
|
707
|
+
*
|
|
708
|
+
* // Display the p5.Framebuffer object while
|
|
709
|
+
* // the user presses the mouse.
|
|
710
|
+
* if (mouseIsPressed === true) {
|
|
711
|
+
* image(myBuffer, -50, -50);
|
|
712
|
+
* }
|
|
713
|
+
* }
|
|
714
|
+
*
|
|
715
|
+
* // Draw a rotating, multicolor torus.
|
|
716
|
+
* function bagel() {
|
|
717
|
+
* background(50);
|
|
718
|
+
* rotateY(frameCount * 0.01);
|
|
719
|
+
* normalMaterial();
|
|
720
|
+
* torus(30);
|
|
721
|
+
* }
|
|
722
|
+
* </code>
|
|
723
|
+
* </div>
|
|
724
|
+
*/
|
|
725
|
+
function draw(callback: Function): void;
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Gets a pixel or a region of pixels from the framebuffer.`myBuffer.get()` is easy to use but it's not as fast as
|
|
729
|
+
* myBuffer.pixels. Use
|
|
730
|
+
* myBuffer.pixels to read many pixel
|
|
731
|
+
* values.The version of `myBuffer.get()` with no parameters returns the entire
|
|
732
|
+
* framebuffer as a a p5.Image object.The version of `myBuffer.get()` with two parameters interprets them as
|
|
733
|
+
* coordinates. It returns an array with the `[R, G, B, A]` values of the
|
|
734
|
+
* pixel at the given point.The version of `myBuffer.get()` with four parameters interprets them as
|
|
735
|
+
* coordinates and dimensions. It returns a subsection of the framebuffer as
|
|
736
|
+
* a p5.Image object. The first two parameters are
|
|
737
|
+
* the coordinates for the upper-left corner of the subsection. The last two
|
|
738
|
+
* parameters are the width and height of the subsection.
|
|
739
|
+
*
|
|
740
|
+
* @param x-coordinate of the pixel. Defaults to 0.
|
|
741
|
+
* @param y-coordinate of the pixel. Defaults to 0.
|
|
742
|
+
* @param width of the subsection to be returned.
|
|
743
|
+
* @param height of the subsection to be returned.
|
|
744
|
+
* @return subsection as a <a href="#/p5.Image">p5.Image</a> object.
|
|
745
|
+
*/
|
|
746
|
+
function get(x: number, y: number, w: number, h: number): p5.Image;
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* @return entire framebuffer as a <a href="#/p5.Image">p5.Image</a> object.
|
|
750
|
+
*/
|
|
751
|
+
function get(x: any, y: any, w: any, h: any): p5.Image;
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* @return color of the pixel at `(x, y)` as an array of color values `[R, G, B, A]`.
|
|
755
|
+
*/
|
|
756
|
+
function get(x: number, y: number, w: any, h: any): number[];
|
|
757
|
+
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export default function p5_Framebuffer(p5: any, fn: any): void;
|