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,1638 @@
|
|
|
1
|
+
// This file is auto-generated from JSDoc documentation
|
|
2
|
+
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
import { Vector } from '../math/p5.Vector';
|
|
5
|
+
|
|
6
|
+
declare module 'p5' {
|
|
7
|
+
/**
|
|
8
|
+
* Applies a transformation matrix to the coordinate system.Transformations such as
|
|
9
|
+
* translate(),
|
|
10
|
+
* rotate(), and
|
|
11
|
+
* scale()
|
|
12
|
+
* use matrix-vector multiplication behind the scenes. A table of numbers,
|
|
13
|
+
* called a matrix, encodes each transformation. The values in the matrix
|
|
14
|
+
* then multiply each point on the canvas, which is represented by a vector.`applyMatrix()` allows for many transformations to be applied at once. See
|
|
15
|
+
* Wikipedia
|
|
16
|
+
* and MDN
|
|
17
|
+
* for more details about transformations.There are two ways to call `applyMatrix()` in two and three dimensions.In 2D mode, the parameters `a`, `b`, `c`, `d`, `e`, and `f`, correspond to
|
|
18
|
+
* elements in the following transformation matrix:The numbers can be passed individually, as in
|
|
19
|
+
* `applyMatrix(2, 0, 0, 0, 2, 0)`. They can also be passed in an array, as in
|
|
20
|
+
* `applyMatrix([2, 0, 0, 0, 2, 0])`.In 3D mode, the parameters `a`, `b`, `c`, `d`, `e`, `f`, `g`, `h`, `i`,
|
|
21
|
+
* `j`, `k`, `l`, `m`, `n`, `o`, and `p` correspond to elements in the
|
|
22
|
+
* following transformation matrix:The numbers can be passed individually, as in
|
|
23
|
+
* `applyMatrix(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1)`. They can
|
|
24
|
+
* also be passed in an array, as in
|
|
25
|
+
* `applyMatrix([2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1])`.By default, transformations accumulate. The
|
|
26
|
+
* push() and pop() functions
|
|
27
|
+
* can be used to isolate transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
28
|
+
* `applyMatrix()` inside the draw() function won't
|
|
29
|
+
* cause shapes to transform continuously.
|
|
30
|
+
*
|
|
31
|
+
* @param an array containing the elements of the transformation matrix. Its length should be either 6 (2D) or 16 (3D).
|
|
32
|
+
* @example <div>
|
|
33
|
+
* <code>
|
|
34
|
+
* function setup() {
|
|
35
|
+
* createCanvas(100, 100);
|
|
36
|
+
*
|
|
37
|
+
* describe('A white circle on a gray background.');
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* function draw() {
|
|
41
|
+
* background(200);
|
|
42
|
+
*
|
|
43
|
+
* // Translate the origin to the center.
|
|
44
|
+
* applyMatrix(1, 0, 0, 1, 50, 50);
|
|
45
|
+
*
|
|
46
|
+
* // Draw the circle at coordinates (0, 0).
|
|
47
|
+
* circle(0, 0, 40);
|
|
48
|
+
* }
|
|
49
|
+
* </code>
|
|
50
|
+
* </div>
|
|
51
|
+
*
|
|
52
|
+
* <div>
|
|
53
|
+
* <code>
|
|
54
|
+
* function setup() {
|
|
55
|
+
* createCanvas(100, 100);
|
|
56
|
+
*
|
|
57
|
+
* describe('A white circle on a gray background.');
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* function draw() {
|
|
61
|
+
* background(200);
|
|
62
|
+
*
|
|
63
|
+
* // Translate the origin to the center.
|
|
64
|
+
* let m = [1, 0, 0, 1, 50, 50];
|
|
65
|
+
* applyMatrix(m);
|
|
66
|
+
*
|
|
67
|
+
* // Draw the circle at coordinates (0, 0).
|
|
68
|
+
* circle(0, 0, 40);
|
|
69
|
+
* }
|
|
70
|
+
* </code>
|
|
71
|
+
* </div>
|
|
72
|
+
*
|
|
73
|
+
* <div>
|
|
74
|
+
* <code>
|
|
75
|
+
* function setup() {
|
|
76
|
+
* createCanvas(100, 100);
|
|
77
|
+
*
|
|
78
|
+
* describe("A white rectangle on a gray background. The rectangle's long axis runs from top-left to bottom-right.");
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* function draw() {
|
|
82
|
+
* background(200);
|
|
83
|
+
*
|
|
84
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
85
|
+
* let angle = QUARTER_PI;
|
|
86
|
+
* let ca = cos(angle);
|
|
87
|
+
* let sa = sin(angle);
|
|
88
|
+
* applyMatrix(ca, sa, -sa, ca, 0, 0);
|
|
89
|
+
*
|
|
90
|
+
* // Draw a rectangle at coordinates (50, 0).
|
|
91
|
+
* rect(50, 0, 40, 20);
|
|
92
|
+
* }
|
|
93
|
+
* </code>
|
|
94
|
+
* </div>
|
|
95
|
+
*
|
|
96
|
+
* <div>
|
|
97
|
+
* <code>
|
|
98
|
+
* function setup() {
|
|
99
|
+
* createCanvas(100, 100);
|
|
100
|
+
*
|
|
101
|
+
* describe(
|
|
102
|
+
* 'Two white squares on a gray background. The larger square appears at the top-center. The smaller square appears at the top-left.'
|
|
103
|
+
* );
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* function draw() {
|
|
107
|
+
* background(200);
|
|
108
|
+
*
|
|
109
|
+
* // Draw a square at (30, 20).
|
|
110
|
+
* square(30, 20, 40);
|
|
111
|
+
*
|
|
112
|
+
* // Scale the coordinate system by a factor of 0.5.
|
|
113
|
+
* applyMatrix(0.5, 0, 0, 0.5, 0, 0);
|
|
114
|
+
*
|
|
115
|
+
* // Draw a square at (30, 20).
|
|
116
|
+
* // It appears at (15, 10) after scaling.
|
|
117
|
+
* square(30, 20, 40);
|
|
118
|
+
* }
|
|
119
|
+
* </code>
|
|
120
|
+
* </div>
|
|
121
|
+
*
|
|
122
|
+
* <div>
|
|
123
|
+
* <code>
|
|
124
|
+
* function setup() {
|
|
125
|
+
* createCanvas(100, 100);
|
|
126
|
+
*
|
|
127
|
+
* describe('A white quadrilateral on a gray background.');
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* function draw() {
|
|
131
|
+
* background(200);
|
|
132
|
+
*
|
|
133
|
+
* // Calculate the shear factor.
|
|
134
|
+
* let angle = QUARTER_PI;
|
|
135
|
+
* let shearFactor = 1 / tan(HALF_PI - angle);
|
|
136
|
+
*
|
|
137
|
+
* // Shear the coordinate system along the x-axis.
|
|
138
|
+
* applyMatrix(1, 0, shearFactor, 1, 0, 0);
|
|
139
|
+
*
|
|
140
|
+
* // Draw the square.
|
|
141
|
+
* square(0, 0, 50);
|
|
142
|
+
* }
|
|
143
|
+
* </code>
|
|
144
|
+
* </div>
|
|
145
|
+
*
|
|
146
|
+
* <div>
|
|
147
|
+
* <code>
|
|
148
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
149
|
+
*
|
|
150
|
+
* function setup() {
|
|
151
|
+
* createCanvas(100, 100, WEBGL);
|
|
152
|
+
*
|
|
153
|
+
* describe('A white cube rotates slowly against a gray background.');
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* function draw() {
|
|
157
|
+
* background(200);
|
|
158
|
+
*
|
|
159
|
+
* // Enable orbiting with the mouse.
|
|
160
|
+
* orbitControl();
|
|
161
|
+
*
|
|
162
|
+
* // Rotate the coordinate system a little more each frame.
|
|
163
|
+
* let angle = frameCount * 0.01;
|
|
164
|
+
* let ca = cos(angle);
|
|
165
|
+
* let sa = sin(angle);
|
|
166
|
+
* applyMatrix(ca, 0, sa, 0, 0, 1, 0, 0, -sa, 0, ca, 0, 0, 0, 0, 1);
|
|
167
|
+
*
|
|
168
|
+
* // Draw a box.
|
|
169
|
+
* box();
|
|
170
|
+
* }
|
|
171
|
+
* </code>
|
|
172
|
+
* </div>
|
|
173
|
+
*/
|
|
174
|
+
function applyMatrix(arr: Array): void;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @param an element of the transformation matrix.
|
|
178
|
+
* @param an element of the transformation matrix.
|
|
179
|
+
* @param an element of the transformation matrix.
|
|
180
|
+
* @param an element of the transformation matrix.
|
|
181
|
+
* @param an element of the transformation matrix.
|
|
182
|
+
* @param an element of the transformation matrix.
|
|
183
|
+
*/
|
|
184
|
+
function applyMatrix(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param an element of the transformation matrix.
|
|
188
|
+
* @param an element of the transformation matrix.
|
|
189
|
+
* @param an element of the transformation matrix.
|
|
190
|
+
* @param an element of the transformation matrix.
|
|
191
|
+
* @param an element of the transformation matrix.
|
|
192
|
+
* @param an element of the transformation matrix.
|
|
193
|
+
* @param an element of the transformation matrix.
|
|
194
|
+
* @param an element of the transformation matrix.
|
|
195
|
+
* @param an element of the transformation matrix.
|
|
196
|
+
* @param an element of the transformation matrix.
|
|
197
|
+
*/
|
|
198
|
+
function applyMatrix(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number): void;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Clears all transformations applied to the coordinate system.
|
|
202
|
+
*
|
|
203
|
+
* @example <div>
|
|
204
|
+
* <code>
|
|
205
|
+
* function setup() {
|
|
206
|
+
* createCanvas(100, 100);
|
|
207
|
+
*
|
|
208
|
+
* describe(
|
|
209
|
+
* 'Two circles drawn on a gray background. A blue circle is at the top-left and a red circle is at the bottom-right.'
|
|
210
|
+
* );
|
|
211
|
+
* }
|
|
212
|
+
*
|
|
213
|
+
* function draw() {
|
|
214
|
+
* background(200);
|
|
215
|
+
*
|
|
216
|
+
* // Translate the origin to the center.
|
|
217
|
+
* translate(50, 50);
|
|
218
|
+
*
|
|
219
|
+
* // Draw a blue circle at the coordinates (25, 25).
|
|
220
|
+
* fill('blue');
|
|
221
|
+
* circle(25, 25, 20);
|
|
222
|
+
*
|
|
223
|
+
* // Clear all transformations.
|
|
224
|
+
* // The origin is now at the top-left corner.
|
|
225
|
+
* resetMatrix();
|
|
226
|
+
*
|
|
227
|
+
* // Draw a red circle at the coordinates (25, 25).
|
|
228
|
+
* fill('red');
|
|
229
|
+
* circle(25, 25, 20);
|
|
230
|
+
* }
|
|
231
|
+
* </code>
|
|
232
|
+
* </div>
|
|
233
|
+
*/
|
|
234
|
+
function resetMatrix(): void;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Rotates the coordinate system.By default, the positive x-axis points to the right and the positive y-axis
|
|
238
|
+
* points downward. The `rotate()` function changes this orientation by
|
|
239
|
+
* rotating the coordinate system about the origin. Everything drawn after
|
|
240
|
+
* `rotate()` is called will appear to be rotated.The first parameter, `angle`, is the amount to rotate. For example, calling
|
|
241
|
+
* `rotate(1)` rotates the coordinate system clockwise 1 radian which is
|
|
242
|
+
* nearly 57˚. `rotate()` interprets angle values using the current
|
|
243
|
+
* angleMode().The second parameter, `axis`, is optional. It's used to orient 3D rotations
|
|
244
|
+
* in WebGL mode. If a p5.Vector is passed, as in
|
|
245
|
+
* `rotate(QUARTER_PI, myVector)`, then the coordinate system will rotate
|
|
246
|
+
* `QUARTER_PI` radians about `myVector`. If an array of vector components is
|
|
247
|
+
* passed, as in `rotate(QUARTER_PI, [1, 0, 0])`, then the coordinate system
|
|
248
|
+
* will rotate `QUARTER_PI` radians about a vector with the components
|
|
249
|
+
* `[1, 0, 0]`.By default, transformations accumulate. For example, calling `rotate(1)`
|
|
250
|
+
* twice has the same effect as calling `rotate(2)` once. The
|
|
251
|
+
* push() and pop() functions
|
|
252
|
+
* can be used to isolate transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
253
|
+
* `rotate(1)` inside the draw() function won't cause
|
|
254
|
+
* shapes to spin.
|
|
255
|
+
*
|
|
256
|
+
* @param angle of rotation in the current <a href="#/p5/angleMode">angleMode()</a>.
|
|
257
|
+
* @param axis to rotate about in 3D.
|
|
258
|
+
* @example <div>
|
|
259
|
+
* <code>
|
|
260
|
+
* function setup() {
|
|
261
|
+
* createCanvas(100, 100);
|
|
262
|
+
*
|
|
263
|
+
* describe(
|
|
264
|
+
* "A white rectangle on a gray background. The rectangle's long axis runs from top-left to bottom-right."
|
|
265
|
+
* );
|
|
266
|
+
* }
|
|
267
|
+
*
|
|
268
|
+
* function draw() {
|
|
269
|
+
* background(200);
|
|
270
|
+
*
|
|
271
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
272
|
+
* rotate(QUARTER_PI);
|
|
273
|
+
*
|
|
274
|
+
* // Draw a rectangle at coordinates (50, 0).
|
|
275
|
+
* rect(50, 0, 40, 20);
|
|
276
|
+
* }
|
|
277
|
+
* </code>
|
|
278
|
+
* </div>
|
|
279
|
+
*
|
|
280
|
+
* <div>
|
|
281
|
+
* <code>
|
|
282
|
+
* function setup() {
|
|
283
|
+
* createCanvas(100, 100);
|
|
284
|
+
*
|
|
285
|
+
* describe(
|
|
286
|
+
* "A white rectangle on a gray background. The rectangle's long axis runs from top-left to bottom-right."
|
|
287
|
+
* );
|
|
288
|
+
* }
|
|
289
|
+
*
|
|
290
|
+
* function draw() {
|
|
291
|
+
* background(200);
|
|
292
|
+
*
|
|
293
|
+
* // Rotate the coordinate system 1/16 turn.
|
|
294
|
+
* rotate(QUARTER_PI / 2);
|
|
295
|
+
*
|
|
296
|
+
* // Rotate the coordinate system another 1/16 turn.
|
|
297
|
+
* rotate(QUARTER_PI / 2);
|
|
298
|
+
*
|
|
299
|
+
* // Draw a rectangle at coordinates (50, 0).
|
|
300
|
+
* rect(50, 0, 40, 20);
|
|
301
|
+
* }
|
|
302
|
+
* </code>
|
|
303
|
+
* </div>
|
|
304
|
+
*
|
|
305
|
+
* <div>
|
|
306
|
+
* <code>
|
|
307
|
+
* function setup() {
|
|
308
|
+
* createCanvas(100, 100);
|
|
309
|
+
*
|
|
310
|
+
* // Use degrees.
|
|
311
|
+
* angleMode(DEGREES);
|
|
312
|
+
*
|
|
313
|
+
* describe(
|
|
314
|
+
* "A white rectangle on a gray background. The rectangle's long axis runs from top-left to bottom-right."
|
|
315
|
+
* );
|
|
316
|
+
* }
|
|
317
|
+
*
|
|
318
|
+
* function draw() {
|
|
319
|
+
* background(200);
|
|
320
|
+
*
|
|
321
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
322
|
+
* rotate(45);
|
|
323
|
+
*
|
|
324
|
+
* // Draw a rectangle at coordinates (50, 0).
|
|
325
|
+
* rect(50, 0, 40, 20);
|
|
326
|
+
* }
|
|
327
|
+
* </code>
|
|
328
|
+
* </div>
|
|
329
|
+
*
|
|
330
|
+
* <div>
|
|
331
|
+
* <code>
|
|
332
|
+
* function setup() {
|
|
333
|
+
* createCanvas(100, 100);
|
|
334
|
+
*
|
|
335
|
+
* describe(
|
|
336
|
+
* 'A white rectangle on a gray background. The rectangle rotates slowly about the top-left corner. It disappears and reappears periodically.'
|
|
337
|
+
* );
|
|
338
|
+
* }
|
|
339
|
+
*
|
|
340
|
+
* function draw() {
|
|
341
|
+
* background(200);
|
|
342
|
+
*
|
|
343
|
+
* // Rotate the coordinate system a little more each frame.
|
|
344
|
+
* let angle = frameCount * 0.01;
|
|
345
|
+
* rotate(angle);
|
|
346
|
+
*
|
|
347
|
+
* // Draw a rectangle at coordinates (50, 0).
|
|
348
|
+
* rect(50, 0, 40, 20);
|
|
349
|
+
* }
|
|
350
|
+
* </code>
|
|
351
|
+
* </div>
|
|
352
|
+
*
|
|
353
|
+
* <div>
|
|
354
|
+
* <code>
|
|
355
|
+
* function setup() {
|
|
356
|
+
* createCanvas(100, 100, WEBGL);
|
|
357
|
+
*
|
|
358
|
+
* describe("A cube on a gray background. The cube's front face points to the top-right.");
|
|
359
|
+
* }
|
|
360
|
+
*
|
|
361
|
+
* function draw() {
|
|
362
|
+
* background(200);
|
|
363
|
+
*
|
|
364
|
+
* // Rotate the coordinate system 1/8 turn about
|
|
365
|
+
* // the axis [1, 1, 0].
|
|
366
|
+
* let axis = createVector(1, 1, 0);
|
|
367
|
+
* rotate(QUARTER_PI, axis);
|
|
368
|
+
*
|
|
369
|
+
* // Draw a box.
|
|
370
|
+
* box();
|
|
371
|
+
* }
|
|
372
|
+
* </code>
|
|
373
|
+
* </div>
|
|
374
|
+
*
|
|
375
|
+
* <div>
|
|
376
|
+
* <code>
|
|
377
|
+
* function setup() {
|
|
378
|
+
* createCanvas(100, 100, WEBGL);
|
|
379
|
+
*
|
|
380
|
+
* describe("A cube on a gray background. The cube's front face points to the top-right.");
|
|
381
|
+
* }
|
|
382
|
+
*
|
|
383
|
+
* function draw() {
|
|
384
|
+
* background(200);
|
|
385
|
+
*
|
|
386
|
+
* // Rotate the coordinate system 1/8 turn about
|
|
387
|
+
* // the axis [1, 1, 0].
|
|
388
|
+
* let axis = [1, 1, 0];
|
|
389
|
+
* rotate(QUARTER_PI, axis);
|
|
390
|
+
*
|
|
391
|
+
* // Draw a box.
|
|
392
|
+
* box();
|
|
393
|
+
* }
|
|
394
|
+
* </code>
|
|
395
|
+
* </div>
|
|
396
|
+
*/
|
|
397
|
+
function rotate(angle: number, axis?: p5.Vector | number[]): void;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Rotates the coordinate system about the x-axis in WebGL mode.The parameter, `angle`, is the amount to rotate. For example, calling
|
|
401
|
+
* `rotateX(1)` rotates the coordinate system about the x-axis by 1 radian.
|
|
402
|
+
* `rotateX()` interprets angle values using the current
|
|
403
|
+
* angleMode().By default, transformations accumulate. For example, calling `rotateX(1)`
|
|
404
|
+
* twice has the same effect as calling `rotateX(2)` once. The
|
|
405
|
+
* push() and pop() functions
|
|
406
|
+
* can be used to isolate transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
407
|
+
* `rotateX(1)` inside the draw() function won't cause
|
|
408
|
+
* shapes to spin.
|
|
409
|
+
*
|
|
410
|
+
* @param angle of rotation in the current <a href="#/p5/angleMode">angleMode()</a>.
|
|
411
|
+
* @example <div>
|
|
412
|
+
* <code>
|
|
413
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
414
|
+
*
|
|
415
|
+
* function setup() {
|
|
416
|
+
* createCanvas(100, 100, WEBGL);
|
|
417
|
+
*
|
|
418
|
+
* describe('A white cube on a gray background.');
|
|
419
|
+
* }
|
|
420
|
+
*
|
|
421
|
+
* function draw() {
|
|
422
|
+
* background(200);
|
|
423
|
+
*
|
|
424
|
+
* // Enable orbiting with the mouse.
|
|
425
|
+
* orbitControl();
|
|
426
|
+
*
|
|
427
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
428
|
+
* rotateX(QUARTER_PI);
|
|
429
|
+
*
|
|
430
|
+
* // Draw a box.
|
|
431
|
+
* box();
|
|
432
|
+
* }
|
|
433
|
+
* </code>
|
|
434
|
+
* </div>
|
|
435
|
+
*
|
|
436
|
+
* <div>
|
|
437
|
+
* <code>
|
|
438
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
439
|
+
*
|
|
440
|
+
* function setup() {
|
|
441
|
+
* createCanvas(100, 100, WEBGL);
|
|
442
|
+
*
|
|
443
|
+
* describe('A white cube on a gray background.');
|
|
444
|
+
* }
|
|
445
|
+
*
|
|
446
|
+
* function draw() {
|
|
447
|
+
* background(200);
|
|
448
|
+
*
|
|
449
|
+
* // Enable orbiting with the mouse.
|
|
450
|
+
* orbitControl();
|
|
451
|
+
*
|
|
452
|
+
* // Rotate the coordinate system 1/16 turn.
|
|
453
|
+
* rotateX(QUARTER_PI / 2);
|
|
454
|
+
*
|
|
455
|
+
* // Rotate the coordinate system 1/16 turn.
|
|
456
|
+
* rotateX(QUARTER_PI / 2);
|
|
457
|
+
*
|
|
458
|
+
* // Draw a box.
|
|
459
|
+
* box();
|
|
460
|
+
* }
|
|
461
|
+
* </code>
|
|
462
|
+
* </div>
|
|
463
|
+
*
|
|
464
|
+
* <div>
|
|
465
|
+
* <code>
|
|
466
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
467
|
+
*
|
|
468
|
+
* function setup() {
|
|
469
|
+
* createCanvas(100, 100, WEBGL);
|
|
470
|
+
*
|
|
471
|
+
* // Use degrees.
|
|
472
|
+
* angleMode(DEGREES);
|
|
473
|
+
*
|
|
474
|
+
* describe('A white cube on a gray background.');
|
|
475
|
+
* }
|
|
476
|
+
*
|
|
477
|
+
* function draw() {
|
|
478
|
+
* background(200);
|
|
479
|
+
*
|
|
480
|
+
* // Enable orbiting with the mouse.
|
|
481
|
+
* orbitControl();
|
|
482
|
+
*
|
|
483
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
484
|
+
* rotateX(45);
|
|
485
|
+
*
|
|
486
|
+
* // Draw a box.
|
|
487
|
+
* box();
|
|
488
|
+
* }
|
|
489
|
+
* </code>
|
|
490
|
+
* </div>
|
|
491
|
+
*
|
|
492
|
+
* <div>
|
|
493
|
+
* <code>
|
|
494
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
495
|
+
*
|
|
496
|
+
* function setup() {
|
|
497
|
+
* createCanvas(100, 100, WEBGL);
|
|
498
|
+
*
|
|
499
|
+
* describe('A white cube rotates slowly against a gray background.');
|
|
500
|
+
* }
|
|
501
|
+
*
|
|
502
|
+
* function draw() {
|
|
503
|
+
* background(200);
|
|
504
|
+
*
|
|
505
|
+
* // Enable orbiting with the mouse.
|
|
506
|
+
* orbitControl();
|
|
507
|
+
*
|
|
508
|
+
* // Rotate the coordinate system a little more each frame.
|
|
509
|
+
* let angle = frameCount * 0.01;
|
|
510
|
+
* rotateX(angle);
|
|
511
|
+
*
|
|
512
|
+
* // Draw a box.
|
|
513
|
+
* box();
|
|
514
|
+
* }
|
|
515
|
+
* </code>
|
|
516
|
+
* </div>
|
|
517
|
+
*/
|
|
518
|
+
function rotateX(angle: number): void;
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Rotates the coordinate system about the y-axis in WebGL mode.The parameter, `angle`, is the amount to rotate. For example, calling
|
|
522
|
+
* `rotateY(1)` rotates the coordinate system about the y-axis by 1 radian.
|
|
523
|
+
* `rotateY()` interprets angle values using the current
|
|
524
|
+
* angleMode().By default, transformations accumulate. For example, calling `rotateY(1)`
|
|
525
|
+
* twice has the same effect as calling `rotateY(2)` once. The
|
|
526
|
+
* push() and pop() functions
|
|
527
|
+
* can be used to isolate transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
528
|
+
* `rotateY(1)` inside the draw() function won't cause
|
|
529
|
+
* shapes to spin.
|
|
530
|
+
*
|
|
531
|
+
* @param angle of rotation in the current <a href="#/p5/angleMode">angleMode()</a>.
|
|
532
|
+
* @example <div>
|
|
533
|
+
* <code>
|
|
534
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
535
|
+
*
|
|
536
|
+
* function setup() {
|
|
537
|
+
* createCanvas(100, 100, WEBGL);
|
|
538
|
+
*
|
|
539
|
+
* describe('A white cube on a gray background.');
|
|
540
|
+
* }
|
|
541
|
+
*
|
|
542
|
+
* function draw() {
|
|
543
|
+
* background(200);
|
|
544
|
+
*
|
|
545
|
+
* // Enable orbiting with the mouse.
|
|
546
|
+
* orbitControl();
|
|
547
|
+
*
|
|
548
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
549
|
+
* rotateY(QUARTER_PI);
|
|
550
|
+
*
|
|
551
|
+
* // Draw a box.
|
|
552
|
+
* box();
|
|
553
|
+
* }
|
|
554
|
+
* </code>
|
|
555
|
+
* </div>
|
|
556
|
+
*
|
|
557
|
+
* <div>
|
|
558
|
+
* <code>
|
|
559
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
560
|
+
*
|
|
561
|
+
* function setup() {
|
|
562
|
+
* createCanvas(100, 100, WEBGL);
|
|
563
|
+
*
|
|
564
|
+
* describe('A white cube on a gray background.');
|
|
565
|
+
* }
|
|
566
|
+
*
|
|
567
|
+
* function draw() {
|
|
568
|
+
* background(200);
|
|
569
|
+
*
|
|
570
|
+
* // Enable orbiting with the mouse.
|
|
571
|
+
* orbitControl();
|
|
572
|
+
*
|
|
573
|
+
* // Rotate the coordinate system 1/16 turn.
|
|
574
|
+
* rotateY(QUARTER_PI / 2);
|
|
575
|
+
*
|
|
576
|
+
* // Rotate the coordinate system 1/16 turn.
|
|
577
|
+
* rotateY(QUARTER_PI / 2);
|
|
578
|
+
*
|
|
579
|
+
* // Draw a box.
|
|
580
|
+
* box();
|
|
581
|
+
* }
|
|
582
|
+
* </code>
|
|
583
|
+
* </div>
|
|
584
|
+
*
|
|
585
|
+
* <div>
|
|
586
|
+
* <code>
|
|
587
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
588
|
+
*
|
|
589
|
+
* function setup() {
|
|
590
|
+
* createCanvas(100, 100, WEBGL);
|
|
591
|
+
*
|
|
592
|
+
* // Use degrees.
|
|
593
|
+
* angleMode(DEGREES);
|
|
594
|
+
*
|
|
595
|
+
* describe('A white cube on a gray background.');
|
|
596
|
+
* }
|
|
597
|
+
*
|
|
598
|
+
* function draw() {
|
|
599
|
+
* background(200);
|
|
600
|
+
*
|
|
601
|
+
* // Enable orbiting with the mouse.
|
|
602
|
+
* orbitControl();
|
|
603
|
+
*
|
|
604
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
605
|
+
* rotateY(45);
|
|
606
|
+
*
|
|
607
|
+
* // Draw a box.
|
|
608
|
+
* box();
|
|
609
|
+
* }
|
|
610
|
+
* </code>
|
|
611
|
+
* </div>
|
|
612
|
+
*
|
|
613
|
+
* <div>
|
|
614
|
+
* <code>
|
|
615
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
616
|
+
*
|
|
617
|
+
* function setup() {
|
|
618
|
+
* createCanvas(100, 100, WEBGL);
|
|
619
|
+
*
|
|
620
|
+
* describe('A white cube rotates slowly against a gray background.');
|
|
621
|
+
* }
|
|
622
|
+
*
|
|
623
|
+
* function draw() {
|
|
624
|
+
* background(200);
|
|
625
|
+
*
|
|
626
|
+
* // Enable orbiting with the mouse.
|
|
627
|
+
* orbitControl();
|
|
628
|
+
*
|
|
629
|
+
* // Rotate the coordinate system a little more each frame.
|
|
630
|
+
* let angle = frameCount * 0.01;
|
|
631
|
+
* rotateY(angle);
|
|
632
|
+
*
|
|
633
|
+
* // Draw a box.
|
|
634
|
+
* box();
|
|
635
|
+
* }
|
|
636
|
+
* </code>
|
|
637
|
+
* </div>
|
|
638
|
+
*/
|
|
639
|
+
function rotateY(angle: number): void;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Rotates the coordinate system about the z-axis in WebGL mode.The parameter, `angle`, is the amount to rotate. For example, calling
|
|
643
|
+
* `rotateZ(1)` rotates the coordinate system about the z-axis by 1 radian.
|
|
644
|
+
* `rotateZ()` interprets angle values using the current
|
|
645
|
+
* angleMode().By default, transformations accumulate. For example, calling `rotateZ(1)`
|
|
646
|
+
* twice has the same effect as calling `rotateZ(2)` once. The
|
|
647
|
+
* push() and pop() functions
|
|
648
|
+
* can be used to isolate transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
649
|
+
* `rotateZ(1)` inside the draw() function won't cause
|
|
650
|
+
* shapes to spin.
|
|
651
|
+
*
|
|
652
|
+
* @param angle of rotation in the current <a href="#/p5/angleMode">angleMode()</a>.
|
|
653
|
+
* @example <div>
|
|
654
|
+
* <code>
|
|
655
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
656
|
+
*
|
|
657
|
+
* function setup() {
|
|
658
|
+
* createCanvas(100, 100, WEBGL);
|
|
659
|
+
*
|
|
660
|
+
* describe('A white cube on a gray background.');
|
|
661
|
+
* }
|
|
662
|
+
*
|
|
663
|
+
* function draw() {
|
|
664
|
+
* background(200);
|
|
665
|
+
*
|
|
666
|
+
* // Enable orbiting with the mouse.
|
|
667
|
+
* orbitControl();
|
|
668
|
+
*
|
|
669
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
670
|
+
* rotateZ(QUARTER_PI);
|
|
671
|
+
*
|
|
672
|
+
* // Draw a box.
|
|
673
|
+
* box();
|
|
674
|
+
* }
|
|
675
|
+
* </code>
|
|
676
|
+
* </div>
|
|
677
|
+
*
|
|
678
|
+
* <div>
|
|
679
|
+
* <code>
|
|
680
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
681
|
+
*
|
|
682
|
+
* function setup() {
|
|
683
|
+
* createCanvas(100, 100, WEBGL);
|
|
684
|
+
*
|
|
685
|
+
* describe('A white cube on a gray background.');
|
|
686
|
+
* }
|
|
687
|
+
*
|
|
688
|
+
* function draw() {
|
|
689
|
+
* background(200);
|
|
690
|
+
*
|
|
691
|
+
* // Enable orbiting with the mouse.
|
|
692
|
+
* orbitControl();
|
|
693
|
+
*
|
|
694
|
+
* // Rotate the coordinate system 1/16 turn.
|
|
695
|
+
* rotateZ(QUARTER_PI / 2);
|
|
696
|
+
*
|
|
697
|
+
* // Rotate the coordinate system 1/16 turn.
|
|
698
|
+
* rotateZ(QUARTER_PI / 2);
|
|
699
|
+
*
|
|
700
|
+
* // Draw a box.
|
|
701
|
+
* box();
|
|
702
|
+
* }
|
|
703
|
+
* </code>
|
|
704
|
+
* </div>
|
|
705
|
+
*
|
|
706
|
+
* <div>
|
|
707
|
+
* <code>
|
|
708
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
709
|
+
*
|
|
710
|
+
* function setup() {
|
|
711
|
+
* createCanvas(100, 100, WEBGL);
|
|
712
|
+
*
|
|
713
|
+
* // Use degrees.
|
|
714
|
+
* angleMode(DEGREES);
|
|
715
|
+
*
|
|
716
|
+
* describe('A white cube on a gray background.');
|
|
717
|
+
* }
|
|
718
|
+
*
|
|
719
|
+
* function draw() {
|
|
720
|
+
* background(200);
|
|
721
|
+
*
|
|
722
|
+
* // Enable orbiting with the mouse.
|
|
723
|
+
* orbitControl();
|
|
724
|
+
*
|
|
725
|
+
* // Rotate the coordinate system 1/8 turn.
|
|
726
|
+
* rotateZ(45);
|
|
727
|
+
*
|
|
728
|
+
* // Draw a box.
|
|
729
|
+
* box();
|
|
730
|
+
* }
|
|
731
|
+
* </code>
|
|
732
|
+
* </div>
|
|
733
|
+
*
|
|
734
|
+
* <div>
|
|
735
|
+
* <code>
|
|
736
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
737
|
+
*
|
|
738
|
+
* function setup() {
|
|
739
|
+
* createCanvas(100, 100, WEBGL);
|
|
740
|
+
*
|
|
741
|
+
* describe('A white cube rotates slowly against a gray background.');
|
|
742
|
+
* }
|
|
743
|
+
*
|
|
744
|
+
* function draw() {
|
|
745
|
+
* background(200);
|
|
746
|
+
*
|
|
747
|
+
* // Enable orbiting with the mouse.
|
|
748
|
+
* orbitControl();
|
|
749
|
+
*
|
|
750
|
+
* // Rotate the coordinate system a little more each frame.
|
|
751
|
+
* let angle = frameCount * 0.01;
|
|
752
|
+
* rotateZ(angle);
|
|
753
|
+
*
|
|
754
|
+
* // Draw a box.
|
|
755
|
+
* box();
|
|
756
|
+
* }
|
|
757
|
+
* </code>
|
|
758
|
+
* </div>
|
|
759
|
+
*/
|
|
760
|
+
function rotateZ(angle: number): void;
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Scales the coordinate system.By default, shapes are drawn at their original scale. A rectangle that's 50
|
|
764
|
+
* pixels wide appears to take up half the width of a 100 pixel-wide canvas.
|
|
765
|
+
* The `scale()` function can shrink or stretch the coordinate system so that
|
|
766
|
+
* shapes appear at different sizes. There are two ways to call `scale()` with
|
|
767
|
+
* parameters that set the scale factor(s).The first way to call `scale()` uses numbers to set the amount of scaling.
|
|
768
|
+
* The first parameter, `s`, sets the amount to scale each axis. For example,
|
|
769
|
+
* calling `scale(2)` stretches the x-, y-, and z-axes by a factor of 2. The
|
|
770
|
+
* next two parameters, `y` and `z`, are optional. They set the amount to
|
|
771
|
+
* scale the y- and z-axes. For example, calling `scale(2, 0.5, 1)` stretches
|
|
772
|
+
* the x-axis by a factor of 2, shrinks the y-axis by a factor of 0.5, and
|
|
773
|
+
* leaves the z-axis unchanged.The second way to call `scale()` uses a p5.Vector
|
|
774
|
+
* object to set the scale factors. For example, calling `scale(myVector)`
|
|
775
|
+
* uses the x-, y-, and z-components of `myVector` to set the amount of
|
|
776
|
+
* scaling along the x-, y-, and z-axes. Doing so is the same as calling
|
|
777
|
+
* `scale(myVector.x, myVector.y, myVector.z)`.By default, transformations accumulate. For example, calling `scale(1)`
|
|
778
|
+
* twice has the same effect as calling `scale(2)` once. The
|
|
779
|
+
* push() and pop() functions
|
|
780
|
+
* can be used to isolate transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
781
|
+
* `scale(2)` inside the draw() function won't cause
|
|
782
|
+
* shapes to grow continuously.
|
|
783
|
+
*
|
|
784
|
+
* @param amount to scale along the positive x-axis.
|
|
785
|
+
* @param amount to scale along the positive y-axis. Defaults to `s`.
|
|
786
|
+
* @param amount to scale along the positive z-axis. Defaults to `y`.
|
|
787
|
+
* @example <div>
|
|
788
|
+
* <code>
|
|
789
|
+
* function setup() {
|
|
790
|
+
* createCanvas(100, 100);
|
|
791
|
+
*
|
|
792
|
+
* describe(
|
|
793
|
+
* 'Two white squares on a gray background. The larger square appears at the top-center. The smaller square appears at the top-left.'
|
|
794
|
+
* );
|
|
795
|
+
* }
|
|
796
|
+
*
|
|
797
|
+
* function draw() {
|
|
798
|
+
* background(200);
|
|
799
|
+
*
|
|
800
|
+
* // Draw a square at (30, 20).
|
|
801
|
+
* square(30, 20, 40);
|
|
802
|
+
*
|
|
803
|
+
* // Scale the coordinate system by a factor of 0.5.
|
|
804
|
+
* scale(0.5);
|
|
805
|
+
*
|
|
806
|
+
* // Draw a square at (30, 20).
|
|
807
|
+
* // It appears at (15, 10) after scaling.
|
|
808
|
+
* square(30, 20, 40);
|
|
809
|
+
* }
|
|
810
|
+
* </code>
|
|
811
|
+
* </div>
|
|
812
|
+
*
|
|
813
|
+
* <div>
|
|
814
|
+
* <code>
|
|
815
|
+
* function setup() {
|
|
816
|
+
* createCanvas(100, 100);
|
|
817
|
+
*
|
|
818
|
+
* describe('A rectangle and a square drawn in white on a gray background.');
|
|
819
|
+
* }
|
|
820
|
+
*
|
|
821
|
+
* function draw() {
|
|
822
|
+
* background(200);
|
|
823
|
+
*
|
|
824
|
+
* // Draw a square at (30, 20).
|
|
825
|
+
* square(30, 20, 40);
|
|
826
|
+
*
|
|
827
|
+
* // Scale the coordinate system by factors of
|
|
828
|
+
* // 0.5 along the x-axis and
|
|
829
|
+
* // 1.3 along the y-axis.
|
|
830
|
+
* scale(0.5, 1.3);
|
|
831
|
+
*
|
|
832
|
+
* // Draw a square at (30, 20).
|
|
833
|
+
* // It appears as a rectangle at (15, 26) after scaling.
|
|
834
|
+
* square(30, 20, 40);
|
|
835
|
+
* }
|
|
836
|
+
* </code>
|
|
837
|
+
* </div>
|
|
838
|
+
*
|
|
839
|
+
* <div>
|
|
840
|
+
* <code>
|
|
841
|
+
* function setup() {
|
|
842
|
+
* createCanvas(100, 100);
|
|
843
|
+
*
|
|
844
|
+
* describe('A rectangle and a square drawn in white on a gray background.');
|
|
845
|
+
* }
|
|
846
|
+
*
|
|
847
|
+
* function draw() {
|
|
848
|
+
* background(200);
|
|
849
|
+
*
|
|
850
|
+
* // Draw a square at (30, 20).
|
|
851
|
+
* square(30, 20, 40);
|
|
852
|
+
*
|
|
853
|
+
* // Create a p5.Vector object.
|
|
854
|
+
* let v = createVector(0.5, 1.3);
|
|
855
|
+
*
|
|
856
|
+
* // Scale the coordinate system by factors of
|
|
857
|
+
* // 0.5 along the x-axis and
|
|
858
|
+
* // 1.3 along the y-axis.
|
|
859
|
+
* scale(v);
|
|
860
|
+
*
|
|
861
|
+
* // Draw a square at (30, 20).
|
|
862
|
+
* // It appears as a rectangle at (15, 26) after scaling.
|
|
863
|
+
* square(30, 20, 40);
|
|
864
|
+
* }
|
|
865
|
+
* </code>
|
|
866
|
+
* </div>
|
|
867
|
+
*
|
|
868
|
+
* <div>
|
|
869
|
+
* <code>
|
|
870
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
871
|
+
*
|
|
872
|
+
* function setup() {
|
|
873
|
+
* createCanvas(100, 100, WEBGL);
|
|
874
|
+
*
|
|
875
|
+
* describe(
|
|
876
|
+
* 'A red box and a blue box drawn on a gray background. The red box appears embedded in the blue box.'
|
|
877
|
+
* );
|
|
878
|
+
* }
|
|
879
|
+
*
|
|
880
|
+
* function draw() {
|
|
881
|
+
* background(200);
|
|
882
|
+
*
|
|
883
|
+
* // Enable orbiting with the mouse.
|
|
884
|
+
* orbitControl();
|
|
885
|
+
*
|
|
886
|
+
* // Turn on the lights.
|
|
887
|
+
* lights();
|
|
888
|
+
*
|
|
889
|
+
* // Style the spheres.
|
|
890
|
+
* noStroke();
|
|
891
|
+
*
|
|
892
|
+
* // Draw the red sphere.
|
|
893
|
+
* fill('red');
|
|
894
|
+
* box();
|
|
895
|
+
*
|
|
896
|
+
* // Scale the coordinate system by factors of
|
|
897
|
+
* // 0.5 along the x-axis and
|
|
898
|
+
* // 1.3 along the y-axis and
|
|
899
|
+
* // 2 along the z-axis.
|
|
900
|
+
* scale(0.5, 1.3, 2);
|
|
901
|
+
*
|
|
902
|
+
* // Draw the blue sphere.
|
|
903
|
+
* fill('blue');
|
|
904
|
+
* box();
|
|
905
|
+
* }
|
|
906
|
+
* </code>
|
|
907
|
+
* </div>
|
|
908
|
+
*/
|
|
909
|
+
function scale(s: number | p5.Vector | number[], y?: number, z?: number): void;
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* @param vector whose components should be used to scale.
|
|
913
|
+
*/
|
|
914
|
+
function scale(scales: p5.Vector | number[]): void;
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
* Shears the x-axis so that shapes appear skewed.By default, the x- and y-axes are perpendicular. The `shearX()` function
|
|
918
|
+
* transforms the coordinate system so that x-coordinates are translated while
|
|
919
|
+
* y-coordinates are fixed.The first parameter, `angle`, is the amount to shear. For example, calling
|
|
920
|
+
* `shearX(1)` transforms all x-coordinates using the formula
|
|
921
|
+
* `x = x + y * tan(angle)`. `shearX()` interprets angle values using the
|
|
922
|
+
* current angleMode().By default, transformations accumulate. For example, calling
|
|
923
|
+
* `shearX(1)` twice has the same effect as calling `shearX(2)` once. The
|
|
924
|
+
* push() and
|
|
925
|
+
* pop() functions can be used to isolate
|
|
926
|
+
* transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
927
|
+
* `shearX(1)` inside the draw() function won't
|
|
928
|
+
* cause shapes to shear continuously.
|
|
929
|
+
*
|
|
930
|
+
* @param angle to shear by in the current <a href="#/p5/angleMode">angleMode()</a>.
|
|
931
|
+
* @example <div>
|
|
932
|
+
* <code>
|
|
933
|
+
* function setup() {
|
|
934
|
+
* createCanvas(100, 100);
|
|
935
|
+
*
|
|
936
|
+
* describe('A white quadrilateral on a gray background.');
|
|
937
|
+
* }
|
|
938
|
+
*
|
|
939
|
+
* function draw() {
|
|
940
|
+
* background(200);
|
|
941
|
+
*
|
|
942
|
+
* // Shear the coordinate system along the x-axis.
|
|
943
|
+
* shearX(QUARTER_PI);
|
|
944
|
+
*
|
|
945
|
+
* // Draw the square.
|
|
946
|
+
* square(0, 0, 50);
|
|
947
|
+
* }
|
|
948
|
+
* </code>
|
|
949
|
+
* </div>
|
|
950
|
+
*
|
|
951
|
+
* <div>
|
|
952
|
+
* <code>
|
|
953
|
+
* function setup() {
|
|
954
|
+
* createCanvas(100, 100);
|
|
955
|
+
*
|
|
956
|
+
* // Use degrees.
|
|
957
|
+
* angleMode(DEGREES);
|
|
958
|
+
*
|
|
959
|
+
* describe('A white quadrilateral on a gray background.');
|
|
960
|
+
* }
|
|
961
|
+
*
|
|
962
|
+
* function draw() {
|
|
963
|
+
* background(200);
|
|
964
|
+
*
|
|
965
|
+
* // Shear the coordinate system along the x-axis.
|
|
966
|
+
* shearX(45);
|
|
967
|
+
*
|
|
968
|
+
* // Draw the square.
|
|
969
|
+
* square(0, 0, 50);
|
|
970
|
+
* }
|
|
971
|
+
* </code>
|
|
972
|
+
* </div>
|
|
973
|
+
*/
|
|
974
|
+
function shearX(angle: number): void;
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Shears the y-axis so that shapes appear skewed.By default, the x- and y-axes are perpendicular. The `shearY()` function
|
|
978
|
+
* transforms the coordinate system so that y-coordinates are translated while
|
|
979
|
+
* x-coordinates are fixed.The first parameter, `angle`, is the amount to shear. For example, calling
|
|
980
|
+
* `shearY(1)` transforms all y-coordinates using the formula
|
|
981
|
+
* `y = y + x * tan(angle)`. `shearY()` interprets angle values using the
|
|
982
|
+
* current angleMode().By default, transformations accumulate. For example, calling
|
|
983
|
+
* `shearY(1)` twice has the same effect as calling `shearY(2)` once. The
|
|
984
|
+
* push() and
|
|
985
|
+
* pop() functions can be used to isolate
|
|
986
|
+
* transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
987
|
+
* `shearY(1)` inside the draw() function won't
|
|
988
|
+
* cause shapes to shear continuously.
|
|
989
|
+
*
|
|
990
|
+
* @param angle to shear by in the current <a href="#/p5/angleMode">angleMode()</a>.
|
|
991
|
+
* @example <div>
|
|
992
|
+
* <code>
|
|
993
|
+
* function setup() {
|
|
994
|
+
* createCanvas(100, 100);
|
|
995
|
+
*
|
|
996
|
+
* describe('A white quadrilateral on a gray background.');
|
|
997
|
+
* }
|
|
998
|
+
*
|
|
999
|
+
* function draw() {
|
|
1000
|
+
* background(200);
|
|
1001
|
+
*
|
|
1002
|
+
* // Shear the coordinate system along the x-axis.
|
|
1003
|
+
* shearY(QUARTER_PI);
|
|
1004
|
+
*
|
|
1005
|
+
* // Draw the square.
|
|
1006
|
+
* square(0, 0, 50);
|
|
1007
|
+
* }
|
|
1008
|
+
* </code>
|
|
1009
|
+
* </div>
|
|
1010
|
+
*
|
|
1011
|
+
* <div>
|
|
1012
|
+
* <code>
|
|
1013
|
+
* function setup() {
|
|
1014
|
+
* createCanvas(100, 100);
|
|
1015
|
+
*
|
|
1016
|
+
* // Use degrees.
|
|
1017
|
+
* angleMode(DEGREES);
|
|
1018
|
+
*
|
|
1019
|
+
* describe('A white quadrilateral on a gray background.');
|
|
1020
|
+
* }
|
|
1021
|
+
*
|
|
1022
|
+
* function draw() {
|
|
1023
|
+
* background(200);
|
|
1024
|
+
*
|
|
1025
|
+
* // Shear the coordinate system along the x-axis.
|
|
1026
|
+
* shearY(45);
|
|
1027
|
+
*
|
|
1028
|
+
* // Draw the square.
|
|
1029
|
+
* square(0, 0, 50);
|
|
1030
|
+
* }
|
|
1031
|
+
* </code>
|
|
1032
|
+
* </div>
|
|
1033
|
+
*/
|
|
1034
|
+
function shearY(angle: number): void;
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Translates the coordinate system.By default, the origin `(0, 0)` is at the sketch's top-left corner in 2D
|
|
1038
|
+
* mode and center in WebGL mode. The `translate()` function shifts the origin
|
|
1039
|
+
* to a different position. Everything drawn after `translate()` is called
|
|
1040
|
+
* will appear to be shifted. There are two ways to call `translate()` with
|
|
1041
|
+
* parameters that set the origin's position.The first way to call `translate()` uses numbers to set the amount of
|
|
1042
|
+
* translation. The first two parameters, `x` and `y`, set the amount to
|
|
1043
|
+
* translate along the positive x- and y-axes. For example, calling
|
|
1044
|
+
* `translate(20, 30)` translates the origin 20 pixels along the x-axis and 30
|
|
1045
|
+
* pixels along the y-axis. The third parameter, `z`, is optional. It sets the
|
|
1046
|
+
* amount to translate along the positive z-axis. For example, calling
|
|
1047
|
+
* `translate(20, 30, 40)` translates the origin 20 pixels along the x-axis,
|
|
1048
|
+
* 30 pixels along the y-axis, and 40 pixels along the z-axis.The second way to call `translate()` uses a
|
|
1049
|
+
* p5.Vector object to set the amount of
|
|
1050
|
+
* translation. For example, calling `translate(myVector)` uses the x-, y-,
|
|
1051
|
+
* and z-components of `myVector` to set the amount to translate along the x-,
|
|
1052
|
+
* y-, and z-axes. Doing so is the same as calling
|
|
1053
|
+
* `translate(myVector.x, myVector.y, myVector.z)`.By default, transformations accumulate. For example, calling
|
|
1054
|
+
* `translate(10, 0)` twice has the same effect as calling
|
|
1055
|
+
* `translate(20, 0)` once. The push() and
|
|
1056
|
+
* pop() functions can be used to isolate
|
|
1057
|
+
* transformations within distinct drawing groups.Note: Transformations are reset at the beginning of the draw loop. Calling
|
|
1058
|
+
* `translate(10, 0)` inside the draw() function won't
|
|
1059
|
+
* cause shapes to move continuously.
|
|
1060
|
+
*
|
|
1061
|
+
* @param amount to translate along the positive x-axis.
|
|
1062
|
+
* @param amount to translate along the positive y-axis.
|
|
1063
|
+
* @param amount to translate along the positive z-axis.
|
|
1064
|
+
* @example <div>
|
|
1065
|
+
* <code>
|
|
1066
|
+
* function setup() {
|
|
1067
|
+
* createCanvas(100, 100);
|
|
1068
|
+
*
|
|
1069
|
+
* describe('A white circle on a gray background.');
|
|
1070
|
+
* }
|
|
1071
|
+
*
|
|
1072
|
+
* function draw() {
|
|
1073
|
+
* background(200);
|
|
1074
|
+
*
|
|
1075
|
+
* // Translate the origin to the center.
|
|
1076
|
+
* translate(50, 50);
|
|
1077
|
+
*
|
|
1078
|
+
* // Draw a circle at coordinates (0, 0).
|
|
1079
|
+
* circle(0, 0, 40);
|
|
1080
|
+
* }
|
|
1081
|
+
* </code>
|
|
1082
|
+
* </div>
|
|
1083
|
+
*
|
|
1084
|
+
* <div>
|
|
1085
|
+
* <code>
|
|
1086
|
+
* function setup() {
|
|
1087
|
+
* createCanvas(100, 100);
|
|
1088
|
+
*
|
|
1089
|
+
* describe(
|
|
1090
|
+
* 'Two circles drawn on a gray background. The blue circle on the right overlaps the red circle at the center.'
|
|
1091
|
+
* );
|
|
1092
|
+
* }
|
|
1093
|
+
*
|
|
1094
|
+
* function draw() {
|
|
1095
|
+
* background(200);
|
|
1096
|
+
*
|
|
1097
|
+
* // Translate the origin to the center.
|
|
1098
|
+
* translate(50, 50);
|
|
1099
|
+
*
|
|
1100
|
+
* // Draw the red circle.
|
|
1101
|
+
* fill('red');
|
|
1102
|
+
* circle(0, 0, 40);
|
|
1103
|
+
*
|
|
1104
|
+
* // Translate the origin to the right.
|
|
1105
|
+
* translate(25, 0);
|
|
1106
|
+
*
|
|
1107
|
+
* // Draw the blue circle.
|
|
1108
|
+
* fill('blue');
|
|
1109
|
+
* circle(0, 0, 40);
|
|
1110
|
+
* }
|
|
1111
|
+
* </code>
|
|
1112
|
+
* </div>
|
|
1113
|
+
*
|
|
1114
|
+
* <div>
|
|
1115
|
+
* <code>
|
|
1116
|
+
* function setup() {
|
|
1117
|
+
* createCanvas(100, 100);
|
|
1118
|
+
*
|
|
1119
|
+
* describe('A white circle moves slowly from left to right on a gray background.');
|
|
1120
|
+
* }
|
|
1121
|
+
*
|
|
1122
|
+
* function draw() {
|
|
1123
|
+
* background(200);
|
|
1124
|
+
*
|
|
1125
|
+
* // Calculate the x-coordinate.
|
|
1126
|
+
* let x = frameCount * 0.2;
|
|
1127
|
+
*
|
|
1128
|
+
* // Translate the origin.
|
|
1129
|
+
* translate(x, 50);
|
|
1130
|
+
*
|
|
1131
|
+
* // Draw a circle at coordinates (0, 0).
|
|
1132
|
+
* circle(0, 0, 40);
|
|
1133
|
+
* }
|
|
1134
|
+
* </code>
|
|
1135
|
+
* </div>
|
|
1136
|
+
*
|
|
1137
|
+
* <div>
|
|
1138
|
+
* <code>
|
|
1139
|
+
* function setup() {
|
|
1140
|
+
* createCanvas(100, 100);
|
|
1141
|
+
*
|
|
1142
|
+
* describe('A white circle on a gray background.');
|
|
1143
|
+
* }
|
|
1144
|
+
*
|
|
1145
|
+
* function draw() {
|
|
1146
|
+
* background(200);
|
|
1147
|
+
*
|
|
1148
|
+
* // Create a p5.Vector object.
|
|
1149
|
+
* let v = createVector(50, 50);
|
|
1150
|
+
*
|
|
1151
|
+
* // Translate the origin by the vector.
|
|
1152
|
+
* translate(v);
|
|
1153
|
+
*
|
|
1154
|
+
* // Draw a circle at coordinates (0, 0).
|
|
1155
|
+
* circle(0, 0, 40);
|
|
1156
|
+
* }
|
|
1157
|
+
* </code>
|
|
1158
|
+
* </div>
|
|
1159
|
+
*
|
|
1160
|
+
* <div>
|
|
1161
|
+
* <code>
|
|
1162
|
+
* function setup() {
|
|
1163
|
+
* createCanvas(100, 100, WEBGL);
|
|
1164
|
+
*
|
|
1165
|
+
* describe(
|
|
1166
|
+
* 'Two spheres sitting side-by-side on gray background. The sphere at the center is red. The sphere on the right is blue.'
|
|
1167
|
+
* );
|
|
1168
|
+
* }
|
|
1169
|
+
*
|
|
1170
|
+
* function draw() {
|
|
1171
|
+
* background(200);
|
|
1172
|
+
*
|
|
1173
|
+
* // Turn on the lights.
|
|
1174
|
+
* lights();
|
|
1175
|
+
*
|
|
1176
|
+
* // Style the spheres.
|
|
1177
|
+
* noStroke();
|
|
1178
|
+
*
|
|
1179
|
+
* // Draw the red sphere.
|
|
1180
|
+
* fill('red');
|
|
1181
|
+
* sphere(10);
|
|
1182
|
+
*
|
|
1183
|
+
* // Translate the origin to the right.
|
|
1184
|
+
* translate(30, 0, 0);
|
|
1185
|
+
*
|
|
1186
|
+
* // Draw the blue sphere.
|
|
1187
|
+
* fill('blue');
|
|
1188
|
+
* sphere(10);
|
|
1189
|
+
* }
|
|
1190
|
+
* </code>
|
|
1191
|
+
* </div>
|
|
1192
|
+
*/
|
|
1193
|
+
function translate(x: number, y: number, z?: number): void;
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* @param vector by which to translate.
|
|
1197
|
+
*/
|
|
1198
|
+
function translate(vector: p5.Vector): void;
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* Begins a drawing group that contains its own styles and transformations.By default, styles such as fill() and
|
|
1202
|
+
* transformations such as rotate() are applied to
|
|
1203
|
+
* all drawing that follows. The `push()` and pop()
|
|
1204
|
+
* functions can limit the effect of styles and transformations to a specific
|
|
1205
|
+
* group of shapes, images, and text. For example, a group of shapes could be
|
|
1206
|
+
* translated to follow the mouse without affecting the rest of the sketch:`// Begin the drawing group.
|
|
1207
|
+
* push();
|
|
1208
|
+
*
|
|
1209
|
+
* // Translate the origin to the mouse's position.
|
|
1210
|
+
* translate(mouseX, mouseY);
|
|
1211
|
+
*
|
|
1212
|
+
* // Style the face.
|
|
1213
|
+
* noStroke();
|
|
1214
|
+
* fill('green');
|
|
1215
|
+
*
|
|
1216
|
+
* // Draw the face.
|
|
1217
|
+
* circle(0, 0, 60);
|
|
1218
|
+
*
|
|
1219
|
+
* // Style the eyes.
|
|
1220
|
+
* fill('white');
|
|
1221
|
+
*
|
|
1222
|
+
* // Draw the left eye.
|
|
1223
|
+
* ellipse(-20, -20, 30, 20);
|
|
1224
|
+
*
|
|
1225
|
+
* // Draw the right eye.
|
|
1226
|
+
* ellipse(20, -20, 30, 20);
|
|
1227
|
+
*
|
|
1228
|
+
* // End the drawing group.
|
|
1229
|
+
* pop();
|
|
1230
|
+
*
|
|
1231
|
+
* // Draw a bug.
|
|
1232
|
+
* let x = random(0, 100);
|
|
1233
|
+
* let y = random(0, 100);
|
|
1234
|
+
* text('🦟', x, y);`In the code snippet above, the bug's position isn't affected by
|
|
1235
|
+
* `translate(mouseX, mouseY)` because that transformation is contained
|
|
1236
|
+
* between `push()` and pop(). The bug moves around
|
|
1237
|
+
* the entire canvas as expected.Note: `push()` and pop() are always called as a
|
|
1238
|
+
* pair. Both functions are required to begin and end a drawing group.`push()` and pop() can also be nested to create
|
|
1239
|
+
* subgroups. For example, the code snippet above could be changed to give
|
|
1240
|
+
* more detail to the frog’s eyes:`// Begin the drawing group.
|
|
1241
|
+
* push();
|
|
1242
|
+
*
|
|
1243
|
+
* // Translate the origin to the mouse's position.
|
|
1244
|
+
* translate(mouseX, mouseY);
|
|
1245
|
+
*
|
|
1246
|
+
* // Style the face.
|
|
1247
|
+
* noStroke();
|
|
1248
|
+
* fill('green');
|
|
1249
|
+
*
|
|
1250
|
+
* // Draw a face.
|
|
1251
|
+
* circle(0, 0, 60);
|
|
1252
|
+
*
|
|
1253
|
+
* // Style the eyes.
|
|
1254
|
+
* fill('white');
|
|
1255
|
+
*
|
|
1256
|
+
* // Draw the left eye.
|
|
1257
|
+
* push();
|
|
1258
|
+
* translate(-20, -20);
|
|
1259
|
+
* ellipse(0, 0, 30, 20);
|
|
1260
|
+
* fill('black');
|
|
1261
|
+
* circle(0, 0, 8);
|
|
1262
|
+
* pop();
|
|
1263
|
+
*
|
|
1264
|
+
* // Draw the right eye.
|
|
1265
|
+
* push();
|
|
1266
|
+
* translate(20, -20);
|
|
1267
|
+
* ellipse(0, 0, 30, 20);
|
|
1268
|
+
* fill('black');
|
|
1269
|
+
* circle(0, 0, 8);
|
|
1270
|
+
* pop();
|
|
1271
|
+
*
|
|
1272
|
+
* // End the drawing group.
|
|
1273
|
+
* pop();
|
|
1274
|
+
*
|
|
1275
|
+
* // Draw a bug.
|
|
1276
|
+
* let x = random(0, 100);
|
|
1277
|
+
* let y = random(0, 100);
|
|
1278
|
+
* text('🦟', x, y);`In this version, the code to draw each eye is contained between its own
|
|
1279
|
+
* `push()` and pop() functions. Doing so makes it
|
|
1280
|
+
* easier to add details in the correct part of a drawing.`push()` and pop() contain the effects of the
|
|
1281
|
+
* following functions:In WebGL mode, `push()` and pop() contain the
|
|
1282
|
+
* effects of a few additional styles:
|
|
1283
|
+
*
|
|
1284
|
+
* @example <div>
|
|
1285
|
+
* <code>
|
|
1286
|
+
* function setup() {
|
|
1287
|
+
* createCanvas(100, 100);
|
|
1288
|
+
*
|
|
1289
|
+
* background(200);
|
|
1290
|
+
*
|
|
1291
|
+
* // Draw the left circle.
|
|
1292
|
+
* circle(25, 50, 20);
|
|
1293
|
+
*
|
|
1294
|
+
* // Begin the drawing group.
|
|
1295
|
+
* push();
|
|
1296
|
+
*
|
|
1297
|
+
* // Translate the origin to the center.
|
|
1298
|
+
* translate(50, 50);
|
|
1299
|
+
*
|
|
1300
|
+
* // Style the circle.
|
|
1301
|
+
* strokeWeight(5);
|
|
1302
|
+
* stroke('royalblue');
|
|
1303
|
+
* fill('orange');
|
|
1304
|
+
*
|
|
1305
|
+
* // Draw the circle.
|
|
1306
|
+
* circle(0, 0, 20);
|
|
1307
|
+
*
|
|
1308
|
+
* // End the drawing group.
|
|
1309
|
+
* pop();
|
|
1310
|
+
*
|
|
1311
|
+
* // Draw the right circle.
|
|
1312
|
+
* circle(75, 50, 20);
|
|
1313
|
+
*
|
|
1314
|
+
* describe(
|
|
1315
|
+
* 'Three circles drawn in a row on a gray background. The left and right circles are white with thin, black borders. The middle circle is orange with a thick, blue border.'
|
|
1316
|
+
* );
|
|
1317
|
+
* }
|
|
1318
|
+
* </code>
|
|
1319
|
+
* </div>
|
|
1320
|
+
*
|
|
1321
|
+
* <div>
|
|
1322
|
+
* <code>
|
|
1323
|
+
* function setup() {
|
|
1324
|
+
* createCanvas(100, 100);
|
|
1325
|
+
*
|
|
1326
|
+
* // Slow the frame rate.
|
|
1327
|
+
* frameRate(24);
|
|
1328
|
+
*
|
|
1329
|
+
* describe('A mosquito buzzes in front of a green frog. The frog follows the mouse as the user moves.');
|
|
1330
|
+
* }
|
|
1331
|
+
*
|
|
1332
|
+
* function draw() {
|
|
1333
|
+
* background(200);
|
|
1334
|
+
*
|
|
1335
|
+
* // Begin the drawing group.
|
|
1336
|
+
* push();
|
|
1337
|
+
*
|
|
1338
|
+
* // Translate the origin to the mouse's position.
|
|
1339
|
+
* translate(mouseX, mouseY);
|
|
1340
|
+
*
|
|
1341
|
+
* // Style the face.
|
|
1342
|
+
* noStroke();
|
|
1343
|
+
* fill('green');
|
|
1344
|
+
*
|
|
1345
|
+
* // Draw a face.
|
|
1346
|
+
* circle(0, 0, 60);
|
|
1347
|
+
*
|
|
1348
|
+
* // Style the eyes.
|
|
1349
|
+
* fill('white');
|
|
1350
|
+
*
|
|
1351
|
+
* // Draw the left eye.
|
|
1352
|
+
* push();
|
|
1353
|
+
* translate(-20, -20);
|
|
1354
|
+
* ellipse(0, 0, 30, 20);
|
|
1355
|
+
* fill('black');
|
|
1356
|
+
* circle(0, 0, 8);
|
|
1357
|
+
* pop();
|
|
1358
|
+
*
|
|
1359
|
+
* // Draw the right eye.
|
|
1360
|
+
* push();
|
|
1361
|
+
* translate(20, -20);
|
|
1362
|
+
* ellipse(0, 0, 30, 20);
|
|
1363
|
+
* fill('black');
|
|
1364
|
+
* circle(0, 0, 8);
|
|
1365
|
+
* pop();
|
|
1366
|
+
*
|
|
1367
|
+
* // End the drawing group.
|
|
1368
|
+
* pop();
|
|
1369
|
+
*
|
|
1370
|
+
* // Draw a bug.
|
|
1371
|
+
* let x = random(0, 100);
|
|
1372
|
+
* let y = random(0, 100);
|
|
1373
|
+
* text('🦟', x, y);
|
|
1374
|
+
* }
|
|
1375
|
+
* </code>
|
|
1376
|
+
* </div>
|
|
1377
|
+
*
|
|
1378
|
+
* <div>
|
|
1379
|
+
* <code>
|
|
1380
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
1381
|
+
*
|
|
1382
|
+
* function setup() {
|
|
1383
|
+
* createCanvas(100, 100, WEBGL);
|
|
1384
|
+
*
|
|
1385
|
+
* describe(
|
|
1386
|
+
* 'Two spheres drawn on a gray background. The sphere on the left is red and lit from the front. The sphere on the right is a blue wireframe.'
|
|
1387
|
+
* );
|
|
1388
|
+
* }
|
|
1389
|
+
*
|
|
1390
|
+
* function draw() {
|
|
1391
|
+
* background(200);
|
|
1392
|
+
*
|
|
1393
|
+
* // Enable orbiting with the mouse.
|
|
1394
|
+
* orbitControl();
|
|
1395
|
+
*
|
|
1396
|
+
* // Draw the red sphere.
|
|
1397
|
+
* push();
|
|
1398
|
+
* translate(-25, 0, 0);
|
|
1399
|
+
* noStroke();
|
|
1400
|
+
* directionalLight(255, 0, 0, 0, 0, -1);
|
|
1401
|
+
* sphere(20);
|
|
1402
|
+
* pop();
|
|
1403
|
+
*
|
|
1404
|
+
* // Draw the blue sphere.
|
|
1405
|
+
* push();
|
|
1406
|
+
* translate(25, 0, 0);
|
|
1407
|
+
* strokeWeight(0.3);
|
|
1408
|
+
* stroke(0, 0, 255);
|
|
1409
|
+
* noFill();
|
|
1410
|
+
* sphere(20);
|
|
1411
|
+
* pop();
|
|
1412
|
+
* }
|
|
1413
|
+
* </code>
|
|
1414
|
+
* </div>
|
|
1415
|
+
*/
|
|
1416
|
+
function push(): void;
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* Ends a drawing group that contains its own styles and transformations.By default, styles such as fill() and
|
|
1420
|
+
* transformations such as rotate() are applied to
|
|
1421
|
+
* all drawing that follows. The push() and `pop()`
|
|
1422
|
+
* functions can limit the effect of styles and transformations to a specific
|
|
1423
|
+
* group of shapes, images, and text. For example, a group of shapes could be
|
|
1424
|
+
* translated to follow the mouse without affecting the rest of the sketch:`// Begin the drawing group.
|
|
1425
|
+
* push();
|
|
1426
|
+
*
|
|
1427
|
+
* // Translate the origin to the mouse's position.
|
|
1428
|
+
* translate(mouseX, mouseY);
|
|
1429
|
+
*
|
|
1430
|
+
* // Style the face.
|
|
1431
|
+
* noStroke();
|
|
1432
|
+
* fill('green');
|
|
1433
|
+
*
|
|
1434
|
+
* // Draw the face.
|
|
1435
|
+
* circle(0, 0, 60);
|
|
1436
|
+
*
|
|
1437
|
+
* // Style the eyes.
|
|
1438
|
+
* fill('white');
|
|
1439
|
+
*
|
|
1440
|
+
* // Draw the left eye.
|
|
1441
|
+
* ellipse(-20, -20, 30, 20);
|
|
1442
|
+
*
|
|
1443
|
+
* // Draw the right eye.
|
|
1444
|
+
* ellipse(20, -20, 30, 20);
|
|
1445
|
+
*
|
|
1446
|
+
* // End the drawing group.
|
|
1447
|
+
* pop();
|
|
1448
|
+
*
|
|
1449
|
+
* // Draw a bug.
|
|
1450
|
+
* let x = random(0, 100);
|
|
1451
|
+
* let y = random(0, 100);
|
|
1452
|
+
* text('🦟', x, y);`In the code snippet above, the bug's position isn't affected by
|
|
1453
|
+
* `translate(mouseX, mouseY)` because that transformation is contained
|
|
1454
|
+
* between push() and `pop()`. The bug moves around
|
|
1455
|
+
* the entire canvas as expected.Note: push() and `pop()` are always called as a
|
|
1456
|
+
* pair. Both functions are required to begin and end a drawing group.push() and `pop()` can also be nested to create
|
|
1457
|
+
* subgroups. For example, the code snippet above could be changed to give
|
|
1458
|
+
* more detail to the frog’s eyes:`// Begin the drawing group.
|
|
1459
|
+
* push();
|
|
1460
|
+
*
|
|
1461
|
+
* // Translate the origin to the mouse's position.
|
|
1462
|
+
* translate(mouseX, mouseY);
|
|
1463
|
+
*
|
|
1464
|
+
* // Style the face.
|
|
1465
|
+
* noStroke();
|
|
1466
|
+
* fill('green');
|
|
1467
|
+
*
|
|
1468
|
+
* // Draw a face.
|
|
1469
|
+
* circle(0, 0, 60);
|
|
1470
|
+
*
|
|
1471
|
+
* // Style the eyes.
|
|
1472
|
+
* fill('white');
|
|
1473
|
+
*
|
|
1474
|
+
* // Draw the left eye.
|
|
1475
|
+
* push();
|
|
1476
|
+
* translate(-20, -20);
|
|
1477
|
+
* ellipse(0, 0, 30, 20);
|
|
1478
|
+
* fill('black');
|
|
1479
|
+
* circle(0, 0, 8);
|
|
1480
|
+
* pop();
|
|
1481
|
+
*
|
|
1482
|
+
* // Draw the right eye.
|
|
1483
|
+
* push();
|
|
1484
|
+
* translate(20, -20);
|
|
1485
|
+
* ellipse(0, 0, 30, 20);
|
|
1486
|
+
* fill('black');
|
|
1487
|
+
* circle(0, 0, 8);
|
|
1488
|
+
* pop();
|
|
1489
|
+
*
|
|
1490
|
+
* // End the drawing group.
|
|
1491
|
+
* pop();
|
|
1492
|
+
*
|
|
1493
|
+
* // Draw a bug.
|
|
1494
|
+
* let x = random(0, 100);
|
|
1495
|
+
* let y = random(0, 100);
|
|
1496
|
+
* text('🦟', x, y);`In this version, the code to draw each eye is contained between its own
|
|
1497
|
+
* push() and `pop()` functions. Doing so makes it
|
|
1498
|
+
* easier to add details in the correct part of a drawing.push() and `pop()` contain the effects of the
|
|
1499
|
+
* following functions:In WebGL mode, push() and `pop()` contain the
|
|
1500
|
+
* effects of a few additional styles:
|
|
1501
|
+
*
|
|
1502
|
+
* @example <div>
|
|
1503
|
+
* <code>
|
|
1504
|
+
* function setup() {
|
|
1505
|
+
* createCanvas(100, 100);
|
|
1506
|
+
*
|
|
1507
|
+
* background(200);
|
|
1508
|
+
*
|
|
1509
|
+
* // Draw the left circle.
|
|
1510
|
+
* circle(25, 50, 20);
|
|
1511
|
+
*
|
|
1512
|
+
* // Begin the drawing group.
|
|
1513
|
+
* push();
|
|
1514
|
+
*
|
|
1515
|
+
* // Translate the origin to the center.
|
|
1516
|
+
* translate(50, 50);
|
|
1517
|
+
*
|
|
1518
|
+
* // Style the circle.
|
|
1519
|
+
* strokeWeight(5);
|
|
1520
|
+
* stroke('royalblue');
|
|
1521
|
+
* fill('orange');
|
|
1522
|
+
*
|
|
1523
|
+
* // Draw the circle.
|
|
1524
|
+
* circle(0, 0, 20);
|
|
1525
|
+
*
|
|
1526
|
+
* // End the drawing group.
|
|
1527
|
+
* pop();
|
|
1528
|
+
*
|
|
1529
|
+
* // Draw the right circle.
|
|
1530
|
+
* circle(75, 50, 20);
|
|
1531
|
+
*
|
|
1532
|
+
* describe(
|
|
1533
|
+
* 'Three circles drawn in a row on a gray background. The left and right circles are white with thin, black borders. The middle circle is orange with a thick, blue border.'
|
|
1534
|
+
* );
|
|
1535
|
+
* }
|
|
1536
|
+
* </code>
|
|
1537
|
+
* </div>
|
|
1538
|
+
*
|
|
1539
|
+
* <div>
|
|
1540
|
+
* <code>
|
|
1541
|
+
* function setup() {
|
|
1542
|
+
* createCanvas(100, 100);
|
|
1543
|
+
*
|
|
1544
|
+
* // Slow the frame rate.
|
|
1545
|
+
* frameRate(24);
|
|
1546
|
+
*
|
|
1547
|
+
* describe('A mosquito buzzes in front of a green frog. The frog follows the mouse as the user moves.');
|
|
1548
|
+
* }
|
|
1549
|
+
*
|
|
1550
|
+
* function draw() {
|
|
1551
|
+
* background(200);
|
|
1552
|
+
*
|
|
1553
|
+
* // Begin the drawing group.
|
|
1554
|
+
* push();
|
|
1555
|
+
*
|
|
1556
|
+
* // Translate the origin to the mouse's position.
|
|
1557
|
+
* translate(mouseX, mouseY);
|
|
1558
|
+
*
|
|
1559
|
+
* // Style the face.
|
|
1560
|
+
* noStroke();
|
|
1561
|
+
* fill('green');
|
|
1562
|
+
*
|
|
1563
|
+
* // Draw a face.
|
|
1564
|
+
* circle(0, 0, 60);
|
|
1565
|
+
*
|
|
1566
|
+
* // Style the eyes.
|
|
1567
|
+
* fill('white');
|
|
1568
|
+
*
|
|
1569
|
+
* // Draw the left eye.
|
|
1570
|
+
* push();
|
|
1571
|
+
* translate(-20, -20);
|
|
1572
|
+
* ellipse(0, 0, 30, 20);
|
|
1573
|
+
* fill('black');
|
|
1574
|
+
* circle(0, 0, 8);
|
|
1575
|
+
* pop();
|
|
1576
|
+
*
|
|
1577
|
+
* // Draw the right eye.
|
|
1578
|
+
* push();
|
|
1579
|
+
* translate(20, -20);
|
|
1580
|
+
* ellipse(0, 0, 30, 20);
|
|
1581
|
+
* fill('black');
|
|
1582
|
+
* circle(0, 0, 8);
|
|
1583
|
+
* pop();
|
|
1584
|
+
*
|
|
1585
|
+
* // End the drawing group.
|
|
1586
|
+
* pop();
|
|
1587
|
+
*
|
|
1588
|
+
* // Draw a bug.
|
|
1589
|
+
* let x = random(0, 100);
|
|
1590
|
+
* let y = random(0, 100);
|
|
1591
|
+
* text('🦟', x, y);
|
|
1592
|
+
* }
|
|
1593
|
+
* </code>
|
|
1594
|
+
* </div>
|
|
1595
|
+
*
|
|
1596
|
+
* <div>
|
|
1597
|
+
* <code>
|
|
1598
|
+
* // Click and drag the mouse to view the scene from different angles.
|
|
1599
|
+
*
|
|
1600
|
+
* function setup() {
|
|
1601
|
+
* createCanvas(100, 100, WEBGL);
|
|
1602
|
+
*
|
|
1603
|
+
* describe(
|
|
1604
|
+
* 'Two spheres drawn on a gray background. The sphere on the left is red and lit from the front. The sphere on the right is a blue wireframe.'
|
|
1605
|
+
* );
|
|
1606
|
+
* }
|
|
1607
|
+
*
|
|
1608
|
+
* function draw() {
|
|
1609
|
+
* background(200);
|
|
1610
|
+
*
|
|
1611
|
+
* // Enable orbiting with the mouse.
|
|
1612
|
+
* orbitControl();
|
|
1613
|
+
*
|
|
1614
|
+
* // Draw the red sphere.
|
|
1615
|
+
* push();
|
|
1616
|
+
* translate(-25, 0, 0);
|
|
1617
|
+
* noStroke();
|
|
1618
|
+
* directionalLight(255, 0, 0, 0, 0, -1);
|
|
1619
|
+
* sphere(20);
|
|
1620
|
+
* pop();
|
|
1621
|
+
*
|
|
1622
|
+
* // Draw the blue sphere.
|
|
1623
|
+
* push();
|
|
1624
|
+
* translate(25, 0, 0);
|
|
1625
|
+
* strokeWeight(0.3);
|
|
1626
|
+
* stroke(0, 0, 255);
|
|
1627
|
+
* noFill();
|
|
1628
|
+
* sphere(20);
|
|
1629
|
+
* pop();
|
|
1630
|
+
* }
|
|
1631
|
+
* </code>
|
|
1632
|
+
* </div>
|
|
1633
|
+
*/
|
|
1634
|
+
function pop(): void;
|
|
1635
|
+
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
export default function transform(p5: any, fn: any): void;
|