q5 2.6.1 → 2.7.0
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/package.json +2 -3
- package/q5.d.ts +697 -564
- package/q5.js +43 -26
- package/q5.min.js +2 -2
- package/src/q5-2d-drawing.js +1 -1
- package/src/q5-2d-image.js +2 -1
- package/src/q5-ai.js +2 -3
- package/src/q5-canvas.js +7 -0
- package/src/q5-core.js +28 -18
- package/src/q5-input.js +3 -3
package/q5.d.ts
CHANGED
|
@@ -5,30 +5,38 @@
|
|
|
5
5
|
* for autocompletion, hover over documentation, and type checking.
|
|
6
6
|
*/
|
|
7
7
|
declare global {
|
|
8
|
-
|
|
9
|
-
// ⭐️ core
|
|
8
|
+
// ⭐️ core
|
|
10
9
|
|
|
10
|
+
class Q5 {
|
|
11
11
|
/** ⭐️
|
|
12
12
|
* Creates an instance of Q5.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param parent - element that the canvas will be placed inside
|
|
14
|
+
* Running `new Q5()` enables the use of q5 functions and variables
|
|
15
|
+
* anywhere in your code.
|
|
16
|
+
* @param {string | Function} [scope] -
|
|
17
|
+
* - "global": (default) top-level global mode, adds q5 functions
|
|
18
|
+
* and variables to the global scope
|
|
19
|
+
* - "auto": if users don't create a new instance of Q5 themselves, an instance will be created automatically with this scope, which replicates p5's global mode
|
|
20
|
+
* - "instance": enables users to [assign a Q5 instance to a variable](https://github.com/q5js/q5.js/wiki/Instance-Mode), not to the global scope
|
|
21
|
+
* @param {HTMLElement} [parent] - element that the canvas will be placed inside
|
|
22
|
+
* @example
|
|
23
|
+
* new Q5();
|
|
24
|
+
* createCanvas(200, 100);
|
|
22
25
|
*/
|
|
23
26
|
constructor(scope?: string | Function, parent?: HTMLElement);
|
|
24
27
|
|
|
25
28
|
/** ⭐️
|
|
26
|
-
*
|
|
29
|
+
* Q5 reformats some errors to make them more readable for beginners.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
static disableFriendlyErrors: boolean;
|
|
33
|
+
|
|
34
|
+
/** ⭐️
|
|
35
|
+
* Sets the default canvas context attributes for all Q5 instances
|
|
36
|
+
* and graphics.
|
|
37
|
+
* @default { alpha: false, colorSpace: 'display-p3' }
|
|
27
38
|
*/
|
|
28
|
-
static canvasOptions: {
|
|
29
|
-
alpha: boolean;
|
|
30
|
-
colorSpace: 'display-p3' | 'srgb';
|
|
31
|
-
};
|
|
39
|
+
static canvasOptions: {};
|
|
32
40
|
|
|
33
41
|
/** ⭐️
|
|
34
42
|
* True if the device supports HDR (the display-p3 colorspace).
|
|
@@ -42,92 +50,123 @@ declare global {
|
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
/** ⭐️
|
|
45
|
-
* The
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
* The draw function is run 60 times per second by default.
|
|
54
|
+
* @example
|
|
55
|
+
function draw() {
|
|
56
|
+
background('lightgray');
|
|
57
|
+
circle(frameCount % 200, 100, 50);
|
|
58
|
+
}
|
|
51
59
|
*/
|
|
52
|
-
|
|
60
|
+
function draw(): void;
|
|
53
61
|
|
|
54
62
|
/** ⭐️
|
|
55
|
-
*
|
|
63
|
+
* The setup function is called once when the program starts.
|
|
64
|
+
* @example
|
|
65
|
+
function setup() {
|
|
66
|
+
createCanvas(200, 100);
|
|
67
|
+
background('aqua');
|
|
68
|
+
}
|
|
56
69
|
*/
|
|
57
|
-
|
|
70
|
+
function setup(): void;
|
|
58
71
|
|
|
59
72
|
/** ⭐️
|
|
60
|
-
*
|
|
73
|
+
* Use preload to load assets before the sketch starts and the
|
|
74
|
+
* setup and draw functions are run.
|
|
75
|
+
* @example
|
|
76
|
+
let logo;
|
|
77
|
+
function preload() {
|
|
78
|
+
logo = loadImage('/q5js_logo.webp');
|
|
79
|
+
}
|
|
80
|
+
function draw() {
|
|
81
|
+
background(logo);
|
|
82
|
+
}
|
|
61
83
|
*/
|
|
62
|
-
|
|
84
|
+
function preload(): void;
|
|
63
85
|
|
|
64
86
|
/** ⭐️
|
|
65
87
|
* The number of frames that have been displayed since the program started.
|
|
88
|
+
* @example
|
|
89
|
+
function draw() {
|
|
90
|
+
background(200);
|
|
91
|
+
textSize(64);
|
|
92
|
+
text(frameCount, 8, 120);
|
|
93
|
+
}
|
|
66
94
|
*/
|
|
67
95
|
var frameCount: number;
|
|
68
96
|
|
|
69
97
|
/** ⭐️
|
|
70
|
-
*
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*/
|
|
77
|
-
var windowWidth: number;
|
|
78
|
-
|
|
79
|
-
/** ⭐️
|
|
80
|
-
* The height of the window.
|
|
81
|
-
*/
|
|
82
|
-
var windowHeight: number;
|
|
83
|
-
|
|
84
|
-
/** ⭐️
|
|
85
|
-
* The current orientation of the device.
|
|
86
|
-
*/
|
|
87
|
-
var deviceOrientation: string | null;
|
|
88
|
-
|
|
89
|
-
/** ⭐️
|
|
90
|
-
* Use preload to load assets before the sketch starts and the
|
|
91
|
-
* setup function is run.
|
|
98
|
+
* Stops the draw loop.
|
|
99
|
+
* @example
|
|
100
|
+
function draw() {
|
|
101
|
+
circle(frameCount * 5, 100, 50);
|
|
102
|
+
noLoop();
|
|
103
|
+
}
|
|
92
104
|
*/
|
|
93
|
-
function
|
|
105
|
+
function noLoop(): void;
|
|
94
106
|
|
|
95
107
|
/** ⭐️
|
|
96
|
-
*
|
|
97
|
-
|
|
98
|
-
|
|
108
|
+
* Redraws the canvas n times. If no input parameter is provided,
|
|
109
|
+
* it calls the draw function once.
|
|
110
|
+
* @param {number} [n] - number of times to redraw the canvas, default is 1
|
|
111
|
+
* @example
|
|
112
|
+
new Q5();
|
|
113
|
+
noLoop();
|
|
99
114
|
|
|
100
|
-
|
|
101
|
-
|
|
115
|
+
function draw() {
|
|
116
|
+
circle(frameCount * 5, 100, 50);
|
|
117
|
+
}
|
|
118
|
+
function mouseClicked() {
|
|
119
|
+
redraw();
|
|
120
|
+
}
|
|
102
121
|
*/
|
|
103
|
-
function
|
|
122
|
+
function redraw(n?: number): void;
|
|
104
123
|
|
|
105
124
|
/** ⭐️
|
|
106
|
-
*
|
|
107
|
-
|
|
108
|
-
|
|
125
|
+
* Starts the draw loop again if it was stopped.
|
|
126
|
+
* @example
|
|
127
|
+
new Q5();
|
|
128
|
+
noLoop();
|
|
109
129
|
|
|
110
|
-
|
|
111
|
-
|
|
130
|
+
function draw() {
|
|
131
|
+
circle(frameCount * 5, 100, 50);
|
|
132
|
+
}
|
|
133
|
+
function mouseClicked() {
|
|
134
|
+
loop();
|
|
135
|
+
}
|
|
112
136
|
*/
|
|
113
137
|
function loop(): void;
|
|
114
138
|
|
|
115
|
-
/** ⭐️
|
|
116
|
-
* Redraws the canvas n times.
|
|
117
|
-
* @param n - number of times to redraw the canvas
|
|
118
|
-
*/
|
|
119
|
-
function redraw(n?: number): void;
|
|
120
|
-
|
|
121
139
|
/** ⭐️
|
|
122
140
|
* Sets the target frame rate or gets the sketch's current frame rate.
|
|
123
|
-
* @param
|
|
124
|
-
* @returns current frame rate
|
|
141
|
+
* @param {number} [hertz] - target frame rate, default is 60
|
|
142
|
+
* @returns {number} current frame rate
|
|
143
|
+
* @example
|
|
144
|
+
function draw() {
|
|
145
|
+
background(200);
|
|
146
|
+
|
|
147
|
+
if (mouseIsPressed) frameRate(10);
|
|
148
|
+
else frameRate(60);
|
|
149
|
+
|
|
150
|
+
circle(frameCount % 200, 100, 50);
|
|
151
|
+
}
|
|
152
|
+
* @example
|
|
153
|
+
function draw() {
|
|
154
|
+
background(200);
|
|
155
|
+
textSize(64);
|
|
156
|
+
text(round(frameRate()), 65, 120);
|
|
157
|
+
}
|
|
125
158
|
*/
|
|
126
|
-
function frameRate(
|
|
159
|
+
function frameRate(hertz?: number): number;
|
|
127
160
|
|
|
128
161
|
/** ⭐️
|
|
129
162
|
* The desired frame rate of the sketch.
|
|
130
|
-
* @returns target frame rate
|
|
163
|
+
* @returns {number} target frame rate
|
|
164
|
+
* @example
|
|
165
|
+
function draw() {
|
|
166
|
+
background(200);
|
|
167
|
+
textSize(64);
|
|
168
|
+
text(getTargetFrameRate(), 65, 120);
|
|
169
|
+
}
|
|
131
170
|
*/
|
|
132
171
|
function getTargetFrameRate(): number;
|
|
133
172
|
|
|
@@ -135,34 +174,93 @@ declare global {
|
|
|
135
174
|
* Gets the current FPS, in terms of how many frames could be generated
|
|
136
175
|
* in one second, which can be higher than the target frame rate. Useful
|
|
137
176
|
* for analyzing performance.
|
|
138
|
-
* @returns frames per second
|
|
177
|
+
* @returns {number} frames per second
|
|
178
|
+
* @example
|
|
179
|
+
function draw() {
|
|
180
|
+
background(200);
|
|
181
|
+
frameRate(1);
|
|
182
|
+
textSize(64);
|
|
183
|
+
text(getFPS(), 8, 120);
|
|
184
|
+
}
|
|
139
185
|
*/
|
|
140
186
|
function getFPS(): number;
|
|
141
187
|
|
|
142
188
|
/** ⭐️
|
|
143
|
-
* Logs a message to the JavaScript console. Alias for the standard
|
|
144
|
-
*
|
|
189
|
+
* Logs a message to the JavaScript console. Alias for the standard
|
|
190
|
+
* [`console.log`](https://developer.mozilla.org/en-US/docs/Web/API/console/log_static) function.
|
|
191
|
+
* @param {*} message - message to log
|
|
145
192
|
*/
|
|
146
193
|
function log(message: any): void;
|
|
147
194
|
|
|
148
195
|
/** ⭐️
|
|
149
|
-
*
|
|
150
|
-
* @
|
|
196
|
+
* The width of the window.
|
|
197
|
+
* @example
|
|
198
|
+
function draw() {
|
|
199
|
+
background(200);
|
|
200
|
+
textSize(64);
|
|
201
|
+
textAlign(CENTER, CENTER);
|
|
202
|
+
text(windowWidth, 100, 100);
|
|
203
|
+
}
|
|
151
204
|
*/
|
|
152
|
-
|
|
205
|
+
var windowWidth: number;
|
|
153
206
|
|
|
154
207
|
/** ⭐️
|
|
155
|
-
* The
|
|
208
|
+
* The height of the window.
|
|
209
|
+
* @example
|
|
210
|
+
function draw() {
|
|
211
|
+
background(200);
|
|
212
|
+
textSize(64);
|
|
213
|
+
textAlign(CENTER, CENTER);
|
|
214
|
+
text(windowHeight, 100, 100);
|
|
215
|
+
}
|
|
156
216
|
*/
|
|
157
|
-
|
|
217
|
+
var windowHeight: number;
|
|
158
218
|
|
|
159
219
|
/** ⭐️
|
|
160
|
-
* The
|
|
220
|
+
* The time passed since the last frame was drawn.
|
|
221
|
+
*
|
|
222
|
+
* With the default frame rate of 60, delta time will be
|
|
223
|
+
* approximately 16.6
|
|
224
|
+
*
|
|
225
|
+
* Can be used to keep movements tied to real time if the sketch
|
|
226
|
+
* is often dropping below the target frame rate. Although if frame
|
|
227
|
+
* rates are consistently low, consider reducing the target frame
|
|
228
|
+
* rate instead.
|
|
229
|
+
* @example
|
|
230
|
+
function draw() {
|
|
231
|
+
background(200);
|
|
232
|
+
text(deltaTime, 60, 106);
|
|
233
|
+
}
|
|
234
|
+
* @example
|
|
235
|
+
let x = 0;
|
|
236
|
+
function draw() {
|
|
237
|
+
background(200);
|
|
238
|
+
// simulate frame rate drops
|
|
239
|
+
frameRate(random(30, 60));
|
|
240
|
+
|
|
241
|
+
x += deltaTime * 0.2;
|
|
242
|
+
circle(x % 200, 100, 50);
|
|
243
|
+
}
|
|
161
244
|
*/
|
|
162
|
-
|
|
245
|
+
var deltaTime: number;
|
|
163
246
|
|
|
164
247
|
// ⬜️ canvas
|
|
165
248
|
|
|
249
|
+
/** ⬜️
|
|
250
|
+
* Creates a canvas element. If no input parameters are provided, the
|
|
251
|
+
* canvas will be the size of the window.
|
|
252
|
+
*
|
|
253
|
+
* If this function is not run by the user, a 200x200 canvas will be
|
|
254
|
+
* created automatically.
|
|
255
|
+
* @param {number} [w] - width of the canvas
|
|
256
|
+
* @param {number} [h] - height of the canvas
|
|
257
|
+
* @param {Object} [options] - options for the canvas
|
|
258
|
+
* @param {boolean} [options.alpha] - whether the canvas should have an alpha channel, default is false
|
|
259
|
+
* @param {string} [options.colorSpace] - color space of the canvas, either "srgb" or "display-p3", default is "display-p3" for devices that support HDR colors
|
|
260
|
+
* @returns {HTMLCanvasElement} created canvas element
|
|
261
|
+
*/
|
|
262
|
+
function createCanvas(w?: number, h?: number, options?: CanvasRenderingContext2DSettings): HTMLCanvasElement;
|
|
263
|
+
|
|
166
264
|
/** ⬜️
|
|
167
265
|
* The canvas element associated with the Q5 instance.
|
|
168
266
|
*/
|
|
@@ -178,70 +276,55 @@ declare global {
|
|
|
178
276
|
*/
|
|
179
277
|
var height: number;
|
|
180
278
|
|
|
181
|
-
/** ⬜️
|
|
182
|
-
* Creates a canvas element.
|
|
183
|
-
* @param w - width of the canvas
|
|
184
|
-
* @param h - height of the canvas
|
|
185
|
-
* @param options - options for the canvas.
|
|
186
|
-
*/
|
|
187
|
-
function createCanvas(w: number, h: number, options?: CanvasRenderingContext2DSettings): HTMLCanvasElement;
|
|
188
|
-
|
|
189
|
-
/** ⬜️
|
|
190
|
-
* Any position coordinates or dimensions you use will be scaled based
|
|
191
|
-
* on the unit provided to this function.
|
|
192
|
-
* @param unit
|
|
193
|
-
* @example
|
|
194
|
-
* new Q5();
|
|
195
|
-
* createCanvas(1000, 1000);
|
|
196
|
-
*
|
|
197
|
-
* flexibleCanvas(400);
|
|
198
|
-
* // rect will appear in the middle of the canvas
|
|
199
|
-
* rect(100, 100, 200, 200);
|
|
200
|
-
*/
|
|
201
|
-
function flexibleCanvas(unit: number): void;
|
|
202
|
-
|
|
203
279
|
/** ⬜️
|
|
204
280
|
* Resizes the canvas to the specified width and height.
|
|
205
|
-
* @param w - width of the canvas
|
|
206
|
-
* @param h - height of the canvas
|
|
281
|
+
* @param {number} w - width of the canvas
|
|
282
|
+
* @param {number} h - height of the canvas
|
|
207
283
|
*/
|
|
208
284
|
function resizeCanvas(w: number, h: number): void;
|
|
209
285
|
|
|
210
286
|
/** ⬜️
|
|
211
287
|
* Sets the pixel density of the canvas.
|
|
212
|
-
* @param v - pixel density value
|
|
288
|
+
* @param {number} v - pixel density value
|
|
289
|
+
* @returns {number} pixel density
|
|
213
290
|
*/
|
|
214
291
|
function pixelDensity(v: number): number;
|
|
215
292
|
|
|
216
293
|
/** ⬜️
|
|
217
294
|
* Returns the current display density.
|
|
295
|
+
* @returns {number} display density
|
|
218
296
|
*/
|
|
219
297
|
function displayDensity(): number;
|
|
220
298
|
|
|
221
299
|
/** ⬜️
|
|
222
300
|
* Enables or disables fullscreen mode.
|
|
223
|
-
* @param v - boolean indicating whether to enable or disable fullscreen mode
|
|
224
|
-
* @returns true if fullscreen mode is enabled, false otherwise
|
|
301
|
+
* @param {boolean} [v] - boolean indicating whether to enable or disable fullscreen mode
|
|
302
|
+
* @returns {void | boolean} true if fullscreen mode is enabled, false otherwise
|
|
225
303
|
*/
|
|
226
304
|
function fullscreen(v?: boolean): void | boolean;
|
|
227
305
|
|
|
228
306
|
/** ⬜️
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* @param
|
|
232
|
-
* @
|
|
307
|
+
* Any position coordinates or dimensions you use will be scaled based
|
|
308
|
+
* on the unit provided to this function.
|
|
309
|
+
* @param {number} unit - unit to scale by
|
|
310
|
+
* @example
|
|
311
|
+
new Q5();
|
|
312
|
+
createCanvas(200, 200);
|
|
313
|
+
flexibleCanvas(100);
|
|
314
|
+
// rect will appear in the middle of the canvas
|
|
315
|
+
rect(20, 20, 60, 60);
|
|
233
316
|
*/
|
|
234
|
-
function
|
|
317
|
+
function flexibleCanvas(unit: number): void;
|
|
235
318
|
|
|
236
319
|
/** ⬜️
|
|
237
320
|
* Sets the fill color for shapes.
|
|
238
|
-
* @param color
|
|
321
|
+
* @param {string | number} color - fill color
|
|
239
322
|
*/
|
|
240
323
|
function fill(color: string | number): void;
|
|
241
324
|
|
|
242
325
|
/** ⬜️
|
|
243
326
|
* Sets the stroke (outline) color for shapes.
|
|
244
|
-
* @param color
|
|
327
|
+
* @param {string | number} color - stroke color
|
|
245
328
|
*/
|
|
246
329
|
function stroke(color: string | number): void;
|
|
247
330
|
|
|
@@ -257,7 +340,7 @@ declare global {
|
|
|
257
340
|
|
|
258
341
|
/** ⬜️
|
|
259
342
|
* Sets the size of the stroke used for lines and the border around shapes.
|
|
260
|
-
* @param weight - size of the stroke in pixels
|
|
343
|
+
* @param {number} weight - size of the stroke in pixels
|
|
261
344
|
*/
|
|
262
345
|
function strokeWeight(weight: number): void;
|
|
263
346
|
|
|
@@ -265,39 +348,39 @@ declare global {
|
|
|
265
348
|
* Sets the global opacity, `ctx.globalAlpha`, which
|
|
266
349
|
* affects all subsequent drawing operations.
|
|
267
350
|
* 0 is completely transparent, 255 is completely opaque.
|
|
268
|
-
* @param alpha - opacity level
|
|
351
|
+
* @param {number} alpha - opacity level
|
|
269
352
|
*/
|
|
270
353
|
function opacity(alpha: number): void;
|
|
271
354
|
|
|
272
355
|
/** ⬜️
|
|
273
356
|
* Translates the origin of the drawing context.
|
|
274
|
-
* @param x
|
|
275
|
-
* @param y
|
|
357
|
+
* @param {number} x - translation along the x-axis
|
|
358
|
+
* @param {number} y - translation along the y-axis
|
|
276
359
|
*/
|
|
277
360
|
function translate(x: number, y: number): void;
|
|
278
361
|
|
|
279
362
|
/** ⬜️
|
|
280
363
|
* Rotates the drawing context.
|
|
281
|
-
* @param angle
|
|
364
|
+
* @param {number} angle - rotation angle in radians
|
|
282
365
|
*/
|
|
283
366
|
function rotate(angle: number): void;
|
|
284
367
|
|
|
285
368
|
/** ⬜️
|
|
286
369
|
* Scales the drawing context.
|
|
287
|
-
* @param x - scaling factor along the x-axis
|
|
288
|
-
* @param y - scaling factor along the y-axis
|
|
370
|
+
* @param {number} x - scaling factor along the x-axis
|
|
371
|
+
* @param {number} [y] - scaling factor along the y-axis
|
|
289
372
|
*/
|
|
290
373
|
function scale(x: number, y?: number): void;
|
|
291
374
|
|
|
292
375
|
/** ⬜️
|
|
293
376
|
* Shears the drawing context along the x-axis.
|
|
294
|
-
* @param angle
|
|
377
|
+
* @param {number} angle - shear angle in radians
|
|
295
378
|
*/
|
|
296
379
|
function shearX(angle: number): void;
|
|
297
380
|
|
|
298
381
|
/** ⬜️
|
|
299
382
|
* Shears the drawing context along the y-axis.
|
|
300
|
-
* @param angle
|
|
383
|
+
* @param {number} angle - shear angle in radians
|
|
301
384
|
*/
|
|
302
385
|
function shearY(angle: number): void;
|
|
303
386
|
|
|
@@ -305,12 +388,12 @@ declare global {
|
|
|
305
388
|
* Applies a transformation matrix.
|
|
306
389
|
*
|
|
307
390
|
* Accepts a 3x3 or 4x4 matrix as either an array or multiple arguments.
|
|
308
|
-
* @param a -
|
|
309
|
-
* @param b -
|
|
310
|
-
* @param c -
|
|
311
|
-
* @param d -
|
|
312
|
-
* @param e -
|
|
313
|
-
* @param f -
|
|
391
|
+
* @param {number} a - horizontal scaling
|
|
392
|
+
* @param {number} b - horizontal skewing
|
|
393
|
+
* @param {number} c - vertical skewing
|
|
394
|
+
* @param {number} d - vertical scaling
|
|
395
|
+
* @param {number} e - horizontal moving
|
|
396
|
+
* @param {number} f - vertical moving
|
|
314
397
|
*/
|
|
315
398
|
function applyMatrix(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
316
399
|
|
|
@@ -352,140 +435,100 @@ declare global {
|
|
|
352
435
|
function pop(): void;
|
|
353
436
|
|
|
354
437
|
/** ⬜️
|
|
355
|
-
*
|
|
438
|
+
* Creates a graphics buffer.
|
|
439
|
+
* @param {number} w - width
|
|
440
|
+
* @param {number} h - height
|
|
441
|
+
* @param {CanvasRenderingContext2DSettings} [opt] - options
|
|
442
|
+
* @returns {Q5} a new Q5 graphics buffer
|
|
443
|
+
*/
|
|
444
|
+
function createGraphics(w: number, h: number, opt?: CanvasRenderingContext2DSettings): Q5;
|
|
445
|
+
|
|
446
|
+
/** ⬜️
|
|
447
|
+
* The 2D rendering context for the canvas.
|
|
356
448
|
*/
|
|
357
449
|
var ctx: CanvasRenderingContext2D;
|
|
358
450
|
|
|
451
|
+
/** ⬜️
|
|
452
|
+
* Alias for `ctx`, the 2D rendering context for the canvas.
|
|
453
|
+
*/
|
|
454
|
+
var drawingContext: CanvasRenderingContext2D;
|
|
455
|
+
|
|
359
456
|
// 💻 display
|
|
360
457
|
|
|
361
458
|
/** 💻
|
|
362
459
|
* The `displayMode` function lets you customize how your canvas is presented.
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* - "
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
* Display scale can be set to make small canvases appear larger.
|
|
375
|
-
* @param displayMode
|
|
376
|
-
* @param renderQuality
|
|
377
|
-
* @param displayScale - can be given as a string (ex. "x2") or a number
|
|
378
|
-
*/
|
|
379
|
-
function displayMode(displayMode: string, renderQuality: string, displayScale: string | number): void;
|
|
460
|
+
* @param {string} mode -
|
|
461
|
+
* - "normal": no styling to canvas or its parent element
|
|
462
|
+
* - "centered": canvas will be centered horizontally and vertically within its parent and if it's display size is bigger than its parent it will not clip
|
|
463
|
+
* - "maxed": canvas will fill the parent element, same as fullscreen for a global mode canvas inside a `main` element
|
|
464
|
+
* - "fullscreen": canvas will fill the screen with letterboxing if necessary to preserve its aspect ratio, like css object-fit contain
|
|
465
|
+
* @param {string} renderQuality -
|
|
466
|
+
* - "default": pixelDensity set to displayDensity
|
|
467
|
+
* - "pixelated": pixelDensity set to 1 and various css styles are applied to the canvas to make it render without image smoothing
|
|
468
|
+
* @param {number} scale - can be given as a string (for example "x2") or a number
|
|
469
|
+
*/
|
|
470
|
+
function displayMode(mode: string, renderQuality: string, scale: string | number): void;
|
|
380
471
|
|
|
381
472
|
// 🧑🎨 drawing
|
|
382
473
|
|
|
383
|
-
/** 🧑🎨
|
|
384
|
-
* Sets the global composite operation for the canvas context.
|
|
385
|
-
* @param x - The composite operation to set.
|
|
386
|
-
*/
|
|
387
|
-
function blendMode(x: string): void;
|
|
388
|
-
|
|
389
|
-
/** 🧑🎨
|
|
390
|
-
* Ses the line cap style for the canvas context.
|
|
391
|
-
* @param x - The line cap style to set ('butt', 'round', 'square').
|
|
392
|
-
*/
|
|
393
|
-
function strokeCap(x: CanvasLineCap): void;
|
|
394
|
-
|
|
395
|
-
/** 🧑🎨
|
|
396
|
-
* Sets the line join style for the canvas context.
|
|
397
|
-
* @param x - The line join style to set ('round', 'bevel', 'miter').
|
|
398
|
-
*/
|
|
399
|
-
function strokeJoin(x: CanvasLineJoin): void;
|
|
400
|
-
|
|
401
|
-
/** 🧑🎨
|
|
402
|
-
* Sets the ellipse mode.
|
|
403
|
-
* @param x - The ellipse mode to set.
|
|
404
|
-
*/
|
|
405
|
-
function ellipseMode(x: string): void;
|
|
406
|
-
|
|
407
|
-
/** 🧑🎨
|
|
408
|
-
* Sets the rectangle mode.
|
|
409
|
-
* @param x - The rectangle mode to set.
|
|
410
|
-
*/
|
|
411
|
-
function rectMode(x: string): void;
|
|
412
|
-
|
|
413
|
-
/** 🧑🎨
|
|
414
|
-
* Sets the curve detail level.
|
|
415
|
-
* @param x - The curve detail level to set.
|
|
416
|
-
*/
|
|
417
|
-
function curveDetail(x: number): void;
|
|
418
|
-
|
|
419
|
-
/** 🧑🎨
|
|
420
|
-
* Sets the curve alpha value.
|
|
421
|
-
* @param x - The curve alpha value to set.
|
|
422
|
-
*/
|
|
423
|
-
function curveAlpha(x: number): void;
|
|
424
|
-
|
|
425
|
-
/** 🧑🎨
|
|
426
|
-
* Sets the curve tightness value.
|
|
427
|
-
* @param x - The curve tightness value to set.
|
|
428
|
-
*/
|
|
429
|
-
function curveTightness(x: number): void;
|
|
430
|
-
|
|
431
474
|
/** 🧑🎨
|
|
432
475
|
* Draws over the entire canvas with a color or image.
|
|
433
|
-
* @param color
|
|
476
|
+
* @param {string | number} color - color or image to draw
|
|
434
477
|
*/
|
|
435
478
|
function background(color: string | number): void;
|
|
436
479
|
|
|
437
480
|
/** 🧑🎨
|
|
438
481
|
* Draws a rectangle.
|
|
439
|
-
* @param x
|
|
440
|
-
* @param y
|
|
441
|
-
* @param w - width
|
|
442
|
-
* @param h - height
|
|
443
|
-
* @param tl - top-left radius for rounded corners
|
|
444
|
-
* @param tr - top-right radius for rounded corners
|
|
445
|
-
* @param br - bottom-right radius for rounded corners
|
|
446
|
-
* @param bl - bottom-left radius for rounded corners
|
|
482
|
+
* @param {number} x - x-coordinate
|
|
483
|
+
* @param {number} y - y-coordinate
|
|
484
|
+
* @param {number} w - width of the rectangle
|
|
485
|
+
* @param {number} [h] - height of the rectangle
|
|
486
|
+
* @param {number} [tl] - top-left radius for rounded corners
|
|
487
|
+
* @param {number} [tr] - top-right radius for rounded corners
|
|
488
|
+
* @param {number} [br] - bottom-right radius for rounded corners
|
|
489
|
+
* @param {number} [bl] - bottom-left radius for rounded corners
|
|
447
490
|
*/
|
|
448
491
|
function rect(x: number, y: number, w: number, h?: number, tl?: number, tr?: number, br?: number, bl?: number): void;
|
|
449
492
|
|
|
450
493
|
/** 🧑🎨
|
|
451
494
|
* Draws a square.
|
|
452
|
-
* @param x
|
|
453
|
-
* @param y
|
|
454
|
-
* @param size - size of the sides of the square
|
|
455
|
-
* @param tl - top-left radius for rounded corners
|
|
456
|
-
* @param tr - top-right radius for rounded corners
|
|
457
|
-
* @param br - bottom-right radius for rounded corners
|
|
458
|
-
* @param bl - bottom-left radius for rounded corners
|
|
495
|
+
* @param {number} x - x-coordinate
|
|
496
|
+
* @param {number} y - y-coordinate
|
|
497
|
+
* @param {number} size - size of the sides of the square
|
|
498
|
+
* @param {number} [tl] - top-left radius for rounded corners
|
|
499
|
+
* @param {number} [tr] - top-right radius for rounded corners
|
|
500
|
+
* @param {number} [br] - bottom-right radius for rounded corners
|
|
501
|
+
* @param {number} [bl] - bottom-left radius for rounded corners
|
|
459
502
|
*/
|
|
460
503
|
function square(x: number, y: number, size: number, tl?: number, tr?: number, br?: number, bl?: number): void;
|
|
461
504
|
|
|
462
505
|
/** 🧑🎨
|
|
463
506
|
* Draws a circle.
|
|
464
|
-
* @param x
|
|
465
|
-
* @param y
|
|
466
|
-
* @param diameter
|
|
507
|
+
* @param {number} x - x-coordinate
|
|
508
|
+
* @param {number} y - y-coordinate
|
|
509
|
+
* @param {number} diameter - diameter of the circle
|
|
467
510
|
*/
|
|
468
511
|
function circle(x: number, y: number, diameter: number): void;
|
|
469
512
|
|
|
470
513
|
/** 🧑🎨
|
|
471
514
|
* Draws an ellipse.
|
|
472
|
-
* @param x
|
|
473
|
-
* @param y
|
|
474
|
-
* @param width
|
|
475
|
-
* @param height
|
|
515
|
+
* @param {number} x - x-coordinate
|
|
516
|
+
* @param {number} y - y-coordinate
|
|
517
|
+
* @param {number} width - width of the ellipse
|
|
518
|
+
* @param {number} [height] - height of the ellipse
|
|
476
519
|
*/
|
|
477
520
|
function ellipse(x: number, y: number, width: number, height?: number): void;
|
|
478
521
|
|
|
479
522
|
/** 🧑🎨
|
|
480
523
|
* Draws an arc.
|
|
481
|
-
* @param x
|
|
482
|
-
* @param y
|
|
483
|
-
* @param w - width
|
|
484
|
-
* @param h - height
|
|
485
|
-
* @param start - angle to start the arc
|
|
486
|
-
* @param stop - angle to stop the arc
|
|
487
|
-
* @param mode - drawing mode, can be `PIE`, `CHORD`, or `OPEN`
|
|
488
|
-
* @param detail - resolution of the arc
|
|
524
|
+
* @param {number} x - x-coordinate
|
|
525
|
+
* @param {number} y - y-coordinate
|
|
526
|
+
* @param {number} w - width of the arc
|
|
527
|
+
* @param {number} h - height of the arc
|
|
528
|
+
* @param {number} start - angle to start the arc
|
|
529
|
+
* @param {number} stop - angle to stop the arc
|
|
530
|
+
* @param {number} [mode] - drawing mode, can be `PIE`, `CHORD`, or `OPEN`
|
|
531
|
+
* @param {number} [detail] - resolution of the arc
|
|
489
532
|
*/
|
|
490
533
|
function arc(
|
|
491
534
|
x: number,
|
|
@@ -500,20 +543,68 @@ declare global {
|
|
|
500
543
|
|
|
501
544
|
/** 🧑🎨
|
|
502
545
|
* Draws a line on the canvas.
|
|
503
|
-
* @param x1 - x-coordinate of the first point
|
|
504
|
-
* @param y1 - y-coordinate of the first point
|
|
505
|
-
* @param x2 - x-coordinate of the second point
|
|
506
|
-
* @param y2 - y-coordinate of the second point
|
|
546
|
+
* @param {number} x1 - x-coordinate of the first point
|
|
547
|
+
* @param {number} y1 - y-coordinate of the first point
|
|
548
|
+
* @param {number} x2 - x-coordinate of the second point
|
|
549
|
+
* @param {number} y2 - y-coordinate of the second point
|
|
507
550
|
*/
|
|
508
551
|
function line(x1: number, y1: number, x2: number, y2: number): void;
|
|
509
552
|
|
|
510
553
|
/** 🧑🎨
|
|
511
554
|
* Draws a point on the canvas.
|
|
512
|
-
* @param x
|
|
513
|
-
* @param y
|
|
555
|
+
* @param {number} x - x-coordinate
|
|
556
|
+
* @param {number} y - y-coordinate
|
|
514
557
|
*/
|
|
515
558
|
function point(x: number, y: number): void;
|
|
516
559
|
|
|
560
|
+
/** 🧑🎨
|
|
561
|
+
* Sets the global composite operation for the canvas context.
|
|
562
|
+
* @param {string} val - composite operation to set
|
|
563
|
+
*/
|
|
564
|
+
function blendMode(val: string): void;
|
|
565
|
+
|
|
566
|
+
/** 🧑🎨
|
|
567
|
+
* Sets the line cap style for the canvas context.
|
|
568
|
+
* @param {CanvasLineCap} val - line cap style to set ('butt', 'round', 'square')
|
|
569
|
+
*/
|
|
570
|
+
function strokeCap(val: CanvasLineCap): void;
|
|
571
|
+
|
|
572
|
+
/** 🧑🎨
|
|
573
|
+
* Sets the line join style for the canvas context.
|
|
574
|
+
* @param {CanvasLineJoin} val - line join style to set ('round', 'bevel', 'miter')
|
|
575
|
+
*/
|
|
576
|
+
function strokeJoin(val: CanvasLineJoin): void;
|
|
577
|
+
|
|
578
|
+
/** 🧑🎨
|
|
579
|
+
* Sets the ellipse mode.
|
|
580
|
+
* @param {string} val - ellipse mode to set
|
|
581
|
+
*/
|
|
582
|
+
function ellipseMode(val: string): void;
|
|
583
|
+
|
|
584
|
+
/** 🧑🎨
|
|
585
|
+
* Sets the rectangle mode.
|
|
586
|
+
* @param {string} val - rectangle mode to set
|
|
587
|
+
*/
|
|
588
|
+
function rectMode(val: string): void;
|
|
589
|
+
|
|
590
|
+
/** 🧑🎨
|
|
591
|
+
* Sets the curve detail level.
|
|
592
|
+
* @param {number} val - curve detail level to set
|
|
593
|
+
*/
|
|
594
|
+
function curveDetail(val: number): void;
|
|
595
|
+
|
|
596
|
+
/** 🧑🎨
|
|
597
|
+
* Sets the curve alpha value.
|
|
598
|
+
* @param {number} val - curve alpha value to set
|
|
599
|
+
*/
|
|
600
|
+
function curveAlpha(val: number): void;
|
|
601
|
+
|
|
602
|
+
/** 🧑🎨
|
|
603
|
+
* Sets the curve tightness value.
|
|
604
|
+
* @param {number} val - curve tightness value to set
|
|
605
|
+
*/
|
|
606
|
+
function curveTightness(val: number): void;
|
|
607
|
+
|
|
517
608
|
/** 🧑🎨
|
|
518
609
|
* Starts recording vertices for a shape.
|
|
519
610
|
*/
|
|
@@ -531,72 +622,72 @@ declare global {
|
|
|
531
622
|
|
|
532
623
|
/** 🧑🎨
|
|
533
624
|
* Specifies a vertex in a shape.
|
|
534
|
-
* @param x
|
|
535
|
-
* @param y
|
|
625
|
+
* @param {number} x - x-coordinate
|
|
626
|
+
* @param {number} y - y-coordinate
|
|
536
627
|
*/
|
|
537
628
|
function vertex(x: number, y: number): void;
|
|
538
629
|
|
|
539
630
|
/** 🧑🎨
|
|
540
631
|
* Specifies a Bezier vertex in a shape.
|
|
541
|
-
* @param cp1x - x-coordinate of the first control point
|
|
542
|
-
* @param cp1y - y-coordinate of the first control point
|
|
543
|
-
* @param cp2x - x-coordinate of the second control point
|
|
544
|
-
* @param cp2y - y-coordinate of the second control point
|
|
545
|
-
* @param x - x-coordinate of the anchor point
|
|
546
|
-
* @param y - y-coordinate of the anchor point
|
|
632
|
+
* @param {number} cp1x - x-coordinate of the first control point
|
|
633
|
+
* @param {number} cp1y - y-coordinate of the first control point
|
|
634
|
+
* @param {number} cp2x - x-coordinate of the second control point
|
|
635
|
+
* @param {number} cp2y - y-coordinate of the second control point
|
|
636
|
+
* @param {number} x - x-coordinate of the anchor point
|
|
637
|
+
* @param {number} y - y-coordinate of the anchor point
|
|
547
638
|
*/
|
|
548
639
|
function bezierVertex(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
549
640
|
|
|
550
641
|
/** 🧑🎨
|
|
551
642
|
* Specifies a quadratic Bezier vertex in a shape.
|
|
552
|
-
* @param cp1x - x-coordinate of the control point
|
|
553
|
-
* @param cp1y - y-coordinate of the control point
|
|
554
|
-
* @param x - x-coordinate of the anchor point
|
|
555
|
-
* @param y - y-coordinate of the anchor point
|
|
643
|
+
* @param {number} cp1x - x-coordinate of the control point
|
|
644
|
+
* @param {number} cp1y - y-coordinate of the control point
|
|
645
|
+
* @param {number} x - x-coordinate of the anchor point
|
|
646
|
+
* @param {number} y - y-coordinate of the anchor point
|
|
556
647
|
*/
|
|
557
648
|
function quadraticVertex(cp1x: number, cp1y: number, x: number, y: number): void;
|
|
558
649
|
|
|
559
650
|
/** 🧑🎨
|
|
560
651
|
* Draws a Bezier curve.
|
|
561
|
-
* @param x1 - x-coordinate of the first anchor point
|
|
562
|
-
* @param y1 - y-coordinate of the first anchor point
|
|
563
|
-
* @param x2 - x-coordinate of the first control point
|
|
564
|
-
* @param y2 - y-coordinate of the first control point
|
|
565
|
-
* @param x3 - x-coordinate of the second control point
|
|
566
|
-
* @param y3 - y-coordinate of the second control point
|
|
567
|
-
* @param x4 - x-coordinate of the second anchor point
|
|
568
|
-
* @param y4 - y-coordinate of the second anchor point
|
|
652
|
+
* @param {number} x1 - x-coordinate of the first anchor point
|
|
653
|
+
* @param {number} y1 - y-coordinate of the first anchor point
|
|
654
|
+
* @param {number} x2 - x-coordinate of the first control point
|
|
655
|
+
* @param {number} y2 - y-coordinate of the first control point
|
|
656
|
+
* @param {number} x3 - x-coordinate of the second control point
|
|
657
|
+
* @param {number} y3 - y-coordinate of the second control point
|
|
658
|
+
* @param {number} x4 - x-coordinate of the second anchor point
|
|
659
|
+
* @param {number} y4 - y-coordinate of the second anchor point
|
|
569
660
|
*/
|
|
570
661
|
function bezier(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
571
662
|
|
|
572
663
|
/** 🧑🎨
|
|
573
664
|
* Draws a triangle.
|
|
574
|
-
* @param x1 - x-coordinate of the first vertex
|
|
575
|
-
* @param y1 - y-coordinate of the first vertex
|
|
576
|
-
* @param x2 - x-coordinate of the second vertex
|
|
577
|
-
* @param y2 - y-coordinate of the second vertex
|
|
578
|
-
* @param x3 - x-coordinate of the third vertex
|
|
579
|
-
* @param y3 - y-coordinate of the third vertex
|
|
665
|
+
* @param {number} x1 - x-coordinate of the first vertex
|
|
666
|
+
* @param {number} y1 - y-coordinate of the first vertex
|
|
667
|
+
* @param {number} x2 - x-coordinate of the second vertex
|
|
668
|
+
* @param {number} y2 - y-coordinate of the second vertex
|
|
669
|
+
* @param {number} x3 - x-coordinate of the third vertex
|
|
670
|
+
* @param {number} y3 - y-coordinate of the third vertex
|
|
580
671
|
*/
|
|
581
672
|
function triangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void;
|
|
582
673
|
|
|
583
674
|
/** 🧑🎨
|
|
584
675
|
* Draws a quadrilateral.
|
|
585
|
-
* @param x1 - x-coordinate of the first vertex
|
|
586
|
-
* @param y1 - y-coordinate of the first vertex
|
|
587
|
-
* @param x2 - x-coordinate of the second vertex
|
|
588
|
-
* @param y2 - y-coordinate of the second vertex
|
|
589
|
-
* @param x3 - x-coordinate of the third vertex
|
|
590
|
-
* @param y3 - y-coordinate of the third vertex
|
|
591
|
-
* @param x4 - x-coordinate of the fourth vertex
|
|
592
|
-
* @param y4 - y-coordinate of the fourth vertex
|
|
676
|
+
* @param {number} x1 - x-coordinate of the first vertex
|
|
677
|
+
* @param {number} y1 - y-coordinate of the first vertex
|
|
678
|
+
* @param {number} x2 - x-coordinate of the second vertex
|
|
679
|
+
* @param {number} y2 - y-coordinate of the second vertex
|
|
680
|
+
* @param {number} x3 - x-coordinate of the third vertex
|
|
681
|
+
* @param {number} y3 - y-coordinate of the third vertex
|
|
682
|
+
* @param {number} x4 - x-coordinate of the fourth vertex
|
|
683
|
+
* @param {number} y4 - y-coordinate of the fourth vertex
|
|
593
684
|
*/
|
|
594
|
-
function quad(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4): void;
|
|
685
|
+
function quad(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
595
686
|
|
|
596
687
|
/** 🧑🎨
|
|
597
688
|
* Sets the canvas to erase mode, where shapes will erase what's underneath them instead of drawing over it.
|
|
598
|
-
* @param fillAlpha - opacity level of the fill color from 0 to 255
|
|
599
|
-
* @param strokeAlpha - opacity level of the stroke color from 0 to 255
|
|
689
|
+
* @param {number} [fillAlpha] - opacity level of the fill color from 0 to 255
|
|
690
|
+
* @param {number} [strokeAlpha] - opacity level of the stroke color from 0 to 255
|
|
600
691
|
*/
|
|
601
692
|
function erase(fillAlpha?: number, strokeAlpha?: number): void;
|
|
602
693
|
|
|
@@ -607,68 +698,78 @@ declare global {
|
|
|
607
698
|
|
|
608
699
|
/** 🧑🎨
|
|
609
700
|
* Checks if a given point is within the current path's fill area.
|
|
610
|
-
* @
|
|
701
|
+
* @param {number} x - x-coordinate of the point
|
|
702
|
+
* @param {number} y - y-coordinate of the point
|
|
703
|
+
* @returns {boolean} true if the point is within the fill area, false otherwise
|
|
611
704
|
*/
|
|
612
705
|
function inFill(x: number, y: number): boolean;
|
|
613
706
|
|
|
614
707
|
/** 🧑🎨
|
|
615
708
|
* Checks if a given point is within the current path's stroke.
|
|
616
|
-
* @
|
|
709
|
+
* @param {number} x - x-coordinate of the point
|
|
710
|
+
* @param {number} y - y-coordinate of the point
|
|
711
|
+
* @returns {boolean} true if the point is within the stroke, false otherwise
|
|
617
712
|
*/
|
|
618
713
|
function inStroke(x: number, y: number): boolean;
|
|
619
714
|
|
|
620
715
|
// 🌆 image
|
|
621
716
|
|
|
622
717
|
/** 🌆
|
|
623
|
-
* Applies a filter to the image
|
|
624
|
-
* @param
|
|
625
|
-
* @param
|
|
718
|
+
* Applies a filter to the image.
|
|
719
|
+
* @param {string} type - type of filter
|
|
720
|
+
* @param {number} [value] - optional parameter, depending on filter type
|
|
626
721
|
*/
|
|
627
|
-
function filter(
|
|
722
|
+
function filter(type: string, value?: number): void;
|
|
628
723
|
|
|
629
724
|
/** 🌆
|
|
630
|
-
* Resizes the image
|
|
631
|
-
* @param w - new width
|
|
632
|
-
* @param h - new height
|
|
725
|
+
* Resizes the image.
|
|
726
|
+
* @param {number} w - new width
|
|
727
|
+
* @param {number} h - new height
|
|
633
728
|
*/
|
|
634
729
|
function resize(w: number, h: number): void;
|
|
635
730
|
|
|
636
731
|
/** 🌆
|
|
637
|
-
* Returns a trimmed image, cropping out transparent pixels
|
|
638
|
-
* from the edges.
|
|
732
|
+
* Returns a trimmed image, cropping out transparent pixels from the edges.
|
|
639
733
|
* @returns {Image}
|
|
640
734
|
*/
|
|
641
735
|
function trim(): Image;
|
|
642
736
|
|
|
643
737
|
/** 🌆
|
|
644
|
-
* Masks the image with another image
|
|
645
|
-
* @param img -
|
|
738
|
+
* Masks the image with another image.
|
|
739
|
+
* @param {Image} img - image to use as a mask
|
|
646
740
|
*/
|
|
647
741
|
function mask(img: Image): void;
|
|
648
742
|
|
|
649
743
|
/** 🌆
|
|
650
|
-
* Saves the image
|
|
651
|
-
* @param
|
|
652
|
-
* @param
|
|
653
|
-
* @param
|
|
744
|
+
* Saves the image.
|
|
745
|
+
* @param {string} filename - filename or path
|
|
746
|
+
* @param {string} extension - file extension
|
|
747
|
+
* @param {number} [quality] - quality of the saved image
|
|
654
748
|
*/
|
|
655
|
-
function save(
|
|
749
|
+
function save(filename: string, extension: string, quality?: number): void;
|
|
656
750
|
|
|
657
751
|
/** 🌆
|
|
658
752
|
* Displays a region of the image on another region of the image.
|
|
659
|
-
*
|
|
660
753
|
* Can be used to create a detail inset, aka a magnifying glass effect.
|
|
661
|
-
*
|
|
662
|
-
* @param
|
|
663
|
-
* @param
|
|
664
|
-
* @param
|
|
665
|
-
* @param
|
|
666
|
-
* @param
|
|
667
|
-
* @param
|
|
668
|
-
* @param
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
754
|
+
* @param {number} srcX - x-coordinate of the source region
|
|
755
|
+
* @param {number} srcY - y-coordinate of the source region
|
|
756
|
+
* @param {number} srcW - width of the source region
|
|
757
|
+
* @param {number} srcH - height of the source region
|
|
758
|
+
* @param {number} dstX - x-coordinate of the destination region
|
|
759
|
+
* @param {number} dstY - y-coordinate of the destination region
|
|
760
|
+
* @param {number} dstW - width of the destination region
|
|
761
|
+
* @param {number} dstH - height of the destination region
|
|
762
|
+
*/
|
|
763
|
+
function inset(
|
|
764
|
+
srcX: number,
|
|
765
|
+
srcY: number,
|
|
766
|
+
srcW: number,
|
|
767
|
+
srcH: number,
|
|
768
|
+
dstX: number,
|
|
769
|
+
dstY: number,
|
|
770
|
+
dstW: number,
|
|
771
|
+
dstH: number
|
|
772
|
+
): void;
|
|
672
773
|
|
|
673
774
|
/** 🌆
|
|
674
775
|
* Returns a copy of the image.
|
|
@@ -678,31 +779,30 @@ declare global {
|
|
|
678
779
|
|
|
679
780
|
/** 🌆
|
|
680
781
|
* Retrieves a subsection of an image or canvas, as a q5 Image.
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
* @
|
|
688
|
-
* @param y
|
|
689
|
-
* @param w - width of the area
|
|
690
|
-
* @param h - height of the area
|
|
691
|
-
* @returns {Image}
|
|
782
|
+
* Or if width and height are both 1, returns the color of the pixel at the given coordinates in `[R, G, B, A]` array format.
|
|
783
|
+
* To edit the color value of multiple pixels, it's faster to use `loadPixels` and `updatePixels`.
|
|
784
|
+
* @param {number} x
|
|
785
|
+
* @param {number} y
|
|
786
|
+
* @param {number} [w] - width of the area
|
|
787
|
+
* @param {number} [h] - height of the area
|
|
788
|
+
* @returns {Image | number[]}
|
|
692
789
|
*/
|
|
693
|
-
function get(x: number, y: number, w?: number, h?: number):
|
|
790
|
+
function get(x: number, y: number, w?: number, h?: number): Image | number[];
|
|
694
791
|
|
|
695
792
|
/** 🌆
|
|
696
793
|
* Sets a pixel's color in the image or canvas.
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* @param
|
|
701
|
-
* @param y
|
|
702
|
-
* @param c - color, canvas, or image
|
|
794
|
+
* Or if a canvas or image is provided, it's drawn on top of the destination image or canvas ignoring its tint setting.
|
|
795
|
+
* @param {number} x
|
|
796
|
+
* @param {number} y
|
|
797
|
+
* @param {any} c - color, canvas, or image
|
|
703
798
|
*/
|
|
704
799
|
function set(x: number, y: number, c: any): void;
|
|
705
800
|
|
|
801
|
+
/** 🌆
|
|
802
|
+
* Array of pixels in the canvas or image. Use `loadPixels` to load the pixel data.
|
|
803
|
+
*/
|
|
804
|
+
var pixels: number[];
|
|
805
|
+
|
|
706
806
|
/** 🌆
|
|
707
807
|
* Loads pixel data into the image's `pixels` array.
|
|
708
808
|
*/
|
|
@@ -714,7 +814,7 @@ declare global {
|
|
|
714
814
|
function updatePixels(): void;
|
|
715
815
|
|
|
716
816
|
/** 🌆
|
|
717
|
-
* Enables smooth image rendering
|
|
817
|
+
* Enables smooth image rendering.
|
|
718
818
|
*/
|
|
719
819
|
function smooth(): void;
|
|
720
820
|
|
|
@@ -726,9 +826,9 @@ declare global {
|
|
|
726
826
|
/** 🌆
|
|
727
827
|
* Applies a tint (color overlay) to the drawing.
|
|
728
828
|
* Tinting affects all subsequent images drawn.
|
|
729
|
-
* @param
|
|
829
|
+
* @param {string | number} color - tint color
|
|
730
830
|
*/
|
|
731
|
-
function tint(
|
|
831
|
+
function tint(color: string | number): void;
|
|
732
832
|
|
|
733
833
|
/** 🌆
|
|
734
834
|
* Images drawn after this function is run will not be tinted.
|
|
@@ -737,39 +837,40 @@ declare global {
|
|
|
737
837
|
|
|
738
838
|
/** 🌆
|
|
739
839
|
* Creates a new image.
|
|
740
|
-
* @param w - width
|
|
741
|
-
* @param h - height
|
|
742
|
-
* @param opt - optional settings for the image
|
|
840
|
+
* @param {number} w - width
|
|
841
|
+
* @param {number} h - height
|
|
842
|
+
* @param {any} [opt] - optional settings for the image
|
|
843
|
+
* @returns {Image}
|
|
743
844
|
*/
|
|
744
845
|
function createImage(w: number, h: number, opt?: any): Image;
|
|
745
846
|
|
|
746
847
|
/** 🌆
|
|
747
848
|
* Sets the image mode, which determines the position and alignment of images drawn on the canvas.
|
|
748
|
-
* - 'CORNER':
|
|
749
|
-
* - 'CORNERS': images will be drawn from top-left
|
|
750
|
-
* - 'CENTER':
|
|
751
|
-
* @param mode
|
|
849
|
+
* - 'CORNER': images will be drawn from the top-left corner (default).
|
|
850
|
+
* - 'CORNERS': images will be drawn from the top-left to the bottom-right corner.
|
|
851
|
+
* - 'CENTER': images will be drawn centered at (dx, dy).
|
|
852
|
+
* @param {string} mode
|
|
752
853
|
*/
|
|
753
|
-
|
|
854
|
+
function imageMode(mode: string): void;
|
|
754
855
|
|
|
755
856
|
/** 🌆
|
|
756
|
-
* Draws an image to the canvas
|
|
757
|
-
* @param img - image to draw
|
|
758
|
-
* @param dx - x-coordinate of the destination corner
|
|
759
|
-
* @param dy - y-coordinate of the destination corner
|
|
760
|
-
* @param dWidth - width of the destination image
|
|
761
|
-
* @param dHeight - height of the destination image
|
|
762
|
-
* @param sx - x-coordinate of the source corner
|
|
763
|
-
* @param sy - y-coordinate of the source corner
|
|
764
|
-
* @param sWidth - width of the source image
|
|
765
|
-
* @param sHeight - height of the source image
|
|
857
|
+
* Draws an image to the canvas.
|
|
858
|
+
* @param {any} img - image to draw
|
|
859
|
+
* @param {number} dx - x-coordinate of the destination corner
|
|
860
|
+
* @param {number} dy - y-coordinate of the destination corner
|
|
861
|
+
* @param {number} [dWidth] - width of the destination image
|
|
862
|
+
* @param {number} [dHeight] - height of the destination image
|
|
863
|
+
* @param {number} [sx] - x-coordinate of the source corner
|
|
864
|
+
* @param {number} [sy] - y-coordinate of the source corner
|
|
865
|
+
* @param {number} [sWidth] - width of the source image
|
|
866
|
+
* @param {number} [sHeight] - height of the source image
|
|
766
867
|
*/
|
|
767
868
|
function image(
|
|
768
869
|
img: any,
|
|
769
870
|
dx: number,
|
|
770
871
|
dy: number,
|
|
771
|
-
dWidth
|
|
772
|
-
dHeight
|
|
872
|
+
dWidth?: number,
|
|
873
|
+
dHeight?: number,
|
|
773
874
|
sx?: number,
|
|
774
875
|
sy?: number,
|
|
775
876
|
sWidth?: number,
|
|
@@ -777,10 +878,10 @@ declare global {
|
|
|
777
878
|
): void;
|
|
778
879
|
|
|
779
880
|
/** 🌆
|
|
780
|
-
* Loads an image from a URL and optionally runs a callback function
|
|
781
|
-
* @param url -
|
|
782
|
-
* @param cb - callback function
|
|
783
|
-
* @param opt - optional parameters for loading the image
|
|
881
|
+
* Loads an image from a URL and optionally runs a callback function.
|
|
882
|
+
* @param {string} url - uRL of the image to load
|
|
883
|
+
* @param {(img: any) => void} [cb] - callback function after the image is loaded
|
|
884
|
+
* @param {any} [opt] - optional parameters for loading the image
|
|
784
885
|
*/
|
|
785
886
|
function loadImage(url: string, cb?: (img: any) => void, opt?: any): void;
|
|
786
887
|
|
|
@@ -827,175 +928,175 @@ declare global {
|
|
|
827
928
|
// ✍️ text
|
|
828
929
|
|
|
829
930
|
/** ✍️
|
|
830
|
-
*
|
|
931
|
+
* Renders text to the screen. Text can be positioned with the x and y
|
|
932
|
+
* parameters and can optionally be constrained within a bounding box.
|
|
933
|
+
* @param {string} str - string of text to display
|
|
934
|
+
* @param {number} x - x-coordinate of the text's position
|
|
935
|
+
* @param {number} y - y-coordinate of the text's position
|
|
936
|
+
* @param {number} [w] - width of the bounding box
|
|
937
|
+
* @param {number} [h] - height of the bounding box
|
|
831
938
|
*/
|
|
832
|
-
|
|
939
|
+
function text(str: string, x: number, y: number, w?: number, h?: number): void;
|
|
833
940
|
|
|
834
941
|
/** ✍️
|
|
835
|
-
*
|
|
942
|
+
* Loads a font from a URL and optionally runs a callback function with the font name once it's loaded.
|
|
943
|
+
*
|
|
944
|
+
* WebGPU: Fonts must be in MSDF format with the file ending
|
|
945
|
+
* "-msdf.json". If no font is loaded before `text` is run, then
|
|
946
|
+
* the default font is loaded:
|
|
947
|
+
* https://q5js.org/fonts/YaHei-msdf.json
|
|
948
|
+
* @param {string} url - uRL of the font to load
|
|
949
|
+
* @param {(fontName: string) => void} [cb] - optional callback function that receives the font name as an argument once the font is loaded
|
|
950
|
+
* @returns {string} name of the loaded font
|
|
836
951
|
*/
|
|
837
|
-
|
|
952
|
+
function loadFont(url: string, cb?: (fontName: string) => void): string;
|
|
838
953
|
|
|
839
954
|
/** ✍️
|
|
840
|
-
*
|
|
955
|
+
* Sets the current font to be used for rendering text.
|
|
956
|
+
* @param {string} fontName - name of the font
|
|
841
957
|
*/
|
|
842
|
-
|
|
958
|
+
function textFont(fontName: string): void;
|
|
843
959
|
|
|
844
960
|
/** ✍️
|
|
845
|
-
*
|
|
961
|
+
* Sets or gets the current font size. If no argument is provided, returns the current font size.
|
|
962
|
+
* @param {number} [size] - size of the font in pixels
|
|
963
|
+
* @returns {number | void} current font size when no argument is provided
|
|
846
964
|
*/
|
|
847
|
-
|
|
965
|
+
function textSize(size?: number): number | void;
|
|
848
966
|
|
|
849
967
|
/** ✍️
|
|
850
|
-
*
|
|
968
|
+
* Sets or gets the current line height. If no argument is provided, returns the current line height.
|
|
969
|
+
* @param {number} [leading] - line height in pixels
|
|
970
|
+
* @returns {number | void} current line height when no argument is provided
|
|
851
971
|
*/
|
|
852
|
-
|
|
972
|
+
function textLeading(leading?: number): number | void;
|
|
853
973
|
|
|
854
974
|
/** ✍️
|
|
855
|
-
*
|
|
975
|
+
* Sets the current text style.
|
|
976
|
+
* @param {'normal' | 'italic' | 'bold' | 'bolditalic'} style - font style
|
|
856
977
|
*/
|
|
857
|
-
|
|
978
|
+
function textStyle(style: 'normal' | 'italic' | 'bold' | 'bolditalic'): void;
|
|
858
979
|
|
|
859
980
|
/** ✍️
|
|
860
|
-
*
|
|
981
|
+
* Sets the horizontal and vertical alignment of text.
|
|
982
|
+
* @param {'left' | 'center' | 'right'} horiz - horizontal alignment
|
|
983
|
+
* @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] - vertical alignment
|
|
861
984
|
*/
|
|
862
|
-
|
|
985
|
+
function textAlign(horiz: 'left' | 'center' | 'right', vert?: 'top' | 'middle' | 'bottom' | 'alphabetic'): void;
|
|
863
986
|
|
|
864
987
|
/** ✍️
|
|
865
|
-
*
|
|
988
|
+
* Calculates and returns the width of a given string of text.
|
|
989
|
+
* @param {string} str - string to measure
|
|
990
|
+
* @returns {number} width of the text in pixels
|
|
866
991
|
*/
|
|
867
|
-
|
|
992
|
+
function textWidth(str: string): number;
|
|
868
993
|
|
|
869
994
|
/** ✍️
|
|
870
|
-
*
|
|
995
|
+
* Calculates and returns the ascent (the distance from the baseline to the top of the highest character) of the current font.
|
|
996
|
+
* @param {string} str - string to measure
|
|
997
|
+
* @returns {number} ascent of the text in pixels
|
|
871
998
|
*/
|
|
872
|
-
|
|
999
|
+
function textAscent(str: string): number;
|
|
873
1000
|
|
|
874
1001
|
/** ✍️
|
|
875
|
-
*
|
|
1002
|
+
* Calculates and returns the descent (the distance from the baseline to the bottom of the lowest character) of the current font.
|
|
1003
|
+
* @param {string} str - string to measure
|
|
1004
|
+
* @returns {number} descent of the text in pixels
|
|
876
1005
|
*/
|
|
877
|
-
|
|
1006
|
+
function textDescent(str: string): number;
|
|
878
1007
|
|
|
879
1008
|
/** ✍️
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
* @
|
|
887
|
-
* @param cb - Optional callback function that receives the font name as an argument once the font is loaded
|
|
888
|
-
* @returns name of the loaded font
|
|
1009
|
+
* Creates an image from a string of text. Width and height
|
|
1010
|
+
* will not be the width and height of the text image, but of
|
|
1011
|
+
* the bounding box that the text will be constrained within.
|
|
1012
|
+
* @param {string} str - string of text
|
|
1013
|
+
* @param {number} w - width of the bounding box
|
|
1014
|
+
* @param {number} h - height of the bounding box
|
|
1015
|
+
* @returns {Q5} an image object representing the rendered text
|
|
889
1016
|
*/
|
|
890
|
-
function
|
|
1017
|
+
function createTextImage(str: string, w: number, h: number): Q5;
|
|
891
1018
|
|
|
892
1019
|
/** ✍️
|
|
893
|
-
*
|
|
894
|
-
*
|
|
1020
|
+
* Renders an image generated from text onto the canvas. The
|
|
1021
|
+
* positioning of the image can be affected by the current text
|
|
1022
|
+
* alignment and baseline settings.
|
|
1023
|
+
* @param {HTMLImageElement} img - image object to render, typically generated from text
|
|
1024
|
+
* @param {number} x - x-coordinate where the image should be placed
|
|
1025
|
+
* @param {number} y - y-coordinate where the image should be placed
|
|
895
1026
|
*/
|
|
896
|
-
function
|
|
1027
|
+
function textImage(img: HTMLImageElement, x: number, y: number): void;
|
|
897
1028
|
|
|
898
1029
|
/** ✍️
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
*
|
|
1030
|
+
* Number formatter, can be used to display a number as a string with
|
|
1031
|
+
* a specified number of digits before and after the decimal point,
|
|
1032
|
+
* optionally adding padding with zeros.
|
|
1033
|
+
* @param {number} n - number to format
|
|
1034
|
+
* @param {number} l - minimum number of digits to appear before the decimal point; the number is padded with zeros if necessary
|
|
1035
|
+
* @param {number} r - number of digits to appear after the decimal point
|
|
1036
|
+
* @returns {string} a string representation of the number, formatted accordingly
|
|
902
1037
|
*/
|
|
903
|
-
function
|
|
1038
|
+
function nf(n: number, l: number, r: number): string;
|
|
904
1039
|
|
|
905
1040
|
/** ✍️
|
|
906
|
-
*
|
|
907
|
-
* @param leading - line height in pixels
|
|
908
|
-
* @returns current line height when no argument is provided
|
|
1041
|
+
* Normal font weight.
|
|
909
1042
|
*/
|
|
910
|
-
|
|
1043
|
+
const NORMAL: 'normal';
|
|
911
1044
|
|
|
912
1045
|
/** ✍️
|
|
913
|
-
*
|
|
914
|
-
* @param style - font style ('normal', 'italic', 'bold', 'bolditalic')
|
|
1046
|
+
* Italic font style.
|
|
915
1047
|
*/
|
|
916
|
-
|
|
1048
|
+
const ITALIC: 'italic';
|
|
917
1049
|
|
|
918
1050
|
/** ✍️
|
|
919
|
-
*
|
|
920
|
-
* @param horiz - horizontal alignment ('left', 'center', 'right')
|
|
921
|
-
* @param vert - vertical alignment ('top', 'middle', 'bottom', 'alphabetic')
|
|
1051
|
+
* Bold font weight.
|
|
922
1052
|
*/
|
|
923
|
-
|
|
1053
|
+
const BOLD: 'bold';
|
|
924
1054
|
|
|
925
1055
|
/** ✍️
|
|
926
|
-
*
|
|
927
|
-
* @param str - string to measure
|
|
928
|
-
* @returns width of the text in pixels
|
|
1056
|
+
* Bold and italic font style.
|
|
929
1057
|
*/
|
|
930
|
-
|
|
1058
|
+
const BOLDITALIC: 'italic bold';
|
|
931
1059
|
|
|
932
1060
|
/** ✍️
|
|
933
|
-
*
|
|
934
|
-
* @param str - string to measure
|
|
935
|
-
* @returns ascent of the text in pixels
|
|
1061
|
+
* Align text to the center.
|
|
936
1062
|
*/
|
|
937
|
-
|
|
1063
|
+
const CENTER: 'center';
|
|
938
1064
|
|
|
939
1065
|
/** ✍️
|
|
940
|
-
*
|
|
941
|
-
* @param str - string to measure
|
|
942
|
-
* @returns descent of the text in pixels
|
|
1066
|
+
* Align text to the left.
|
|
943
1067
|
*/
|
|
944
|
-
|
|
1068
|
+
const LEFT: 'left';
|
|
945
1069
|
|
|
946
1070
|
/** ✍️
|
|
947
|
-
*
|
|
948
|
-
* will not be the width and height of the text image, but of
|
|
949
|
-
* the bounding box that the text will be constrained within.
|
|
950
|
-
* @param str - string of text
|
|
951
|
-
* @param w - width of the bounding box
|
|
952
|
-
* @param h - height of the bounding box
|
|
953
|
-
* @returns An image object representing the rendered text.
|
|
1071
|
+
* Align text to the right.
|
|
954
1072
|
*/
|
|
955
|
-
|
|
1073
|
+
const RIGHT: 'right';
|
|
956
1074
|
|
|
957
1075
|
/** ✍️
|
|
958
|
-
*
|
|
959
|
-
* parameters and can optionally be constrained within a bounding box.
|
|
960
|
-
* @param str - string of text to display
|
|
961
|
-
* @param x - x-coordinate of the text's position
|
|
962
|
-
* @param y - y-coordinate of the text's position
|
|
963
|
-
* @param w - width of the bounding box
|
|
964
|
-
* @param h - height of the bounding box
|
|
1076
|
+
* Align text to the top.
|
|
965
1077
|
*/
|
|
966
|
-
|
|
1078
|
+
const TOP: 'top';
|
|
967
1079
|
|
|
968
1080
|
/** ✍️
|
|
969
|
-
*
|
|
970
|
-
* positioning of the image can be affected by the current text
|
|
971
|
-
* alignment and baseline settings.
|
|
972
|
-
* @param img - image object to render, typically generated from text
|
|
973
|
-
* @param x - x-coordinate where the image should be placed
|
|
974
|
-
* @param y - y-coordinate where the image should be placed
|
|
1081
|
+
* Align text to the bottom.
|
|
975
1082
|
*/
|
|
976
|
-
|
|
1083
|
+
const BOTTOM: 'bottom';
|
|
977
1084
|
|
|
978
1085
|
/** ✍️
|
|
979
|
-
*
|
|
980
|
-
* a specified number of digits before and after the decimal point,
|
|
981
|
-
* optionally adding padding with zeros.
|
|
982
|
-
* @param n - number to format
|
|
983
|
-
* @param l - minimum number of digits to appear before the decimal point, the number is padded with zeros if necessary.
|
|
984
|
-
* @param r - number of digits to appear after the decimal point
|
|
985
|
-
* @returns A string representation of the number, formatted according to the specified conditions.
|
|
1086
|
+
* Align text to the baseline (alphabetic).
|
|
986
1087
|
*/
|
|
987
|
-
|
|
1088
|
+
const BASELINE: 'alphabetic';
|
|
988
1089
|
|
|
989
1090
|
// ✨ ai
|
|
990
1091
|
|
|
991
1092
|
/** ✨
|
|
992
1093
|
* Run this function before a line of code that isn't working as expected.
|
|
993
|
-
* @param question - optional question to ask the AI
|
|
1094
|
+
* @param {string} [question] - optional question to ask the AI
|
|
994
1095
|
* @example
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1096
|
+
function draw() {
|
|
1097
|
+
askAI();
|
|
1098
|
+
text('Hello!');
|
|
1099
|
+
}
|
|
999
1100
|
*/
|
|
1000
1101
|
function askAI(question?: string): void;
|
|
1001
1102
|
|
|
@@ -1005,19 +1106,19 @@ declare global {
|
|
|
1005
1106
|
* Sets the color mode for the sketch. Changes the type of color object created by color functions.
|
|
1006
1107
|
*
|
|
1007
1108
|
* In WebGPU, the default color mode is 'rgb' in float format.
|
|
1008
|
-
* @param
|
|
1009
|
-
* @param format - color format (1
|
|
1109
|
+
* @param {'rgb' | 'srgb' | 'oklch'} mode - color mode
|
|
1110
|
+
* @param {1 | 255} format - color format (1 for float, 255 for integer)
|
|
1010
1111
|
*/
|
|
1011
1112
|
function colorMode(mode: 'rgb' | 'srgb' | 'oklch', format: 1 | 255): void;
|
|
1012
1113
|
|
|
1013
1114
|
/** 🎨
|
|
1014
|
-
*
|
|
1115
|
+
* Creates a new `Color` object. It can parse different
|
|
1015
1116
|
* color representations depending on the current `colorMode`.
|
|
1016
|
-
* @param c0 - first color component, or a string representing the color, or a `Color` object, or an array of components
|
|
1017
|
-
* @param c1 - second color component
|
|
1018
|
-
* @param c2 - third color component
|
|
1019
|
-
* @param c3 - fourth color component (alpha)
|
|
1020
|
-
* @returns
|
|
1117
|
+
* @param {string | number | Color | number[]} c0 - first color component, or a string representing the color, or a `Color` object, or an array of components
|
|
1118
|
+
* @param {number} [c1] - second color component
|
|
1119
|
+
* @param {number} [c2] - third color component
|
|
1120
|
+
* @param {number} [c3] - fourth color component (alpha)
|
|
1121
|
+
* @returns {Color} a new `Color` object
|
|
1021
1122
|
*/
|
|
1022
1123
|
function color(c0: string | number | Color | number[], c1?: number, c2?: number, c3?: number): Color;
|
|
1023
1124
|
|
|
@@ -1051,7 +1152,7 @@ declare global {
|
|
|
1051
1152
|
/** 🖲️
|
|
1052
1153
|
* The current button being pressed ('left', 'right', 'center'), or null if no button is pressed.
|
|
1053
1154
|
*/
|
|
1054
|
-
let mouseButton: string
|
|
1155
|
+
let mouseButton: string;
|
|
1055
1156
|
|
|
1056
1157
|
/** 🖲️
|
|
1057
1158
|
* True if a key is currently pressed, false otherwise.
|
|
@@ -1064,23 +1165,23 @@ declare global {
|
|
|
1064
1165
|
let mouseIsPressed: boolean;
|
|
1065
1166
|
|
|
1066
1167
|
/** 🖲️
|
|
1067
|
-
* The value of the last key pressed
|
|
1168
|
+
* The value of the last key pressed.
|
|
1068
1169
|
*/
|
|
1069
|
-
let key: string
|
|
1170
|
+
let key: string;
|
|
1070
1171
|
|
|
1071
1172
|
/** 🖲️
|
|
1072
|
-
* The keyCode of the last key pressed
|
|
1173
|
+
* The keyCode of the last key pressed.
|
|
1073
1174
|
*/
|
|
1074
|
-
let keyCode: number
|
|
1175
|
+
let keyCode: number;
|
|
1075
1176
|
|
|
1076
1177
|
/** 🖲️
|
|
1077
1178
|
* Sets the cursor to a specified type or image path.
|
|
1078
1179
|
* If an image is provided, optional x and y coordinates can
|
|
1079
1180
|
* specify the active point of the cursor.
|
|
1080
1181
|
* https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
|
|
1081
|
-
* @param name - name of the cursor or the path to an image
|
|
1082
|
-
* @param x - x-coordinate of the cursor's hot spot
|
|
1083
|
-
* @param y - y-coordinate of the cursor's hot spot
|
|
1182
|
+
* @param {string} name - name of the cursor or the path to an image
|
|
1183
|
+
* @param {number} [x] - x-coordinate of the cursor's hot spot
|
|
1184
|
+
* @param {number} [y] - y-coordinate of the cursor's hot spot
|
|
1084
1185
|
*/
|
|
1085
1186
|
function cursor(name: string, x?: number, y?: number): void;
|
|
1086
1187
|
|
|
@@ -1100,8 +1201,9 @@ declare global {
|
|
|
1100
1201
|
function exitPointerLock(): void;
|
|
1101
1202
|
|
|
1102
1203
|
/** 🖲️
|
|
1103
|
-
* Returns true if the
|
|
1104
|
-
* @param key
|
|
1204
|
+
* Returns true if the user is pressing the specified key, false otherwise. Accepts case-insensitive key names.
|
|
1205
|
+
* @param {string} key - key to check
|
|
1206
|
+
* @returns {boolean} true if the key is pressed, false otherwise
|
|
1105
1207
|
*/
|
|
1106
1208
|
function keyIsDown(key: string): boolean;
|
|
1107
1209
|
|
|
@@ -1109,89 +1211,89 @@ declare global {
|
|
|
1109
1211
|
|
|
1110
1212
|
/** 🧮
|
|
1111
1213
|
* Calculates the distance between two points.
|
|
1112
|
-
* @param x1 - x-coordinate of the first point
|
|
1113
|
-
* @param y1 - y-coordinate of the first point
|
|
1114
|
-
* @param x2 - x-coordinate of the second point
|
|
1115
|
-
* @param y2 - y-coordinate of the second point
|
|
1116
|
-
* @returns
|
|
1214
|
+
* @param {number} x1 - x-coordinate of the first point
|
|
1215
|
+
* @param {number} y1 - y-coordinate of the first point
|
|
1216
|
+
* @param {number} x2 - x-coordinate of the second point
|
|
1217
|
+
* @param {number} y2 - y-coordinate of the second point
|
|
1218
|
+
* @returns {number} distance between the points
|
|
1117
1219
|
*/
|
|
1118
1220
|
function dist(x1: number, y1: number, x2: number, y2: number): number;
|
|
1119
1221
|
|
|
1120
1222
|
/** 🧮
|
|
1121
1223
|
* Maps a number from one range to another.
|
|
1122
|
-
* @param value - incoming value to be converted
|
|
1123
|
-
* @param start1 -
|
|
1124
|
-
* @param stop1 -
|
|
1125
|
-
* @param start2 -
|
|
1126
|
-
* @param stop2 -
|
|
1127
|
-
* @returns mapped value
|
|
1224
|
+
* @param {number} value - incoming value to be converted
|
|
1225
|
+
* @param {number} start1 - lower bound of the value's current range
|
|
1226
|
+
* @param {number} stop1 - upper bound of the value's current range
|
|
1227
|
+
* @param {number} start2 - lower bound of the value's target range
|
|
1228
|
+
* @param {number} stop2 - upper bound of the value's target range
|
|
1229
|
+
* @returns {number} mapped value
|
|
1128
1230
|
*/
|
|
1129
1231
|
function map(value: number, start1: number, stop1: number, start2: number, stop2: number): number;
|
|
1130
1232
|
|
|
1131
1233
|
/** 🧮
|
|
1132
1234
|
* Sets the mode for interpreting and drawing angles. Can be either 'degrees' or 'radians'.
|
|
1133
|
-
* @param mode -
|
|
1235
|
+
* @param {'degrees' | 'radians'} mode - mode to set for angle interpretation
|
|
1134
1236
|
*/
|
|
1135
1237
|
function angleMode(mode: 'degrees' | 'radians'): void;
|
|
1136
1238
|
|
|
1137
1239
|
/** 🧮
|
|
1138
1240
|
* Converts degrees to radians.
|
|
1139
|
-
* @param degrees -
|
|
1140
|
-
* @returns
|
|
1241
|
+
* @param {number} degrees - angle in degrees
|
|
1242
|
+
* @returns {number} angle in radians
|
|
1141
1243
|
*/
|
|
1142
1244
|
function radians(degrees: number): number;
|
|
1143
1245
|
|
|
1144
1246
|
/** 🧮
|
|
1145
1247
|
* Converts radians to degrees.
|
|
1146
|
-
* @param radians -
|
|
1147
|
-
* @returns
|
|
1248
|
+
* @param {number} radians - angle in radians
|
|
1249
|
+
* @returns {number} angle in degrees
|
|
1148
1250
|
*/
|
|
1149
1251
|
function degrees(radians: number): number;
|
|
1150
1252
|
|
|
1151
1253
|
/** 🧮
|
|
1152
1254
|
* Calculates a number between two numbers at a specific increment.
|
|
1153
|
-
* @param start -
|
|
1154
|
-
* @param stop -
|
|
1155
|
-
* @param amt -
|
|
1156
|
-
* @returns
|
|
1255
|
+
* @param {number} start - first number
|
|
1256
|
+
* @param {number} stop - second number
|
|
1257
|
+
* @param {number} amt - amount to interpolate between the two values
|
|
1258
|
+
* @returns {number} interpolated number
|
|
1157
1259
|
*/
|
|
1158
1260
|
function lerp(start: number, stop: number, amt: number): number;
|
|
1159
1261
|
|
|
1160
1262
|
/** 🧮
|
|
1161
1263
|
* Constrains a value between a minimum and maximum value.
|
|
1162
|
-
* @param n -
|
|
1163
|
-
* @param low -
|
|
1164
|
-
* @param high -
|
|
1165
|
-
* @returns
|
|
1264
|
+
* @param {number} n - number to constrain
|
|
1265
|
+
* @param {number} low - lower bound
|
|
1266
|
+
* @param {number} high - upper bound
|
|
1267
|
+
* @returns {number} constrained value
|
|
1166
1268
|
*/
|
|
1167
1269
|
function constrain(n: number, low: number, high: number): number;
|
|
1168
1270
|
|
|
1169
1271
|
/** 🧮
|
|
1170
1272
|
* Normalizes a number from another range into a value between 0 and 1.
|
|
1171
|
-
* @param n -
|
|
1172
|
-
* @param start -
|
|
1173
|
-
* @param stop -
|
|
1174
|
-
* @returns
|
|
1273
|
+
* @param {number} n - number to normalize
|
|
1274
|
+
* @param {number} start - lower bound of the range
|
|
1275
|
+
* @param {number} stop - upper bound of the range
|
|
1276
|
+
* @returns {number} normalized number
|
|
1175
1277
|
*/
|
|
1176
1278
|
function norm(n: number, start: number, stop: number): number;
|
|
1177
1279
|
|
|
1178
1280
|
/** 🧮
|
|
1179
1281
|
* Calculates the square of a number.
|
|
1180
|
-
* @param n -
|
|
1181
|
-
* @returns
|
|
1282
|
+
* @param {number} n - number to square
|
|
1283
|
+
* @returns {number} square of the number
|
|
1182
1284
|
*/
|
|
1183
1285
|
function sq(n: number): number;
|
|
1184
1286
|
|
|
1185
1287
|
/** 🧮
|
|
1186
1288
|
* Calculates the fractional part of a number.
|
|
1187
|
-
* @param n -
|
|
1188
|
-
* @returns
|
|
1289
|
+
* @param {number} n - number whose fractional part is to be calculated
|
|
1290
|
+
* @returns {number} fractional part of the number
|
|
1189
1291
|
*/
|
|
1190
1292
|
function fract(n: number): number;
|
|
1191
1293
|
|
|
1192
1294
|
/** 🧮
|
|
1193
1295
|
* Sets the seed for the random number generator.
|
|
1194
|
-
* @param seed -
|
|
1296
|
+
* @param {number} seed - seed value
|
|
1195
1297
|
*/
|
|
1196
1298
|
function randomSeed(seed: number): void;
|
|
1197
1299
|
|
|
@@ -1200,60 +1302,78 @@ declare global {
|
|
|
1200
1302
|
* If one number argument is provided, returns a random number between 0 and the provided value.
|
|
1201
1303
|
* If two number arguments are provided, returns a random number between the two values.
|
|
1202
1304
|
* If an array is provided, returns a random element from the array.
|
|
1203
|
-
* @param a - lower bound (inclusive) or an array
|
|
1204
|
-
* @param b - upper bound (exclusive)
|
|
1205
|
-
* @returns
|
|
1305
|
+
* @param {number | any[]} [a] - lower bound (inclusive) or an array
|
|
1306
|
+
* @param {number} [b] - upper bound (exclusive)
|
|
1307
|
+
* @returns {number | any} a random number or element
|
|
1206
1308
|
*/
|
|
1207
1309
|
function random(a?: number | any[], b?: number): number | any;
|
|
1208
1310
|
|
|
1209
1311
|
/** 🧮
|
|
1210
1312
|
* Sets the random number generation method.
|
|
1211
|
-
* @param method - method to use for random number generation
|
|
1313
|
+
* @param {any} method - method to use for random number generation
|
|
1212
1314
|
*/
|
|
1213
1315
|
function randomGenerator(method: any): void;
|
|
1214
1316
|
|
|
1215
1317
|
/** 🧮
|
|
1216
1318
|
* Generates a random number following a Gaussian (normal) distribution.
|
|
1217
|
-
* @param mean - mean (center) of the distribution
|
|
1218
|
-
* @param std - standard deviation (spread or "width") of the distribution
|
|
1219
|
-
* @returns
|
|
1319
|
+
* @param {number} mean - mean (center) of the distribution
|
|
1320
|
+
* @param {number} std - standard deviation (spread or "width") of the distribution
|
|
1321
|
+
* @returns {number} a random number following a Gaussian distribution
|
|
1220
1322
|
*/
|
|
1221
1323
|
function randomGaussian(mean: number, std: number): number;
|
|
1222
1324
|
|
|
1223
1325
|
/** 🧮
|
|
1224
1326
|
* Generates a random number following an exponential distribution.
|
|
1225
|
-
* @returns
|
|
1327
|
+
* @returns {number} a random number following an exponential distribution
|
|
1226
1328
|
*/
|
|
1227
1329
|
function randomExponential(): number;
|
|
1228
1330
|
|
|
1229
1331
|
/** 🧮
|
|
1230
1332
|
* Sets the noise generation mode.
|
|
1231
|
-
* @param
|
|
1333
|
+
* @param {'perlin' | 'simplex' | 'blocky'} mode - noise generation mode
|
|
1232
1334
|
*/
|
|
1233
1335
|
function noiseMode(mode: 'perlin' | 'simplex' | 'blocky'): void;
|
|
1234
1336
|
|
|
1235
1337
|
/** 🧮
|
|
1236
1338
|
* Sets the seed value for noise generation.
|
|
1237
|
-
* @param seed
|
|
1339
|
+
* @param {number} seed - seed value
|
|
1238
1340
|
*/
|
|
1239
1341
|
function noiseSeed(seed: number): void;
|
|
1240
1342
|
|
|
1241
1343
|
/** 🧮
|
|
1242
1344
|
* Generates a noise value based on the x, y, and z inputs.
|
|
1243
|
-
* @param x
|
|
1244
|
-
* @param y
|
|
1245
|
-
* @param z
|
|
1246
|
-
* @returns a noise value
|
|
1345
|
+
* @param {number} [x] - x-coordinate input
|
|
1346
|
+
* @param {number} [y] - y-coordinate input
|
|
1347
|
+
* @param {number} [z] - z-coordinate input
|
|
1348
|
+
* @returns {number} a noise value
|
|
1247
1349
|
*/
|
|
1248
1350
|
function noise(x?: number, y?: number, z?: number): number;
|
|
1249
1351
|
|
|
1250
1352
|
/** 🧮
|
|
1251
1353
|
* Sets the level of detail for noise generation.
|
|
1252
|
-
* @param lod - level of detail (number of octaves)
|
|
1253
|
-
* @param falloff - falloff rate for each octave
|
|
1354
|
+
* @param {number} lod - level of detail (number of octaves)
|
|
1355
|
+
* @param {number} falloff - falloff rate for each octave
|
|
1254
1356
|
*/
|
|
1255
1357
|
function noiseDetail(lod: number, falloff: number): void;
|
|
1256
1358
|
|
|
1359
|
+
/** 🧮
|
|
1360
|
+
* The ratio of a circle's circumference to its diameter.
|
|
1361
|
+
* Approximately 3.14159.
|
|
1362
|
+
*/
|
|
1363
|
+
const PI: number;
|
|
1364
|
+
|
|
1365
|
+
/** 🧮
|
|
1366
|
+
* 2 * PI.
|
|
1367
|
+
* Approximately 6.28319.
|
|
1368
|
+
*/
|
|
1369
|
+
const TWO_PI: number;
|
|
1370
|
+
|
|
1371
|
+
/** 🧮
|
|
1372
|
+
* Alias for 2 * PI.
|
|
1373
|
+
* Approximately 6.28319.
|
|
1374
|
+
*/
|
|
1375
|
+
const TAU: number;
|
|
1376
|
+
|
|
1257
1377
|
// 🔊 sound
|
|
1258
1378
|
|
|
1259
1379
|
/** 🔊
|
|
@@ -1263,27 +1383,27 @@ declare global {
|
|
|
1263
1383
|
class Sound extends Audio {
|
|
1264
1384
|
/** 🔊
|
|
1265
1385
|
* Creates a new `Sound` object.
|
|
1266
|
-
* @param path - path to the sound file
|
|
1386
|
+
* @param {string} path - path to the sound file
|
|
1267
1387
|
*/
|
|
1268
1388
|
constructor(path: string);
|
|
1269
1389
|
|
|
1270
1390
|
/** 🔊
|
|
1271
1391
|
* Sets the volume of the sound.
|
|
1272
|
-
* @param level - volume level, between 0.0 and 1.0
|
|
1392
|
+
* @param {number} level - volume level, between 0.0 and 1.0
|
|
1273
1393
|
* @deprecated Set the `.volume` property instead.
|
|
1274
1394
|
*/
|
|
1275
1395
|
setVolume(level: number): void;
|
|
1276
1396
|
|
|
1277
1397
|
/** 🔊
|
|
1278
1398
|
* Sets whether the sound should loop.
|
|
1279
|
-
* @param loop -
|
|
1399
|
+
* @param {boolean} loop - a boolean indicating whether to loop the sound
|
|
1280
1400
|
* @deprecated Set the `.loop` property instead.
|
|
1281
1401
|
*/
|
|
1282
1402
|
setLoop(loop: boolean): void;
|
|
1283
1403
|
|
|
1284
1404
|
/** 🔊
|
|
1285
1405
|
* Sets the stereo panning of the sound.
|
|
1286
|
-
* @param value -
|
|
1406
|
+
* @param {number} value - panning value, between -1 (full left) and 1 (full right)
|
|
1287
1407
|
* @deprecated Set the `.pan` property instead.
|
|
1288
1408
|
*/
|
|
1289
1409
|
setPan(value: number): void;
|
|
@@ -1291,20 +1411,21 @@ declare global {
|
|
|
1291
1411
|
|
|
1292
1412
|
/** 🔊
|
|
1293
1413
|
* Loads a sound file and returns an enhanced Audio object with additional methods.
|
|
1294
|
-
* @param path -
|
|
1295
|
-
* @param cb -
|
|
1296
|
-
* @returns
|
|
1414
|
+
* @param {string} path - path to the sound file
|
|
1415
|
+
* @param {(a: Sound) => void} [cb] - an optional callback function that is called when the sound is ready to play
|
|
1416
|
+
* @returns {Sound} an enhanced Audio object with additional methods for volume, looping, and panning
|
|
1297
1417
|
*/
|
|
1298
1418
|
function loadSound(path: string, cb?: (a: Sound) => void): Sound;
|
|
1299
1419
|
|
|
1300
1420
|
/** 🔊
|
|
1301
1421
|
* Returns the AudioContext used by the library. Creates a new one if it doesn't exist.
|
|
1302
|
-
* @returns
|
|
1422
|
+
* @returns {AudioContext} AudioContext instance
|
|
1303
1423
|
*/
|
|
1304
1424
|
function getAudioContext(): AudioContext;
|
|
1305
1425
|
|
|
1306
1426
|
/** 🔊
|
|
1307
1427
|
* Resumes the AudioContext if it has been suspended.
|
|
1428
|
+
* @returns {Promise<void>} a promise that resolves when the AudioContext is resumed
|
|
1308
1429
|
*/
|
|
1309
1430
|
function userStartAudio(): Promise<void>;
|
|
1310
1431
|
|
|
@@ -1312,44 +1433,43 @@ declare global {
|
|
|
1312
1433
|
|
|
1313
1434
|
/** 🛠️
|
|
1314
1435
|
* Loads a text file from the specified path. Result is one string.
|
|
1315
|
-
* @param path -
|
|
1316
|
-
* @param cb - a callback function that is run when the file is loaded
|
|
1436
|
+
* @param {string} path - path to the text file
|
|
1437
|
+
* @param {(result: string) => void} cb - a callback function that is run when the file is loaded
|
|
1317
1438
|
*/
|
|
1318
1439
|
function loadText(path: string, cb: (result: string) => void): void;
|
|
1319
1440
|
|
|
1320
1441
|
/** 🛠️
|
|
1321
1442
|
* Loads a JSON file from the specified path. Result depends on the
|
|
1322
1443
|
* JSON file's contents, but is typically an object or array.
|
|
1323
|
-
* @param path -
|
|
1324
|
-
* @param cb - a callback function that is run when the file is loaded
|
|
1444
|
+
* @param {string} path - path to the JSON file
|
|
1445
|
+
* @param {(result: any) => void} cb - a callback function that is run when the file is loaded
|
|
1325
1446
|
*/
|
|
1326
1447
|
function loadJSON(path: string, cb: (result: any) => void): void;
|
|
1327
1448
|
|
|
1328
1449
|
/** 🛠️
|
|
1329
|
-
* Loads a CSV file from the specified path. Result is an array
|
|
1330
|
-
*
|
|
1331
|
-
* @param
|
|
1332
|
-
* @param cb - a callback function that is run when the file is loaded
|
|
1450
|
+
* Loads a CSV file from the specified path. Result is an array of objects.
|
|
1451
|
+
* @param {string} path - path to the CSV file
|
|
1452
|
+
* @param {(result: object[]) => void} cb - a callback function that is run when the file is loaded
|
|
1333
1453
|
*/
|
|
1334
1454
|
function loadCSV(path: string, cb: (result: object[]) => void): void;
|
|
1335
1455
|
|
|
1336
1456
|
/** 🛠️
|
|
1337
1457
|
* Stores an item in localStorage.
|
|
1338
|
-
* @param key -
|
|
1339
|
-
* @param value -
|
|
1458
|
+
* @param {string} key - key under which to store the item
|
|
1459
|
+
* @param {string} value - value to store
|
|
1340
1460
|
*/
|
|
1341
1461
|
function storeItem(key: string, value: string): void;
|
|
1342
1462
|
|
|
1343
1463
|
/** 🛠️
|
|
1344
1464
|
* Retrieves an item from localStorage.
|
|
1345
|
-
* @param key -
|
|
1346
|
-
* @returns
|
|
1465
|
+
* @param {string} key - key of the item to retrieve
|
|
1466
|
+
* @returns {string} value of the retrieved item
|
|
1347
1467
|
*/
|
|
1348
|
-
function getItem(key: string): string
|
|
1468
|
+
function getItem(key: string): string;
|
|
1349
1469
|
|
|
1350
1470
|
/** 🛠️
|
|
1351
1471
|
* Removes an item from localStorage.
|
|
1352
|
-
* @param key -
|
|
1472
|
+
* @param {string} key - key of the item to remove
|
|
1353
1473
|
*/
|
|
1354
1474
|
function removeItem(key: string): void;
|
|
1355
1475
|
|
|
@@ -1360,31 +1480,31 @@ declare global {
|
|
|
1360
1480
|
|
|
1361
1481
|
/** 🛠️
|
|
1362
1482
|
* Returns the current year.
|
|
1363
|
-
* @returns
|
|
1483
|
+
* @returns {number} current year
|
|
1364
1484
|
*/
|
|
1365
1485
|
function year(): number;
|
|
1366
1486
|
|
|
1367
1487
|
/** 🛠️
|
|
1368
|
-
* Returns the current day of the
|
|
1369
|
-
* @returns
|
|
1488
|
+
* Returns the current day of the month.
|
|
1489
|
+
* @returns {number} current day
|
|
1370
1490
|
*/
|
|
1371
1491
|
function day(): number;
|
|
1372
1492
|
|
|
1373
1493
|
/** 🛠️
|
|
1374
1494
|
* Returns the current hour.
|
|
1375
|
-
* @returns
|
|
1495
|
+
* @returns {number} current hour
|
|
1376
1496
|
*/
|
|
1377
1497
|
function hour(): number;
|
|
1378
1498
|
|
|
1379
1499
|
/** 🛠️
|
|
1380
1500
|
* Returns the current minute.
|
|
1381
|
-
* @returns
|
|
1501
|
+
* @returns {number} current minute
|
|
1382
1502
|
*/
|
|
1383
1503
|
function minute(): number;
|
|
1384
1504
|
|
|
1385
1505
|
/** 🛠️
|
|
1386
1506
|
* Returns the current second.
|
|
1387
|
-
* @returns
|
|
1507
|
+
* @returns {number} current second
|
|
1388
1508
|
*/
|
|
1389
1509
|
function second(): number;
|
|
1390
1510
|
|
|
@@ -1411,130 +1531,143 @@ declare global {
|
|
|
1411
1531
|
|
|
1412
1532
|
/** ↗️
|
|
1413
1533
|
* Constructs a new Vector object.
|
|
1414
|
-
* @param x -
|
|
1415
|
-
* @param y -
|
|
1416
|
-
* @param z -
|
|
1534
|
+
* @param {number} x - x component of the vector
|
|
1535
|
+
* @param {number} y - y component of the vector
|
|
1536
|
+
* @param {number} [z] - optional. The z component of the vector
|
|
1417
1537
|
*/
|
|
1418
1538
|
constructor(x: number, y: number, z?: number);
|
|
1419
1539
|
|
|
1420
1540
|
/** ↗️
|
|
1421
1541
|
* Adds a vector to this vector.
|
|
1422
|
-
* @param v -
|
|
1542
|
+
* @param {Vector} v - vector to add
|
|
1543
|
+
* @returns {Vector} resulting vector after addition
|
|
1423
1544
|
*/
|
|
1424
1545
|
add(v: Vector): Vector;
|
|
1425
1546
|
|
|
1426
1547
|
/** ↗️
|
|
1427
1548
|
* Subtracts a vector from this vector.
|
|
1428
|
-
* @param v -
|
|
1549
|
+
* @param {Vector} v - vector to subtract
|
|
1550
|
+
* @returns {Vector} resulting vector after subtraction
|
|
1429
1551
|
*/
|
|
1430
1552
|
sub(v: Vector): Vector;
|
|
1431
1553
|
|
|
1432
1554
|
/** ↗️
|
|
1433
1555
|
* Multiplies this vector by a scalar or element-wise by another vector.
|
|
1434
|
-
* @param n -
|
|
1556
|
+
* @param {number | Vector} n - scalar to multiply by, or a vector for element-wise multiplication
|
|
1557
|
+
* @returns {Vector} resulting vector after multiplication
|
|
1435
1558
|
*/
|
|
1436
1559
|
mult(n: number | Vector): Vector;
|
|
1437
1560
|
|
|
1438
1561
|
/** ↗️
|
|
1439
1562
|
* Divides this vector by a scalar or element-wise by another vector.
|
|
1440
|
-
* @param n -
|
|
1563
|
+
* @param {number | Vector} n - scalar to divide by, or a vector for element-wise division
|
|
1564
|
+
* @returns {Vector} resulting vector after division
|
|
1441
1565
|
*/
|
|
1442
1566
|
div(n: number | Vector): Vector;
|
|
1443
1567
|
|
|
1444
1568
|
/** ↗️
|
|
1445
1569
|
* Calculates the magnitude (length) of the vector.
|
|
1446
|
-
* @returns
|
|
1570
|
+
* @returns {number} magnitude of the vector
|
|
1447
1571
|
*/
|
|
1448
1572
|
mag(): number;
|
|
1449
1573
|
|
|
1450
1574
|
/** ↗️
|
|
1451
1575
|
* Normalizes the vector to a length of 1 (making it a unit vector).
|
|
1576
|
+
* @returns {Vector} this vector after normalization
|
|
1452
1577
|
*/
|
|
1453
1578
|
normalize(): Vector;
|
|
1454
1579
|
|
|
1455
1580
|
/** ↗️
|
|
1456
1581
|
* Sets the magnitude of the vector to the specified length.
|
|
1457
|
-
* @param len -
|
|
1582
|
+
* @param {number} len - new length of the vector
|
|
1583
|
+
* @returns {Vector} this vector after setting magnitude
|
|
1458
1584
|
*/
|
|
1459
1585
|
setMag(len: number): Vector;
|
|
1460
1586
|
|
|
1461
1587
|
/** ↗️
|
|
1462
1588
|
* Calculates the dot product of this vector and another vector.
|
|
1463
|
-
* @param v -
|
|
1464
|
-
* @returns
|
|
1589
|
+
* @param {Vector} v - other vector
|
|
1590
|
+
* @returns {number} dot product
|
|
1465
1591
|
*/
|
|
1466
1592
|
dot(v: Vector): number;
|
|
1467
1593
|
|
|
1468
1594
|
/** ↗️
|
|
1469
1595
|
* Calculates the cross product of this vector and another vector.
|
|
1470
|
-
* @param v -
|
|
1471
|
-
* @returns
|
|
1596
|
+
* @param {Vector} v - other vector
|
|
1597
|
+
* @returns {Vector} a new vector that is the cross product of this vector and the given vector
|
|
1472
1598
|
*/
|
|
1473
1599
|
cross(v: Vector): Vector;
|
|
1474
1600
|
|
|
1475
1601
|
/** ↗️
|
|
1476
1602
|
* Calculates the distance between this vector and another vector.
|
|
1477
|
-
* @param v -
|
|
1478
|
-
* @returns
|
|
1603
|
+
* @param {Vector} v - other vector
|
|
1604
|
+
* @returns {number} distance
|
|
1479
1605
|
*/
|
|
1480
1606
|
dist(v: Vector): number;
|
|
1481
1607
|
|
|
1482
1608
|
/** ↗️
|
|
1483
1609
|
* Copies this vector.
|
|
1484
|
-
* @returns
|
|
1610
|
+
* @returns {Vector} a new vector with the same components as this one
|
|
1485
1611
|
*/
|
|
1486
1612
|
copy(): Vector;
|
|
1487
1613
|
|
|
1488
1614
|
/** ↗️
|
|
1489
1615
|
* Sets the components of the vector.
|
|
1490
|
-
* @param x -
|
|
1491
|
-
* @param y -
|
|
1492
|
-
* @param z -
|
|
1616
|
+
* @param {number} x - x component
|
|
1617
|
+
* @param {number} y - y component
|
|
1618
|
+
* @param {number} [z] - optional. The z component
|
|
1619
|
+
* @returns {void}
|
|
1493
1620
|
*/
|
|
1494
1621
|
set(x: number, y: number, z?: number): void;
|
|
1495
1622
|
|
|
1496
1623
|
/** ↗️
|
|
1497
1624
|
* Limits the magnitude of the vector to the value used for the max parameter.
|
|
1498
|
-
* @param max -
|
|
1625
|
+
* @param {number} max - maximum magnitude for the vector
|
|
1626
|
+
* @returns {Vector} this vector after limiting
|
|
1499
1627
|
*/
|
|
1500
1628
|
limit(max: number): Vector;
|
|
1501
1629
|
|
|
1502
1630
|
/** ↗️
|
|
1503
1631
|
* Calculates the angle of rotation for this vector (only 2D vectors).
|
|
1504
|
-
* @returns
|
|
1632
|
+
* @returns {number} angle of rotation
|
|
1505
1633
|
*/
|
|
1506
1634
|
heading(): number;
|
|
1507
1635
|
|
|
1508
1636
|
/** ↗️
|
|
1509
1637
|
* Rotates the vector to a specific angle without changing its magnitude.
|
|
1638
|
+
* @param {number} angle - angle in radians to set the heading to
|
|
1639
|
+
* @returns {Vector} this vector after setting the heading
|
|
1510
1640
|
*/
|
|
1511
1641
|
setHeading(angle: number): Vector;
|
|
1512
1642
|
|
|
1513
1643
|
/** ↗️
|
|
1514
1644
|
* Rotates the vector by the given angle (only 2D vectors).
|
|
1515
|
-
* @param angle -
|
|
1645
|
+
* @param {number} angle - angle of rotation in radians
|
|
1646
|
+
* @returns {Vector} this vector after rotation
|
|
1516
1647
|
*/
|
|
1517
1648
|
rotate(angle: number): Vector;
|
|
1518
1649
|
|
|
1519
1650
|
/** ↗️
|
|
1520
1651
|
* Linearly interpolates between this vector and another vector.
|
|
1521
|
-
* @param v -
|
|
1522
|
-
* @param amt -
|
|
1652
|
+
* @param {Vector} v - vector to interpolate towards
|
|
1653
|
+
* @param {number} amt - amount of interpolation; a number between 0.0 (close to the current vector) and 1.0 (close to the target vector)
|
|
1654
|
+
* @returns {Vector} this vector after interpolation
|
|
1523
1655
|
*/
|
|
1524
1656
|
lerp(v: Vector, amt: number): Vector;
|
|
1525
1657
|
|
|
1526
1658
|
/** ↗️
|
|
1527
1659
|
* Linearly interpolates between this vector and another vector, including the magnitude.
|
|
1528
|
-
* @param v -
|
|
1529
|
-
* @param amt -
|
|
1660
|
+
* @param {Vector} v - vector to interpolate towards
|
|
1661
|
+
* @param {number} amt - amount of interpolation; a number between 0.0 (close to the current vector) and 1.0 (close to the target vector)
|
|
1662
|
+
* @returns {Vector} this vector after spherical interpolation
|
|
1530
1663
|
*/
|
|
1531
1664
|
slerp(v: Vector, amt: number): Vector;
|
|
1532
1665
|
|
|
1533
1666
|
/** ↗️
|
|
1534
1667
|
* Static method to create a new 2D vector from an angle.
|
|
1535
|
-
* @param angle -
|
|
1536
|
-
* @param length -
|
|
1537
|
-
* @returns
|
|
1668
|
+
* @param {number} angle - angle in radians
|
|
1669
|
+
* @param {number} [length] - length of the vector. The default is 1
|
|
1670
|
+
* @returns {Vector} a new 2D vector pointing in the direction of the given angle
|
|
1538
1671
|
*/
|
|
1539
1672
|
static fromAngle(angle: number, length?: number): Vector;
|
|
1540
1673
|
}
|