q5 3.7.5 → 3.7.6
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/defs/q5-c2d-es.d.ts +3223 -52
- package/defs/q5-c2d.d.ts +10 -26
- package/defs/q5-es.d.ts +3472 -59
- package/deno.json +1 -1
- package/package.json +1 -1
- package/q5.d.ts +10 -26
- package/q5.js +286 -7
- package/q5.min.js +1 -1
package/defs/q5-es.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare global {
|
|
|
5
5
|
/**
|
|
6
6
|
* Bienvenido a la documentación de q5! 🤩
|
|
7
7
|
*
|
|
8
|
-
* ¿Primera vez programando? Revisa la [guía para principiantes de q5].
|
|
8
|
+
* ¿Primera vez programando? Revisa la [guía para principiantes de q5](https://github.com/q5js/q5.js/wiki/q5-Beginner's-Brief).
|
|
9
9
|
*
|
|
10
10
|
* En estas páginas de "Aprender" puedes experimentar editando los mini ejemplos. ¡Diviértete! 😎
|
|
11
11
|
*/
|
|
@@ -27,14 +27,14 @@ declare global {
|
|
|
27
27
|
* fondo('silver');
|
|
28
28
|
* círculo(0, 0, 80);
|
|
29
29
|
*/
|
|
30
|
-
function crearLienzo(ancho?: number, alto?: number, opciones
|
|
30
|
+
function crearLienzo(ancho?: number, alto?: number, opciones?: CanvasRenderingContext2DSettings): Promise<HTMLCanvasElement>;
|
|
31
31
|
|
|
32
32
|
/** ⭐
|
|
33
33
|
* Función a declarar. Se ejecutará 60 veces por segundo de forma predeterminada. Tiene comportamiento de bucle, lo que permite hacer animaciones cuadro a cuadro.
|
|
34
34
|
* @example
|
|
35
35
|
* q5.dibujar = function () {
|
|
36
36
|
* fondo('silver');
|
|
37
|
-
* círculo(
|
|
37
|
+
* círculo(ratónX, ratónY, 80);
|
|
38
38
|
* };
|
|
39
39
|
*/
|
|
40
40
|
function dibujar(): void;
|
|
@@ -46,11 +46,11 @@ declare global {
|
|
|
46
46
|
* @param {any} mensaje a imprimir
|
|
47
47
|
* @example
|
|
48
48
|
* q5.dibujar = function () {
|
|
49
|
-
* círculo(
|
|
50
|
-
* log('
|
|
49
|
+
* círculo(ratónX, ratónY, 80);
|
|
50
|
+
* log('El ratón está en:', ratónX, ratónY);
|
|
51
51
|
* };
|
|
52
52
|
*/
|
|
53
|
-
function log(
|
|
53
|
+
function log(mensaje: any): void;
|
|
54
54
|
|
|
55
55
|
// 🧑🎨 shapes
|
|
56
56
|
|
|
@@ -65,94 +65,3507 @@ declare global {
|
|
|
65
65
|
*/
|
|
66
66
|
function círculo(): void;
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
/** 🧑🎨
|
|
69
|
+
* Dibuja una elipse.
|
|
70
|
+
* @param {number} x posición x
|
|
71
|
+
* @param {number} y posición y
|
|
72
|
+
* @param {number} ancho ancho de la elipse
|
|
73
|
+
* @param {number} [alto] alto de la elipse
|
|
74
|
+
* @example
|
|
75
|
+
* await crearLienzo(200, 100);
|
|
76
|
+
* elipse(0, 0, 160, 80);
|
|
77
|
+
*/
|
|
78
|
+
function elipse(x: number, y: number, ancho: number, alto?: number): void;
|
|
69
79
|
|
|
70
|
-
/**
|
|
71
|
-
* Dibuja
|
|
80
|
+
/** 🧑🎨
|
|
81
|
+
* Dibuja un rectángulo o un rectángulo redondeado.
|
|
82
|
+
* @param {number} x posición x
|
|
83
|
+
* @param {number} y posición y
|
|
84
|
+
* @param {number} w ancho del rectángulo
|
|
85
|
+
* @param {number} [h] alto del rectángulo
|
|
86
|
+
* @param {number} [redondeado] radio para todas las esquinas
|
|
87
|
+
* @example
|
|
88
|
+
* await crearLienzo(200);
|
|
89
|
+
* fondo(0.8);
|
|
72
90
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
91
|
+
* rect(-70, -80, 40, 60);
|
|
92
|
+
* rect(-20, -30, 40, 60, 10);
|
|
93
|
+
* rect(30, 20, 40, 60, 30);
|
|
94
|
+
*/
|
|
95
|
+
function rect(x: number, y: number, ancho: number, alto?: number, redondeado?: number): void;
|
|
96
|
+
|
|
97
|
+
/** 🧑🎨
|
|
98
|
+
* Dibuja un cuadrado o un cuadrado redondeado.
|
|
99
|
+
* @param {number} x posición x
|
|
100
|
+
* @param {number} y posición y
|
|
101
|
+
* @param {number} tamaño tamaño de los lados del cuadrado
|
|
102
|
+
* @param {number} [redondeado] radio para todas las esquinas
|
|
103
|
+
* @example
|
|
104
|
+
* await crearLienzo(200);
|
|
105
|
+
* fondo(0.8);
|
|
106
|
+
*
|
|
107
|
+
* cuadrado(-70, -70, 40);
|
|
108
|
+
* cuadrado(-20, -20, 40, 10);
|
|
109
|
+
* cuadrado(30, 30, 40, 30);
|
|
110
|
+
*/
|
|
111
|
+
function cuadrado(x: number, y: number, tamaño: number, redondeado?: number): void;
|
|
112
|
+
|
|
113
|
+
/** 🧑🎨
|
|
114
|
+
* Dibuja un punto en el lienzo.
|
|
115
|
+
* @param {number} x posición x
|
|
116
|
+
* @param {number} y posición y
|
|
77
117
|
* @example
|
|
78
118
|
* await crearLienzo(200, 100);
|
|
79
|
-
*
|
|
119
|
+
* trazo('white');
|
|
120
|
+
* punto(-25, 0);
|
|
121
|
+
*
|
|
122
|
+
* grosorTrazo(10);
|
|
123
|
+
* punto(25, 0);
|
|
124
|
+
*/
|
|
125
|
+
function punto(x: number, y: number): void;
|
|
126
|
+
|
|
127
|
+
/** 🧑🎨
|
|
128
|
+
* Dibuja una línea en el lienzo.
|
|
129
|
+
* @param {number} x1 posición x del primer punto
|
|
130
|
+
* @param {number} y1 posición y del primer punto
|
|
131
|
+
* @param {number} x2 posición x del segundo punto
|
|
132
|
+
* @param {number} y2 posición y del segundo punto
|
|
133
|
+
* @example
|
|
134
|
+
* await crearLienzo(200, 100);
|
|
135
|
+
* trazo('lime');
|
|
136
|
+
* línea(-80, -30, 80, 30);
|
|
137
|
+
*/
|
|
138
|
+
function línea(): void;
|
|
139
|
+
|
|
140
|
+
/** 🧑🎨
|
|
141
|
+
* Dibuja una cápsula.
|
|
142
|
+
* @param {number} x1 posición x del primer punto
|
|
143
|
+
* @param {number} y1 posición y del primer punto
|
|
144
|
+
* @param {number} x2 posición x del segundo punto
|
|
145
|
+
* @param {number} y2 posición y del segundo punto
|
|
146
|
+
* @param {number} r radio de los extremos semicirculares de la cápsula
|
|
147
|
+
* @example
|
|
148
|
+
* await crearLienzo(200, 100);
|
|
149
|
+
* fondo(0.8);
|
|
150
|
+
* grosorTrazo(5);
|
|
151
|
+
* cápsula(-60, -10, 60, 10, 10);
|
|
80
152
|
* @example
|
|
81
153
|
* q5.dibujar = function () {
|
|
82
|
-
* fondo(0.
|
|
83
|
-
*
|
|
154
|
+
* fondo(0.8);
|
|
155
|
+
* relleno('cyan');
|
|
156
|
+
* grosorTrazo(10);
|
|
157
|
+
* cápsula(0, 0, ratónX, ratónY, 20);
|
|
84
158
|
* };
|
|
85
159
|
*/
|
|
86
|
-
function
|
|
160
|
+
function cápsula(): void;
|
|
87
161
|
|
|
88
|
-
|
|
162
|
+
/** 🧑🎨
|
|
163
|
+
* Establecer a `ESQUINA` (por defecto), `CENTRO`, `RADIO`, o `ESQUINAS`.
|
|
164
|
+
*
|
|
165
|
+
* Cambia cómo se interpretan las primeras cuatro entradas para
|
|
166
|
+
* `rect` y `cuadrado`.
|
|
167
|
+
* @param {string} modo
|
|
168
|
+
* @example
|
|
169
|
+
* await crearLienzo(200, 100);
|
|
170
|
+
* fondo(0.8);
|
|
171
|
+
* modoRect(ESQUINA);
|
|
172
|
+
*
|
|
173
|
+
* // ( x, y, w, h)
|
|
174
|
+
* rect(-50, -25, 100, 50);
|
|
175
|
+
* @example
|
|
176
|
+
* await crearLienzo(200, 100);
|
|
177
|
+
* fondo(0.8);
|
|
178
|
+
* modoRect(CENTRO);
|
|
179
|
+
*
|
|
180
|
+
* // ( cX, cY, w, h)
|
|
181
|
+
* rect(0, 0, 100, 50);
|
|
182
|
+
* @example
|
|
183
|
+
* await crearLienzo(200, 100);
|
|
184
|
+
* fondo(0.8);
|
|
185
|
+
* modoRect(RADIO);
|
|
186
|
+
*
|
|
187
|
+
* // ( cX, cY, rX, rY)
|
|
188
|
+
* rect(0, 0, 50, 25);
|
|
189
|
+
* @example
|
|
190
|
+
* await crearLienzo(200, 100);
|
|
191
|
+
* fondo(0.8);
|
|
192
|
+
* modoRect(ESQUINAS);
|
|
193
|
+
*
|
|
194
|
+
* // ( x1, y1, x2, y2)
|
|
195
|
+
* rect(-50, -25, 50, 25);
|
|
196
|
+
*/
|
|
197
|
+
function modoRect(modo: string): void;
|
|
89
198
|
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
199
|
+
/** 🧑🎨
|
|
200
|
+
* Establecer a `CENTRO` (por defecto), `RADIO`, `ESQUINA`, o `ESQUINAS`.
|
|
201
|
+
*
|
|
202
|
+
* Cambia cómo se interpretan las primeras cuatro entradas para
|
|
203
|
+
* `elipse`, `círculo`, y `arco`.
|
|
204
|
+
* @param {string} modo
|
|
205
|
+
* @example
|
|
206
|
+
* await crearLienzo(200, 100);
|
|
207
|
+
* fondo(0.8);
|
|
208
|
+
* modoEliptico(CENTRO);
|
|
209
|
+
*
|
|
210
|
+
* // ( x, y, w, h)
|
|
211
|
+
* elipse(0, 0, 100, 50);
|
|
212
|
+
* @example
|
|
213
|
+
* await crearLienzo(200, 100);
|
|
214
|
+
* fondo(0.8);
|
|
215
|
+
* modoEliptico(RADIO);
|
|
216
|
+
*
|
|
217
|
+
* // ( x, y, rX, rY)
|
|
218
|
+
* elipse(0, 0, 50, 25);
|
|
219
|
+
* @example
|
|
220
|
+
* await crearLienzo(200, 100);
|
|
221
|
+
* fondo(0.8);
|
|
222
|
+
* modoEliptico(ESQUINA);
|
|
223
|
+
*
|
|
224
|
+
* // (lX, tY, w, h)
|
|
225
|
+
* elipse(-50, -25, 100, 50);
|
|
226
|
+
* @example
|
|
227
|
+
* await crearLienzo(200, 100);
|
|
228
|
+
* fondo(0.8);
|
|
229
|
+
* modoEliptico(ESQUINAS);
|
|
230
|
+
*
|
|
231
|
+
* // ( x1, y1, x2, y2)
|
|
232
|
+
* elipse(-50, -25, 50, 25);
|
|
92
233
|
*/
|
|
93
|
-
|
|
234
|
+
function modoEliptico(modo: string): void;
|
|
94
235
|
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
236
|
+
/** 🧑🎨
|
|
237
|
+
* Modo de alineación de forma, para usar en `modoRect` y `modoEliptico`.
|
|
97
238
|
*/
|
|
98
|
-
|
|
239
|
+
const ESQUINA: 'corner';
|
|
99
240
|
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
241
|
+
/** 🧑🎨
|
|
242
|
+
* Modo de alineación de forma, para usar en `modoRect` y `modoEliptico`.
|
|
102
243
|
*/
|
|
103
|
-
|
|
244
|
+
const RADIO: 'radius';
|
|
104
245
|
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
246
|
+
/** 🧑🎨
|
|
247
|
+
* Modo de alineación de forma, para usar en `modoRect` y `modoEliptico`.
|
|
107
248
|
*/
|
|
108
|
-
|
|
249
|
+
const ESQUINAS: 'corners';
|
|
109
250
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
251
|
+
// 🌆 image
|
|
252
|
+
|
|
253
|
+
/** 🌆
|
|
254
|
+
* Carga una imagen desde una URL.
|
|
255
|
+
*
|
|
256
|
+
* Por defecto, los recursos se cargan en paralelo antes de que q5 ejecute `dibujar`. Usa `await` para esperar a que una imagen se cargue.
|
|
257
|
+
* @param {string} url url de la imagen a cargar
|
|
258
|
+
* @returns {Q5.Image & PromiseLike<Q5.Image>} imagen
|
|
259
|
+
* @example
|
|
260
|
+
* await crearLienzo(200);
|
|
261
|
+
*
|
|
262
|
+
* let logo = cargarImagen('/q5js_logo.avif');
|
|
263
|
+
*
|
|
264
|
+
* q5.dibujar = function () {
|
|
265
|
+
* fondo(logo);
|
|
266
|
+
* };
|
|
267
|
+
* @example
|
|
268
|
+
* await crearLienzo(200);
|
|
269
|
+
*
|
|
270
|
+
* let logo = await cargarImagen('/q5js_logo.avif');
|
|
271
|
+
* fondo(logo);
|
|
113
272
|
*/
|
|
114
|
-
function
|
|
273
|
+
function cargarImagen(url: string): Q5.Imagen & PromiseLike<Q5.Imagen>;
|
|
115
274
|
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
275
|
+
/** 🌆
|
|
276
|
+
* Dibuja una imagen o fotograma de video en el lienzo.
|
|
277
|
+
* @param {Q5.Image | HTMLVideoElement} img imagen o video a dibujar
|
|
278
|
+
* @param {number} dx posición x donde dibujar la imagen
|
|
279
|
+
* @param {number} dy posición y donde dibujar la imagen
|
|
280
|
+
* @param {number} [dw] ancho de la imagen de destino
|
|
281
|
+
* @param {number} [dh] alto de la imagen de destino
|
|
282
|
+
* @param {number} [sx] posición x en la fuente para empezar a recortar una subsección
|
|
283
|
+
* @param {number} [sy] posición y en la fuente para empezar a recortar una subsección
|
|
284
|
+
* @param {number} [sw] ancho de la subsección de la imagen fuente
|
|
285
|
+
* @param {number} [sh] alto de la subsección de la imagen fuente
|
|
286
|
+
* @example
|
|
287
|
+
* await crearLienzo(200);
|
|
288
|
+
*
|
|
289
|
+
* let logo = cargarImagen('/q5js_logo.avif');
|
|
290
|
+
*
|
|
291
|
+
* q5.dibujar = function () {
|
|
292
|
+
* imagen(logo, -100, -100, 200, 200);
|
|
293
|
+
* };
|
|
294
|
+
* @example
|
|
295
|
+
* await crearLienzo(200);
|
|
296
|
+
*
|
|
297
|
+
* let logo = cargarImagen('/q5js_logo.avif');
|
|
298
|
+
*
|
|
299
|
+
* q5.dibujar = function () {
|
|
300
|
+
* imagen(logo, -100, -100, 200, 200, 256, 256, 512, 512);
|
|
301
|
+
* };
|
|
118
302
|
*/
|
|
119
|
-
function
|
|
303
|
+
function imagen(): void;
|
|
120
304
|
|
|
121
|
-
/**
|
|
122
|
-
*
|
|
305
|
+
/** 🌆
|
|
306
|
+
* Establecer a `CORNER` (por defecto), `CORNERS`, o `CENTER`.
|
|
123
307
|
*
|
|
124
|
-
*
|
|
125
|
-
* @param
|
|
126
|
-
* @
|
|
308
|
+
* Cambia cómo se interpretan las entradas a `imagen`.
|
|
309
|
+
* @param {string} modo
|
|
310
|
+
* @example
|
|
311
|
+
* await crearLienzo(200);
|
|
312
|
+
* let logo = cargarImagen('/q5js_logo.avif');
|
|
313
|
+
*
|
|
314
|
+
* q5.dibujar = function () {
|
|
315
|
+
* modoImagen(CORNER);
|
|
316
|
+
*
|
|
317
|
+
* // ( img, x, y, w, h)
|
|
318
|
+
* imagen(logo, -50, -50, 100, 100);
|
|
319
|
+
* };
|
|
320
|
+
* @example
|
|
321
|
+
* await crearLienzo(200);
|
|
322
|
+
* let logo = cargarImagen('/q5js_logo.avif');
|
|
323
|
+
*
|
|
324
|
+
* q5.dibujar = function () {
|
|
325
|
+
* modoImagen(CENTER);
|
|
326
|
+
*
|
|
327
|
+
* // ( img, cX, cY, w, h)
|
|
328
|
+
* imagen(logo, 0, 0, 100, 100);
|
|
329
|
+
* };
|
|
330
|
+
* @example
|
|
331
|
+
* await crearLienzo(200);
|
|
332
|
+
* let logo = cargarImagen('/q5js_logo.avif');
|
|
333
|
+
*
|
|
334
|
+
* q5.dibujar = function () {
|
|
335
|
+
* modoImagen(CORNERS);
|
|
336
|
+
*
|
|
337
|
+
* // ( img, x1, y1, x2, y2)
|
|
338
|
+
* imagen(logo, -50, -50, 50, 50);
|
|
339
|
+
* };
|
|
127
340
|
*/
|
|
128
|
-
function
|
|
341
|
+
function modoImagen(modo: string): void;
|
|
129
342
|
|
|
130
|
-
/**
|
|
131
|
-
*
|
|
343
|
+
/** 🌆
|
|
344
|
+
* Establece la escala de imagen por defecto, que se aplica a las imágenes cuando
|
|
345
|
+
* se dibujan sin un ancho o alto especificado.
|
|
346
|
+
*
|
|
347
|
+
* Por defecto es 0.5 para que las imágenes aparezcan en su tamaño real
|
|
348
|
+
* cuando la densidad de píxeles es 2. Las imágenes se dibujarán a un tamaño
|
|
349
|
+
* por defecto consistente relativo al lienzo independientemente de la densidad de píxeles.
|
|
350
|
+
*
|
|
351
|
+
* Esta función debe llamarse antes de que se carguen las imágenes para
|
|
352
|
+
* tener efecto.
|
|
353
|
+
* @param {number} escala
|
|
354
|
+
* @returns {number} escala de imagen por defecto
|
|
132
355
|
*/
|
|
133
|
-
function
|
|
356
|
+
function escalaImagenPorDefecto(escala: number): number;
|
|
134
357
|
|
|
135
|
-
/**
|
|
136
|
-
*
|
|
358
|
+
/** 🌆
|
|
359
|
+
* Redimensiona la imagen.
|
|
360
|
+
* @param {number} w nuevo ancho
|
|
361
|
+
* @param {number} h nuevo alto
|
|
362
|
+
* @example
|
|
363
|
+
* await crearLienzo(200);
|
|
137
364
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
365
|
+
* let logo = await cargar('/q5js_logo.avif');
|
|
366
|
+
*
|
|
367
|
+
* logo.redimensionar(128, 128);
|
|
368
|
+
* imagen(logo, -100, -100, 200, 200);
|
|
140
369
|
*/
|
|
141
|
-
function
|
|
370
|
+
function redimensionar(w: number, h: number): void;
|
|
142
371
|
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
372
|
+
/** 🌆
|
|
373
|
+
* Devuelve una imagen recortada, eliminando los píxeles transparentes de los bordes.
|
|
374
|
+
* @returns {Q5.Image}
|
|
375
|
+
*/
|
|
376
|
+
function recortar(): Q5.Imagen;
|
|
377
|
+
|
|
378
|
+
/** 🌆
|
|
379
|
+
* Habilita el renderizado suave de imágenes mostradas más grandes que
|
|
380
|
+
* su tamaño real. Esta es la configuración por defecto, así que ejecutar esta
|
|
381
|
+
* función solo tiene efecto si se ha llamado a `noSuavizar`.
|
|
382
|
+
* @example
|
|
383
|
+
* await crearLienzo(200);
|
|
384
|
+
* let icono = await cargar('/q5js_icon.png');
|
|
385
|
+
* imagen(icono, -100, -100, 200, 200);
|
|
386
|
+
*/
|
|
387
|
+
function suavizar(): void;
|
|
388
|
+
|
|
389
|
+
/** 🌆
|
|
390
|
+
* Deshabilita el renderizado suave de imágenes para un aspecto pixelado.
|
|
391
|
+
* @example
|
|
392
|
+
* await crearLienzo(200);
|
|
145
393
|
*
|
|
146
|
-
*
|
|
394
|
+
* let icono = await cargar('/q5js_icon.png');
|
|
395
|
+
*
|
|
396
|
+
* noSuavizar();
|
|
397
|
+
* imagen(icono, -100, -100, 200, 200);
|
|
147
398
|
*/
|
|
148
|
-
function
|
|
399
|
+
function noSuavizar(): void;
|
|
149
400
|
|
|
150
|
-
/**
|
|
151
|
-
*
|
|
401
|
+
/** 🌆
|
|
402
|
+
* Aplica un tinte (superposición de color) al dibujo.
|
|
152
403
|
*
|
|
153
|
-
*
|
|
404
|
+
* El valor alfa del color de tinte determina la
|
|
405
|
+
* fuerza del tinte. Para cambiar la opacidad de una imagen,
|
|
406
|
+
* usa la función `opacidad`.
|
|
407
|
+
*
|
|
408
|
+
* El teñido afecta a todas las imágenes dibujadas posteriormente. El color de tinte
|
|
409
|
+
* se aplica a las imágenes usando el modo de mezcla "multiply".
|
|
410
|
+
*
|
|
411
|
+
* Dado que el proceso de teñido es intensivo en rendimiento, cada vez
|
|
412
|
+
* que se tiñe una imagen, q5 almacena en caché el resultado. `imagen` dibujará la
|
|
413
|
+
* imagen teñida en caché a menos que el color de tinte haya cambiado o la
|
|
414
|
+
* imagen que se está tiñendo haya sido editada.
|
|
415
|
+
*
|
|
416
|
+
* Si necesitas dibujar una imagen múltiples veces cada fotograma con
|
|
417
|
+
* diferentes tintes, considera hacer copias de la imagen y teñir
|
|
418
|
+
* cada copia por separado.
|
|
419
|
+
* @param {string | number} color color de tinte
|
|
420
|
+
* @example
|
|
421
|
+
* await crearLienzo(200);
|
|
422
|
+
*
|
|
423
|
+
* let logo = await cargar('/q5js_logo.avif');
|
|
424
|
+
*
|
|
425
|
+
* teñir(1, 0, 0, 0.5);
|
|
426
|
+
* imagen(logo, -100, -100, 200, 200);
|
|
154
427
|
*/
|
|
155
|
-
function
|
|
428
|
+
function teñir(): void;
|
|
429
|
+
|
|
430
|
+
/** 🌆
|
|
431
|
+
* Las imágenes dibujadas después de ejecutar esta función no serán teñidas.
|
|
432
|
+
*/
|
|
433
|
+
function noTeñir(): void;
|
|
434
|
+
|
|
435
|
+
/** 🌆
|
|
436
|
+
* Enmascara la imagen con otra imagen.
|
|
437
|
+
* @param {Q5.Image} img imagen a usar como máscara
|
|
438
|
+
*/
|
|
439
|
+
function enmascarar(img: Q5.Imagen): void;
|
|
440
|
+
|
|
441
|
+
/** 🌆
|
|
442
|
+
* Devuelve una copia de la imagen.
|
|
443
|
+
* @returns {Q5.Image}
|
|
444
|
+
*/
|
|
445
|
+
function copiar(): Q5.Imagen;
|
|
446
|
+
|
|
447
|
+
/** 🌆
|
|
448
|
+
* Muestra una región de la imagen en otra región de la imagen.
|
|
449
|
+
* Se puede usar para crear un detalle insertado, también conocido como efecto de lupa.
|
|
450
|
+
* @param {number} sx coordenada x de la región fuente
|
|
451
|
+
* @param {number} sy coordenada y de la región fuente
|
|
452
|
+
* @param {number} sw ancho de la región fuente
|
|
453
|
+
* @param {number} sh alto de la región fuente
|
|
454
|
+
* @param {number} dx coordenada x de la región destino
|
|
455
|
+
* @param {number} dy coordenada y de la región destino
|
|
456
|
+
* @param {number} dw ancho de la región destino
|
|
457
|
+
* @param {number} dh alto de la región destino
|
|
458
|
+
* @example
|
|
459
|
+
* await crearLienzo(200);
|
|
460
|
+
*
|
|
461
|
+
* let logo = await cargar('/q5js_logo.avif');
|
|
462
|
+
*
|
|
463
|
+
* logo.insertado(256, 256, 512, 512, 0, 0, 256, 256);
|
|
464
|
+
* imagen(logo, -100, -100, 200, 200);
|
|
465
|
+
*/
|
|
466
|
+
function insertado(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
|
|
467
|
+
|
|
468
|
+
/** 🌆
|
|
469
|
+
* Recupera una subsección de una imagen o lienzo como una nueva Imagen Q5
|
|
470
|
+
* o el color de un píxel en la imagen o lienzo.
|
|
471
|
+
*
|
|
472
|
+
* Si solo se especifican x e y, esta función devuelve el color del píxel
|
|
473
|
+
* en la coordenada dada en formato de array `[R, G, B, A]`. Si `cargarPíxeles`
|
|
474
|
+
* nunca se ha ejecutado, es ejecutado por esta función.
|
|
475
|
+
*
|
|
476
|
+
* Si haces cambios en el lienzo o imagen, debes llamar a `cargarPíxeles`
|
|
477
|
+
* antes de usar esta función para obtener los datos de color actuales.
|
|
478
|
+
*
|
|
479
|
+
* No aplicable a lienzos WebGPU.
|
|
480
|
+
* @param {number} x
|
|
481
|
+
* @param {number} y
|
|
482
|
+
* @param {number} [w] ancho del área, por defecto es 1
|
|
483
|
+
* @param {number} [h] alto del área, por defecto es 1
|
|
484
|
+
* @returns {Q5.Image | number[]}
|
|
485
|
+
* @example
|
|
486
|
+
* await crearLienzo(200);
|
|
487
|
+
*
|
|
488
|
+
* let logo = await cargar('/q5js_logo.avif');
|
|
489
|
+
*
|
|
490
|
+
* let recortada = logo.obtener(256, 256, 512, 512);
|
|
491
|
+
* imagen(recortada, -100, -100, 200, 200);
|
|
492
|
+
*/
|
|
493
|
+
function obtener(x: number, y: number, w?: number, h?: number): Q5.Imagen | number[];
|
|
494
|
+
|
|
495
|
+
/** 🌆
|
|
496
|
+
* Establece el color de un píxel en la imagen o lienzo. El modo de color debe ser RGB.
|
|
497
|
+
*
|
|
498
|
+
* O si se proporciona un lienzo o imagen, se dibuja encima de la
|
|
499
|
+
* imagen o lienzo de destino, ignorando su configuración de tinte.
|
|
500
|
+
*
|
|
501
|
+
* Ejecuta `actualizarPíxeles` para aplicar los cambios.
|
|
502
|
+
*
|
|
503
|
+
* No aplicable a lienzos WebGPU.
|
|
504
|
+
* @param {number} x
|
|
505
|
+
* @param {number} y
|
|
506
|
+
* @param {any} val color, lienzo, o imagen
|
|
507
|
+
* @example
|
|
508
|
+
* await crearLienzo(200);
|
|
509
|
+
*
|
|
510
|
+
* let c = color('lime');
|
|
511
|
+
* let img = crearImagen(50, 50);
|
|
512
|
+
*
|
|
513
|
+
* q5.dibujar = function () {
|
|
514
|
+
* img.establecer(aleatorio(50), aleatorio(50), c);
|
|
515
|
+
* img.actualizarPíxeles();
|
|
516
|
+
*
|
|
517
|
+
* fondo(img);
|
|
518
|
+
* };
|
|
519
|
+
*/
|
|
520
|
+
function establecer(x: number, y: number, val: any): void;
|
|
521
|
+
|
|
522
|
+
/** 🌆
|
|
523
|
+
* Array de datos de color de píxeles de un lienzo o imagen.
|
|
524
|
+
*
|
|
525
|
+
* Vacío por defecto, poblar ejecutando `cargarPíxeles`.
|
|
526
|
+
*
|
|
527
|
+
* Cada píxel está representado por cuatro valores consecutivos en el array,
|
|
528
|
+
* correspondientes a sus canales rojo, verde, azul y alfa.
|
|
529
|
+
*
|
|
530
|
+
* Los datos del píxel superior izquierdo están al principio del array
|
|
531
|
+
* y los datos del píxel inferior derecho están al final, yendo de
|
|
532
|
+
* izquierda a derecha y de arriba a abajo.
|
|
533
|
+
*/
|
|
534
|
+
function píxeles(): void;
|
|
535
|
+
|
|
536
|
+
/** 🌆
|
|
537
|
+
* Carga datos de píxeles en `píxeles` desde el lienzo o imagen.
|
|
538
|
+
*
|
|
539
|
+
* El ejemplo a continuación establece el canal verde de algunos píxeles
|
|
540
|
+
* a un valor aleatorio.
|
|
541
|
+
*
|
|
542
|
+
* No aplicable a lienzos WebGPU.
|
|
543
|
+
* @example
|
|
544
|
+
* frecuenciaRefresco(5);
|
|
545
|
+
* let icono = cargarImagen('/q5js_icon.png');
|
|
546
|
+
*
|
|
547
|
+
* q5.dibujar = function () {
|
|
548
|
+
* icono.cargarPíxeles();
|
|
549
|
+
* for (let i = 0; i < icono.píxeles.length; i += 16) {
|
|
550
|
+
* icono.píxeles[i + 1] = aleatorio(1);
|
|
551
|
+
* }
|
|
552
|
+
* icono.actualizarPíxeles();
|
|
553
|
+
* fondo(icono);
|
|
554
|
+
* };
|
|
555
|
+
*/
|
|
556
|
+
function cargarPíxeles(): void;
|
|
557
|
+
|
|
558
|
+
/** 🌆
|
|
559
|
+
* Aplica cambios en el array `píxeles` al lienzo o imagen.
|
|
560
|
+
*
|
|
561
|
+
* No aplicable a lienzos WebGPU.
|
|
562
|
+
* @example
|
|
563
|
+
* await crearLienzo(200);
|
|
564
|
+
* let c = color('pink');
|
|
565
|
+
*
|
|
566
|
+
* let img = crearImagen(50, 50);
|
|
567
|
+
* for (let x = 0; x < 50; x += 3) {
|
|
568
|
+
* for (let y = 0; y < 50; y += 3) {
|
|
569
|
+
* img.establecer(x, y, c);
|
|
570
|
+
* }
|
|
571
|
+
* }
|
|
572
|
+
* img.actualizarPíxeles();
|
|
573
|
+
*
|
|
574
|
+
* fondo(img);
|
|
575
|
+
*/
|
|
576
|
+
function actualizarPíxeles(): void;
|
|
577
|
+
|
|
578
|
+
/** 🌆
|
|
579
|
+
* Aplica un filtro a la imagen.
|
|
580
|
+
*
|
|
581
|
+
* Mira la documentación de las constantes de filtro de q5 a continuación para más información.
|
|
582
|
+
*
|
|
583
|
+
* También se puede usar una cadena de filtro CSS.
|
|
584
|
+
* https://developer.mozilla.org/docs/Web/CSS/filter
|
|
585
|
+
*
|
|
586
|
+
* No aplicable a lienzos WebGPU.
|
|
587
|
+
* @param {string} tipo tipo de filtro o una cadena de filtro CSS
|
|
588
|
+
* @param {number} [valor] valor opcional, depende del tipo de filtro
|
|
589
|
+
* @example
|
|
590
|
+
* await crearLienzo(200);
|
|
591
|
+
* let logo = await cargar('/q5js_logo.avif');
|
|
592
|
+
* logo.filtro(INVERTIR);
|
|
593
|
+
* imagen(logo, -100, -100, 200, 200);
|
|
594
|
+
*/
|
|
595
|
+
function filtro(tipo: string, valor?: number): void;
|
|
596
|
+
|
|
597
|
+
/** 🌆
|
|
598
|
+
* Convierte la imagen a píxeles blancos y negros dependiendo si están por encima o por debajo de cierto umbral.
|
|
599
|
+
*/
|
|
600
|
+
const UMBRAL: 1;
|
|
601
|
+
|
|
602
|
+
/** 🌆
|
|
603
|
+
* Convierte la imagen a escala de grises estableciendo cada píxel a su luminancia.
|
|
604
|
+
*/
|
|
605
|
+
const GRIS: 2;
|
|
606
|
+
|
|
607
|
+
/** 🌆
|
|
608
|
+
* Establece el canal alfa a totalmente opaco.
|
|
609
|
+
*/
|
|
610
|
+
const OPACO: 3;
|
|
611
|
+
|
|
612
|
+
/** 🌆
|
|
613
|
+
* Invierte el color de cada píxel.
|
|
614
|
+
*/
|
|
615
|
+
const INVERTIR: 4;
|
|
616
|
+
|
|
617
|
+
/** 🌆
|
|
618
|
+
* Limita cada canal de la imagen al número de colores especificado como argumento.
|
|
619
|
+
*/
|
|
620
|
+
const POSTERIZAR: 5;
|
|
621
|
+
|
|
622
|
+
/** 🌆
|
|
623
|
+
* Aumenta el tamaño de las áreas brillantes.
|
|
624
|
+
*/
|
|
625
|
+
const DILATAR: 6;
|
|
626
|
+
|
|
627
|
+
/** 🌆
|
|
628
|
+
* Aumenta el tamaño de las áreas oscuras.
|
|
629
|
+
*/
|
|
630
|
+
const EROSIONAR: 7;
|
|
631
|
+
|
|
632
|
+
/** 🌆
|
|
633
|
+
* Aplica un desenfoque gaussiano a la imagen.
|
|
634
|
+
*/
|
|
635
|
+
const DESENFOCAR: 8;
|
|
636
|
+
|
|
637
|
+
/** 🌆
|
|
638
|
+
* Crea una nueva imagen.
|
|
639
|
+
* @param {number} w ancho
|
|
640
|
+
* @param {number} h alto
|
|
641
|
+
* @param {any} [opt] configuraciones opcionales para la imagen
|
|
642
|
+
* @returns {Q5.Image}
|
|
643
|
+
*/
|
|
644
|
+
function crearImagen(w: number, h: number, opt?: any): Q5.Imagen;
|
|
645
|
+
|
|
646
|
+
/** 🌆
|
|
647
|
+
* Crea un búfer de gráficos.
|
|
648
|
+
*
|
|
649
|
+
* Deshabilitado por defecto en q5 WebGPU.
|
|
650
|
+
* Mira el issue [#104](https://github.com/q5js/q5.js/issues/104) para detalles.
|
|
651
|
+
* @param {number} w ancho
|
|
652
|
+
* @param {number} h alto
|
|
653
|
+
* @param {object} [opt] opciones
|
|
654
|
+
* @returns {Q5} un nuevo búfer de gráficos Q5
|
|
655
|
+
*/
|
|
656
|
+
function crearGráficos(): void;
|
|
657
|
+
|
|
658
|
+
// 📘 text
|
|
659
|
+
|
|
660
|
+
/** 📘
|
|
661
|
+
* Renderiza texto en el lienzo.
|
|
662
|
+
*
|
|
663
|
+
* El texto se puede posicionar con los parámetros x e y
|
|
664
|
+
* y opcionalmente se puede restringir.
|
|
665
|
+
* @param {string} str cadena de texto a mostrar
|
|
666
|
+
* @param {number} x coordenada-x de la posición del texto
|
|
667
|
+
* @param {number} y coordenada-y de la posición del texto
|
|
668
|
+
* @param {number} [anchoEnvoltura] ancho máximo de línea en caracteres
|
|
669
|
+
* @param {number} [limiteLineas] número máximo de líneas
|
|
670
|
+
* @example
|
|
671
|
+
* await crearLienzo(200, 100);
|
|
672
|
+
* fondo('silver');
|
|
673
|
+
*
|
|
674
|
+
* tamañoTexto(32);
|
|
675
|
+
* texto('Hello, world!', -88, 10);
|
|
676
|
+
* @example
|
|
677
|
+
* await crearLienzo(200);
|
|
678
|
+
* fondo(0.8);
|
|
679
|
+
* tamañoTexto(20);
|
|
680
|
+
*
|
|
681
|
+
* let info =
|
|
682
|
+
* 'q5.js was designed to make creative coding fun and accessible for a new generation of artists, designers, educators, and beginners.';
|
|
683
|
+
*
|
|
684
|
+
* texto(info, -88, -70, 20, 6);
|
|
685
|
+
* //
|
|
686
|
+
* //
|
|
687
|
+
*/
|
|
688
|
+
function texto(str: string, x: number, y: number, anchoEnvoltura?: number, limiteLineas?: number): void;
|
|
689
|
+
|
|
690
|
+
/** 📘
|
|
691
|
+
* Carga una fuente desde una URL.
|
|
692
|
+
*
|
|
693
|
+
* El archivo de fuente puede estar en cualquier formato aceptado en CSS, como
|
|
694
|
+
* archivos .ttf y .otf. El primer ejemplo a continuación carga
|
|
695
|
+
* [Robotica](https://www.dafont.com/robotica-courtney.font).
|
|
696
|
+
*
|
|
697
|
+
* También soporta cargar [fuentes de Google](https://fonts.google.com/).
|
|
698
|
+
* El segundo ejemplo carga
|
|
699
|
+
* [Pacifico](https://fonts.google.com/specimen/Pacifico).
|
|
700
|
+
*
|
|
701
|
+
* Si no se cargan fuentes, se usa la fuente sans-serif por defecto.
|
|
702
|
+
*
|
|
703
|
+
* Por defecto, los recursos se cargan en paralelo antes de que q5 ejecute `dibujar`. Usa `await` para esperar a que una fuente se cargue.
|
|
704
|
+
*
|
|
705
|
+
* En q5 WebGPU, las fuentes en [formato MSDF](https://github.com/q5js/q5.js/wiki/q5-WebGPU-renderer#text-rendering)
|
|
706
|
+
* con el archivo terminando en "-msdf.json" se pueden usar para renderizado de texto de alto rendimiento. Haz la tuya usando el [convertidor de fuentes MSDF](https://msdf-bmfont.donmccurdy.com/).
|
|
707
|
+
* @param {string} url URL de la fuente a cargar
|
|
708
|
+
* @returns {FontFace & PromiseLike<FontFace>} fuente
|
|
709
|
+
* @example
|
|
710
|
+
* await crearLienzo(200, 56);
|
|
711
|
+
*
|
|
712
|
+
* await cargarFuente('/assets/Robotica.ttf');
|
|
713
|
+
*
|
|
714
|
+
* relleno('skyblue');
|
|
715
|
+
* tamañoTexto(64);
|
|
716
|
+
* imagenTexto('Hello!', -98, 24);
|
|
717
|
+
* @example
|
|
718
|
+
* await crearLienzo(200, 74);
|
|
719
|
+
*
|
|
720
|
+
* cargarFuente('fonts.googleapis.com/css2?family=Pacifico');
|
|
721
|
+
*
|
|
722
|
+
* q5.dibujar = function () {
|
|
723
|
+
* relleno('hotpink');
|
|
724
|
+
* tamañoTexto(68);
|
|
725
|
+
* imagenTexto('Hello!', -98, 31);
|
|
726
|
+
* };
|
|
727
|
+
* @example
|
|
728
|
+
* await crearLienzo(200, 74);
|
|
729
|
+
*
|
|
730
|
+
* await cargarFuente('sans-serif'); // msdf
|
|
731
|
+
*
|
|
732
|
+
* relleno('white');
|
|
733
|
+
* tamañoTexto(68);
|
|
734
|
+
* imagenTexto('Hello!', -98, 31);
|
|
735
|
+
*/
|
|
736
|
+
function cargarFuente(url: string): FontFace & PromiseLike<FontFace>;
|
|
737
|
+
|
|
738
|
+
/** 📘
|
|
739
|
+
* Establece la fuente actual a usar para renderizar texto.
|
|
740
|
+
*
|
|
741
|
+
* Por defecto, la fuente se establece a la [familia de fuentes CSS](https://developer.mozilla.org/docs/Web/CSS/font-family)
|
|
742
|
+
* "sans-serif" o la última fuente cargada.
|
|
743
|
+
* @param {string} nombreFuente nombre de la familia de fuentes o un objeto FontFace
|
|
744
|
+
* @example
|
|
745
|
+
* await crearLienzo(200, 160);
|
|
746
|
+
* fondo(0.8);
|
|
747
|
+
*
|
|
748
|
+
* fuenteTexto('serif');
|
|
749
|
+
*
|
|
750
|
+
* q5.dibujar = function () {
|
|
751
|
+
* tamañoTexto(32);
|
|
752
|
+
* texto('Hello, world!', -96, 10);
|
|
753
|
+
* };
|
|
754
|
+
* @example
|
|
755
|
+
* await crearLienzo(200);
|
|
756
|
+
* fondo(0.8);
|
|
757
|
+
*
|
|
758
|
+
* fuenteTexto('monospace');
|
|
759
|
+
*
|
|
760
|
+
* q5.dibujar = function () {
|
|
761
|
+
* texto('Hello, world!', -68, 10);
|
|
762
|
+
* };
|
|
763
|
+
*/
|
|
764
|
+
function fuenteTexto(nombreFuente: string): void;
|
|
765
|
+
|
|
766
|
+
/** 📘
|
|
767
|
+
* Establece u obtiene el tamaño de fuente actual. Si no se proporciona argumento, devuelve el tamaño de fuente actual.
|
|
768
|
+
* @param {number} [tamaño] tamaño de la fuente en píxeles
|
|
769
|
+
* @returns {number | void} tamaño de fuente actual cuando no se proporciona argumento
|
|
770
|
+
* @example
|
|
771
|
+
* q5.dibujar = function () {
|
|
772
|
+
* fondo(0.8);
|
|
773
|
+
*
|
|
774
|
+
* tamañoTexto(abs(ratónX));
|
|
775
|
+
* texto('A', -90, 90);
|
|
776
|
+
* };
|
|
777
|
+
*/
|
|
778
|
+
function tamañoTexto(): void;
|
|
779
|
+
|
|
780
|
+
/** 📘
|
|
781
|
+
* Establece u obtiene la altura de línea actual. Si no se proporciona argumento, devuelve la altura de línea actual.
|
|
782
|
+
* @param {number} [interlineado] altura de línea en píxeles
|
|
783
|
+
* @returns {number | void} altura de línea actual cuando no se proporciona argumento
|
|
784
|
+
* @example
|
|
785
|
+
* q5.dibujar = function () {
|
|
786
|
+
* fondo(0.8);
|
|
787
|
+
*
|
|
788
|
+
* tamañoTexto(abs(ratónX));
|
|
789
|
+
* texto('A', -90, 90);
|
|
790
|
+
* rect(-90, 90, 5, -interlineado());
|
|
791
|
+
* };
|
|
792
|
+
*/
|
|
793
|
+
function interlineado(interlineado?: number): number | void;
|
|
794
|
+
|
|
795
|
+
/** 📘
|
|
796
|
+
* Establece el estilo de texto actual.
|
|
797
|
+
*
|
|
798
|
+
* No aplicable a WebGPU cuando se usan fuentes MSDF.
|
|
799
|
+
* @param {'normal' | 'italic' | 'bold' | 'bolditalic'} estilo estilo de fuente
|
|
800
|
+
* @example
|
|
801
|
+
* await crearLienzo(200);
|
|
802
|
+
* fondo(0.8);
|
|
803
|
+
*
|
|
804
|
+
* estiloTexto(CURSIVA);
|
|
805
|
+
*
|
|
806
|
+
* tamañoTexto(32);
|
|
807
|
+
* texto('Hello, world!', -88, 6);
|
|
808
|
+
*/
|
|
809
|
+
function estiloTexto(estilo: 'normal' | 'italic' | 'bold' | 'bolditalic'): void;
|
|
810
|
+
|
|
811
|
+
/** 📘
|
|
812
|
+
* Establece la alineación horizontal y vertical del texto.
|
|
813
|
+
* @param {'left' | 'center' | 'right'} horiz alineación horizontal
|
|
814
|
+
* @param {'top' | 'middle' | 'bottom' | 'alphabetic'} [vert] alineación vertical
|
|
815
|
+
* @example
|
|
816
|
+
* await crearLienzo(200);
|
|
817
|
+
* fondo(0.8);
|
|
818
|
+
* tamañoTexto(32);
|
|
819
|
+
*
|
|
820
|
+
* alineaciónTexto(CENTRO, MEDIO);
|
|
821
|
+
* texto('Hello, world!', 0, 0);
|
|
822
|
+
*/
|
|
823
|
+
function alineaciónTexto(): void;
|
|
824
|
+
|
|
825
|
+
/** 📘
|
|
826
|
+
* Establece el peso del texto.
|
|
827
|
+
*
|
|
828
|
+
* - 100: delgado
|
|
829
|
+
* - 200: extra-ligero
|
|
830
|
+
* - 300: ligero
|
|
831
|
+
* - 400: normal/regular
|
|
832
|
+
* - 500: medio
|
|
833
|
+
* - 600: semi-negrita
|
|
834
|
+
* - 700: negrita
|
|
835
|
+
* - 800: más negrita/extra-negrita
|
|
836
|
+
* - 900: negro/pesado
|
|
837
|
+
* @param {number | string} peso peso de la fuente
|
|
838
|
+
* @example
|
|
839
|
+
* await crearLienzo(200);
|
|
840
|
+
* fondo(0.8);
|
|
841
|
+
* tamañoTexto(32);
|
|
842
|
+
* alineaciónTexto(CENTRO, MEDIO);
|
|
843
|
+
*
|
|
844
|
+
* pesoTexto(100);
|
|
845
|
+
* texto('Hello, world!', 0, 0);
|
|
846
|
+
*/
|
|
847
|
+
function pesoTexto(peso: number | string): void;
|
|
848
|
+
|
|
849
|
+
/** 📘
|
|
850
|
+
* Calcula y devuelve el ancho de una cadena de texto dada.
|
|
851
|
+
* @param {string} str cadena a medir
|
|
852
|
+
* @returns {number} ancho del texto en píxeles
|
|
853
|
+
* @example
|
|
854
|
+
* q5.dibujar = function () {
|
|
855
|
+
* fondo(0.8);
|
|
856
|
+
*
|
|
857
|
+
* tamañoTexto(abs(ratónX));
|
|
858
|
+
* rect(-90, 90, anchoTexto('A'), -interlineado());
|
|
859
|
+
* texto('A', -90, 90);
|
|
860
|
+
* };
|
|
861
|
+
*/
|
|
862
|
+
function anchoTexto(str: string): number;
|
|
863
|
+
|
|
864
|
+
/** 📘
|
|
865
|
+
* Calcula y devuelve el ascenso (la distancia desde la línea base hasta la parte superior del carácter más alto) de la fuente actual.
|
|
866
|
+
* @param {string} str cadena a medir
|
|
867
|
+
* @returns {number} ascenso del texto en píxeles
|
|
868
|
+
* @example
|
|
869
|
+
* q5.dibujar = function () {
|
|
870
|
+
* fondo(0.8);
|
|
871
|
+
*
|
|
872
|
+
* tamañoTexto(abs(ratónX));
|
|
873
|
+
* rect(-90, 90, anchoTexto('A'), -ascensoTexto());
|
|
874
|
+
* texto('A', -90, 90);
|
|
875
|
+
* };
|
|
876
|
+
*/
|
|
877
|
+
function ascensoTexto(str: string): number;
|
|
878
|
+
|
|
879
|
+
/** 📘
|
|
880
|
+
* Calcula y devuelve el descenso (la distancia desde la línea base hasta la parte inferior del carácter más bajo) de la fuente actual.
|
|
881
|
+
* @param {string} str cadena a medir
|
|
882
|
+
* @returns {number} descenso del texto en píxeles
|
|
883
|
+
* @example
|
|
884
|
+
* await crearLienzo(200);
|
|
885
|
+
* fondo(0.8);
|
|
886
|
+
* tamañoTexto(64);
|
|
887
|
+
*
|
|
888
|
+
* rect(-100, 0, 200, descensoTexto('q5'));
|
|
889
|
+
* texto('q5', -90, 0);
|
|
890
|
+
*/
|
|
891
|
+
function descensoTexto(str: string): number;
|
|
892
|
+
|
|
893
|
+
/** 📘
|
|
894
|
+
* Crea una imagen a partir de una cadena de texto.
|
|
895
|
+
* @param {string} str cadena de texto
|
|
896
|
+
* @param {number} [anchoEnvoltura] ancho máximo de línea en caracteres
|
|
897
|
+
* @param {number} [limiteLineas] número máximo de líneas
|
|
898
|
+
* @returns {Q5.Image} un objeto de imagen representando el texto renderizado
|
|
899
|
+
* @example
|
|
900
|
+
* await crearLienzo(200);
|
|
901
|
+
* tamañoTexto(96);
|
|
902
|
+
*
|
|
903
|
+
* let img = crearImagenTexto('🐶');
|
|
904
|
+
* img.filtro(INVERTIR);
|
|
905
|
+
*
|
|
906
|
+
* q5.dibujar = function () {
|
|
907
|
+
* imagen(img, -45, -90);
|
|
908
|
+
* };
|
|
909
|
+
*/
|
|
910
|
+
function crearImagenTexto(str: string, anchoEnvoltura: number, limiteLineas: number): Q5.Imagen;
|
|
911
|
+
|
|
912
|
+
/** 📘
|
|
913
|
+
* Renderiza una imagen generada a partir de texto en el lienzo.
|
|
914
|
+
*
|
|
915
|
+
* Si el primer parámetro es una cadena, se creará y almacenará en caché automáticamente
|
|
916
|
+
* una imagen del texto.
|
|
917
|
+
*
|
|
918
|
+
* El posicionamiento de la imagen se ve afectado por la configuración actual de
|
|
919
|
+
* alineación de texto y línea base.
|
|
920
|
+
*
|
|
921
|
+
* En q5 WebGPU, esta función es la única forma de dibujar texto multicolor,
|
|
922
|
+
* como emojis, y de usar fuentes que no están en formato MSDF.
|
|
923
|
+
* Usar esta función para dibujar texto que cambia cada fotograma tiene
|
|
924
|
+
* un costo de rendimiento muy alto.
|
|
925
|
+
* @param {Q5.Image | string} img imagen o texto
|
|
926
|
+
* @param {number} x coordenada-x donde se debe colocar la imagen
|
|
927
|
+
* @param {number} y coordenada-y donde se debe colocar la imagen
|
|
928
|
+
* @example
|
|
929
|
+
* await crearLienzo(200);
|
|
930
|
+
* fondo(0.8);
|
|
931
|
+
* tamañoTexto(96);
|
|
932
|
+
* alineaciónTexto(CENTRO, CENTRO);
|
|
933
|
+
*
|
|
934
|
+
* imagenTexto('🐶', 0, 0);
|
|
935
|
+
* @example
|
|
936
|
+
* await crearLienzo(200);
|
|
937
|
+
*
|
|
938
|
+
* await cargar('/assets/Robotica.ttf');
|
|
939
|
+
*
|
|
940
|
+
* fondo(0.8);
|
|
941
|
+
* tamañoTexto(66);
|
|
942
|
+
* imagenTexto('Hello!', -100, 100);
|
|
943
|
+
*/
|
|
944
|
+
function imagenTexto(img: Q5.Imagen | String, x: number, y: number): void;
|
|
945
|
+
|
|
946
|
+
/** 📘
|
|
947
|
+
* Formateador de números, se puede usar para mostrar un número como una cadena con
|
|
948
|
+
* un número especificado de dígitos antes y después del punto decimal,
|
|
949
|
+
* opcionalmente añadiendo relleno con ceros.
|
|
950
|
+
* @param {number} n número a formatear
|
|
951
|
+
* @param {number} l número mínimo de dígitos que aparecen antes del punto decimal; el número se rellena con ceros si es necesario
|
|
952
|
+
* @param {number} r número de dígitos que aparecen después del punto decimal
|
|
953
|
+
* @returns {string} una representación de cadena del número, formateada en consecuencia
|
|
954
|
+
* @example
|
|
955
|
+
* await crearLienzo(200, 100);
|
|
956
|
+
* fondo(0.8);
|
|
957
|
+
*
|
|
958
|
+
* tamañoTexto(32);
|
|
959
|
+
* texto(nf(PI, 4, 5), -90, 10);
|
|
960
|
+
*/
|
|
961
|
+
function nf(num: number, digitos: number): string;
|
|
962
|
+
|
|
963
|
+
/** 📘
|
|
964
|
+
* Estilo de fuente normal.
|
|
965
|
+
*/
|
|
966
|
+
const NORMAL: 'normal';
|
|
967
|
+
|
|
968
|
+
/** 📘
|
|
969
|
+
* Estilo de fuente cursiva.
|
|
970
|
+
*/
|
|
971
|
+
const CURSIVA: 'italic';
|
|
972
|
+
|
|
973
|
+
/** 📘
|
|
974
|
+
* Peso de fuente negrita.
|
|
975
|
+
*/
|
|
976
|
+
const NEGRILLA: 'bold';
|
|
977
|
+
|
|
978
|
+
/** 📘
|
|
979
|
+
* Estilo de fuente negrita y cursiva.
|
|
980
|
+
*/
|
|
981
|
+
const NEGRILLA_CURSIVA: 'italic bold';
|
|
982
|
+
|
|
983
|
+
/** 📘
|
|
984
|
+
* Alinear texto a la izquierda.
|
|
985
|
+
*/
|
|
986
|
+
const IZQUIERDA: 'left';
|
|
987
|
+
|
|
988
|
+
/** 📘
|
|
989
|
+
* Alinear texto al centro.
|
|
990
|
+
*/
|
|
991
|
+
const CENTRO: 'center';
|
|
992
|
+
|
|
993
|
+
/** 📘
|
|
994
|
+
* Alinear texto a la derecha.
|
|
995
|
+
*/
|
|
996
|
+
const DERECHA: 'right';
|
|
997
|
+
|
|
998
|
+
/** 📘
|
|
999
|
+
* Alinear texto arriba.
|
|
1000
|
+
*/
|
|
1001
|
+
const ARRIBA: 'top';
|
|
1002
|
+
|
|
1003
|
+
/** 📘
|
|
1004
|
+
* Alinear texto abajo.
|
|
1005
|
+
*/
|
|
1006
|
+
const ABAJO: 'bottom';
|
|
1007
|
+
|
|
1008
|
+
/** 📘
|
|
1009
|
+
* Alinear texto a la línea base (alfabética).
|
|
1010
|
+
*/
|
|
1011
|
+
const LINEA_BASE: 'alphabetic';
|
|
1012
|
+
|
|
1013
|
+
// 🖲 input
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* El manejo de entrada de q5 es muy básico.
|
|
1017
|
+
*
|
|
1018
|
+
* Para un mejor manejo de entrada, incluyendo soporte para controladores de juegos, considera usar el addon [p5play](https://p5play.org/) con q5.
|
|
1019
|
+
*
|
|
1020
|
+
* Ten en cuenta que las respuestas de entrada dentro de `dibujar` pueden retrasarse
|
|
1021
|
+
* hasta un ciclo de fotograma: desde el momento exacto en que ocurre un evento de entrada
|
|
1022
|
+
* hasta la próxima vez que se dibuja un fotograma.
|
|
1023
|
+
*
|
|
1024
|
+
* Reproduce sonidos o activa otra retroalimentación no visual inmediatamente
|
|
1025
|
+
* respondiendo a eventos de entrada dentro de funciones como
|
|
1026
|
+
* `alPresionarRatón` y `alPresionarTecla`.
|
|
1027
|
+
*/
|
|
1028
|
+
|
|
1029
|
+
/** 🖲
|
|
1030
|
+
* Posición X actual del ratón.
|
|
1031
|
+
* @example
|
|
1032
|
+
* q5.dibujar = function () {
|
|
1033
|
+
* fondo(0.8);
|
|
1034
|
+
* tamañoTexto(64);
|
|
1035
|
+
* texto(redondear(ratónX), -50, 20);
|
|
1036
|
+
* };
|
|
1037
|
+
*/
|
|
1038
|
+
function ratónX(): void;
|
|
1039
|
+
|
|
1040
|
+
/** 🖲
|
|
1041
|
+
* Posición Y actual del ratón.
|
|
1042
|
+
* @example
|
|
1043
|
+
* q5.dibujar = function () {
|
|
1044
|
+
* fondo(0.8);
|
|
1045
|
+
* círculo(0, ratónY, 100);
|
|
1046
|
+
* };
|
|
1047
|
+
*/
|
|
1048
|
+
function ratónY(): void;
|
|
1049
|
+
|
|
1050
|
+
/** 🖲
|
|
1051
|
+
* Posición X previa del ratón.
|
|
1052
|
+
*/
|
|
1053
|
+
function pRatónX(): void;
|
|
1054
|
+
|
|
1055
|
+
/** 🖲
|
|
1056
|
+
* Posición Y previa del ratón.
|
|
1057
|
+
*/
|
|
1058
|
+
function pRatónY(): void;
|
|
1059
|
+
|
|
1060
|
+
/** 🖲
|
|
1061
|
+
* El botón actual siendo presionado: 'left', 'right', 'center').
|
|
1062
|
+
*
|
|
1063
|
+
* El valor por defecto es una cadena vacía.
|
|
1064
|
+
* @example
|
|
1065
|
+
* q5.dibujar = function () {
|
|
1066
|
+
* fondo(0.8);
|
|
1067
|
+
* tamañoTexto(64);
|
|
1068
|
+
* texto(botónRatón, -80, 20);
|
|
1069
|
+
* };
|
|
1070
|
+
*/
|
|
1071
|
+
function botónRatón(): void;
|
|
1072
|
+
|
|
1073
|
+
/** 🖲
|
|
1074
|
+
* Verdadero si el ratón está actualmente presionado, falso de lo contrario.
|
|
1075
|
+
* @example
|
|
1076
|
+
* q5.dibujar = function () {
|
|
1077
|
+
* if (ratónPresionado) fondo(0.4);
|
|
1078
|
+
* else fondo(0.8);
|
|
1079
|
+
* };
|
|
1080
|
+
*/
|
|
1081
|
+
function ratónPresionado(): void;
|
|
1082
|
+
|
|
1083
|
+
/** 🖲
|
|
1084
|
+
* Define esta función para responder a eventos de presionar el ratón.
|
|
1085
|
+
* @example
|
|
1086
|
+
* await crearLienzo(200);
|
|
1087
|
+
* let gris = 0.4;
|
|
1088
|
+
*
|
|
1089
|
+
* q5.alPresionarRatón = function () {
|
|
1090
|
+
* fondo(gris);
|
|
1091
|
+
* gris = (gris + 0.1) % 1;
|
|
1092
|
+
* };
|
|
1093
|
+
*/
|
|
1094
|
+
function alPresionarRatón(): void;
|
|
1095
|
+
|
|
1096
|
+
/** 🖲
|
|
1097
|
+
* Define esta función para responder a eventos de soltar el ratón.
|
|
1098
|
+
* @example
|
|
1099
|
+
* await crearLienzo(200);
|
|
1100
|
+
* let gris = 0.4;
|
|
1101
|
+
*
|
|
1102
|
+
* q5.alSoltarRatón = function () {
|
|
1103
|
+
* fondo(gris);
|
|
1104
|
+
* gris = (gris + 0.1) % 1;
|
|
1105
|
+
* };
|
|
1106
|
+
*/
|
|
1107
|
+
function alSoltarRatón(): void;
|
|
1108
|
+
|
|
1109
|
+
/** 🖲
|
|
1110
|
+
* Define esta función para responder a eventos de mover el ratón.
|
|
1111
|
+
*
|
|
1112
|
+
* En dispositivos con pantalla táctil esta función no se llama
|
|
1113
|
+
* cuando el usuario arrastra su dedo en la pantalla.
|
|
1114
|
+
* @example
|
|
1115
|
+
* await crearLienzo(200);
|
|
1116
|
+
* let gris = 0.4;
|
|
1117
|
+
*
|
|
1118
|
+
* q5.alMoverRatón = function () {
|
|
1119
|
+
* fondo(gris);
|
|
1120
|
+
* gris = (gris + 0.005) % 1;
|
|
1121
|
+
* };
|
|
1122
|
+
*/
|
|
1123
|
+
function alMoverRatón(): void;
|
|
1124
|
+
|
|
1125
|
+
/** 🖲
|
|
1126
|
+
* Define esta función para responder a eventos de arrastrar el ratón.
|
|
1127
|
+
*
|
|
1128
|
+
* Arrastrar el ratón se define como mover el ratón
|
|
1129
|
+
* mientras un botón del ratón está presionado.
|
|
1130
|
+
* @example
|
|
1131
|
+
* await crearLienzo(200);
|
|
1132
|
+
* let gris = 0.4;
|
|
1133
|
+
*
|
|
1134
|
+
* q5.alArrastrarRatón = function () {
|
|
1135
|
+
* fondo(gris);
|
|
1136
|
+
* gris = (gris + 0.005) % 1;
|
|
1137
|
+
* };
|
|
1138
|
+
*/
|
|
1139
|
+
function alArrastrarRatón(): void;
|
|
1140
|
+
|
|
1141
|
+
/** 🖲
|
|
1142
|
+
* Define esta función para responder a eventos de doble clic del ratón.
|
|
1143
|
+
* @example
|
|
1144
|
+
* await crearLienzo(200);
|
|
1145
|
+
* let gris = 0.4;
|
|
1146
|
+
*
|
|
1147
|
+
* q5.dobleClic = function () {
|
|
1148
|
+
* fondo(gris);
|
|
1149
|
+
* gris = (gris + 0.1) % 1;
|
|
1150
|
+
* };
|
|
1151
|
+
*/
|
|
1152
|
+
function dobleClic(): void;
|
|
1153
|
+
|
|
1154
|
+
/** 🖲
|
|
1155
|
+
* El nombre de la última tecla presionada.
|
|
1156
|
+
* @example
|
|
1157
|
+
* q5.dibujar = function () {
|
|
1158
|
+
* fondo(0.8);
|
|
1159
|
+
* tamañoTexto(64);
|
|
1160
|
+
* texto(tecla, -80, 20);
|
|
1161
|
+
* };
|
|
1162
|
+
*/
|
|
1163
|
+
let tecla: string;
|
|
1164
|
+
|
|
1165
|
+
/** 🖲
|
|
1166
|
+
* Verdadero si una tecla está actualmente presionada, falso de lo contrario.
|
|
1167
|
+
* @example
|
|
1168
|
+
* q5.dibujar = function () {
|
|
1169
|
+
* if (teclaPresionada) fondo(0.4);
|
|
1170
|
+
* else fondo(0.8);
|
|
1171
|
+
* };
|
|
1172
|
+
*/
|
|
1173
|
+
let teclaPresionada: boolean;
|
|
1174
|
+
|
|
1175
|
+
/** 🖲
|
|
1176
|
+
* Devuelve verdadero si el usuario está presionando la tecla especificada, falso
|
|
1177
|
+
* de lo contrario. Acepta nombres de teclas insensibles a mayúsculas.
|
|
1178
|
+
* @param {string} tecla tecla a comprobar
|
|
1179
|
+
* @returns {boolean} verdadero si la tecla está presionada, falso de lo contrario
|
|
1180
|
+
* @example
|
|
1181
|
+
* q5.dibujar = function () {
|
|
1182
|
+
* fondo(0.8);
|
|
1183
|
+
*
|
|
1184
|
+
* if (teclaEstaPresionada('f') && teclaEstaPresionada('j')) {
|
|
1185
|
+
* rect(-50, -50, 100, 100);
|
|
1186
|
+
* }
|
|
1187
|
+
* };
|
|
1188
|
+
*/
|
|
1189
|
+
function teclaEstaPresionada(tecla: string): boolean;
|
|
1190
|
+
|
|
1191
|
+
/** 🖲
|
|
1192
|
+
* Define esta función para responder a eventos de presionar tecla.
|
|
1193
|
+
* @example
|
|
1194
|
+
* await crearLienzo(200);
|
|
1195
|
+
* let gris = 0.4;
|
|
1196
|
+
*
|
|
1197
|
+
* q5.alPresionarTecla = function () {
|
|
1198
|
+
* fondo(gris);
|
|
1199
|
+
* gris = (gris + 0.1) % 1;
|
|
1200
|
+
* };
|
|
1201
|
+
*/
|
|
1202
|
+
function alPresionarTecla(): void;
|
|
1203
|
+
|
|
1204
|
+
/** 🖲
|
|
1205
|
+
* Define esta función para responder a eventos de soltar tecla.
|
|
1206
|
+
* @example
|
|
1207
|
+
* await crearLienzo(200);
|
|
1208
|
+
* let gris = 0.4;
|
|
1209
|
+
*
|
|
1210
|
+
* q5.alSoltarTecla = function () {
|
|
1211
|
+
* fondo(gris);
|
|
1212
|
+
* gris = (gris + 0.1) % 1;
|
|
1213
|
+
* };
|
|
1214
|
+
*/
|
|
1215
|
+
function alSoltarTecla(): void;
|
|
1216
|
+
|
|
1217
|
+
/** 🖲
|
|
1218
|
+
* Array que contiene todos los puntos de toque actuales dentro de la
|
|
1219
|
+
* ventana del navegador. Cada toque es un objeto con
|
|
1220
|
+
* propiedades `id`, `x`, e `y`.
|
|
1221
|
+
* @example
|
|
1222
|
+
* q5.dibujar = function () {
|
|
1223
|
+
* fondo(0.8);
|
|
1224
|
+
* for (let toque of toques) {
|
|
1225
|
+
* círculo(toque.x, toque.y, 100);
|
|
1226
|
+
* }
|
|
1227
|
+
* };
|
|
1228
|
+
*/
|
|
1229
|
+
let toques: any[];
|
|
1230
|
+
|
|
1231
|
+
/** 🖲
|
|
1232
|
+
* Define esta función para responder a eventos de inicio de toque
|
|
1233
|
+
* en el lienzo.
|
|
1234
|
+
*
|
|
1235
|
+
* Devuelve true para habilitar gestos táctiles como pellizcar para hacer zoom
|
|
1236
|
+
* y desplazarse, que q5 deshabilita en el lienzo por defecto.
|
|
1237
|
+
* @example
|
|
1238
|
+
* await crearLienzo(200);
|
|
1239
|
+
* let gris = 0.4;
|
|
1240
|
+
*
|
|
1241
|
+
* q5.alEmpezarToque = function () {
|
|
1242
|
+
* fondo(gris);
|
|
1243
|
+
* gris = (gris + 0.1) % 1;
|
|
1244
|
+
* };
|
|
1245
|
+
*/
|
|
1246
|
+
function alEmpezarToque(): void;
|
|
1247
|
+
|
|
1248
|
+
/** 🖲
|
|
1249
|
+
* Define esta función para responder a eventos de fin de toque
|
|
1250
|
+
* en el lienzo.
|
|
1251
|
+
*
|
|
1252
|
+
* Devuelve true para habilitar gestos táctiles como pellizcar para hacer zoom
|
|
1253
|
+
* y desplazarse, que q5 deshabilita en el lienzo por defecto.
|
|
1254
|
+
* @example
|
|
1255
|
+
* await crearLienzo(200);
|
|
1256
|
+
* let gris = 0.4;
|
|
1257
|
+
*
|
|
1258
|
+
* q5.alTerminarToque = function () {
|
|
1259
|
+
* fondo(gris);
|
|
1260
|
+
* gris = (gris + 0.1) % 1;
|
|
1261
|
+
* };
|
|
1262
|
+
*/
|
|
1263
|
+
function alTerminarToque(): void;
|
|
1264
|
+
|
|
1265
|
+
/** 🖲
|
|
1266
|
+
* Define esta función para responder a eventos de movimiento de toque
|
|
1267
|
+
* en el lienzo.
|
|
1268
|
+
*
|
|
1269
|
+
* Devuelve true para habilitar gestos táctiles como pellizcar para hacer zoom
|
|
1270
|
+
* y desplazarse, que q5 deshabilita en el lienzo por defecto.
|
|
1271
|
+
* @example
|
|
1272
|
+
* await crearLienzo(200);
|
|
1273
|
+
* let gris = 0.4;
|
|
1274
|
+
*
|
|
1275
|
+
* q5.alMoverToque = function () {
|
|
1276
|
+
* fondo(gris);
|
|
1277
|
+
* gris = (gris + 0.005) % 1;
|
|
1278
|
+
* };
|
|
1279
|
+
*/
|
|
1280
|
+
function alMoverToque(): void;
|
|
1281
|
+
|
|
1282
|
+
/** 🖲
|
|
1283
|
+
* Objeto que contiene todos los punteros actuales dentro de la
|
|
1284
|
+
* ventana del navegador.
|
|
1285
|
+
*
|
|
1286
|
+
* Esto incluye ratón, toque y punteros de lápiz.
|
|
1287
|
+
*
|
|
1288
|
+
* Cada puntero es un objeto con
|
|
1289
|
+
* propiedades `event`, `x`, e `y`.
|
|
1290
|
+
* La propiedad `event` contiene el
|
|
1291
|
+
* [PointerEvent](https://developer.mozilla.org/docs/Web/API/PointerEvent) original.
|
|
1292
|
+
* @example
|
|
1293
|
+
* q5.dibujar = function () {
|
|
1294
|
+
* fondo(0.8);
|
|
1295
|
+
* for (let punteroID in punteros) {
|
|
1296
|
+
* let puntero = punteros[punteroID];
|
|
1297
|
+
* círculo(puntero.x, puntero.y, 100);
|
|
1298
|
+
* }
|
|
1299
|
+
* };
|
|
1300
|
+
*/
|
|
1301
|
+
let punteros: {};
|
|
1302
|
+
|
|
1303
|
+
/** 🖲
|
|
1304
|
+
* Establece el cursor a un [tipo de cursor CSS](https://developer.mozilla.org/docs/Web/CSS/cursor) o imagen.
|
|
1305
|
+
* Si se proporciona una imagen, las coordenadas x e y opcionales pueden
|
|
1306
|
+
* especificar el punto activo del cursor.
|
|
1307
|
+
* @param {string} nombre nombre del cursor o la url a una imagen
|
|
1308
|
+
* @param {number} [x] coordenada x del punto del cursor
|
|
1309
|
+
* @param {number} [y] coordenada y del punto del cursor
|
|
1310
|
+
* @example
|
|
1311
|
+
* await crearLienzo(200, 100);
|
|
1312
|
+
* cursor('pointer');
|
|
1313
|
+
*/
|
|
1314
|
+
function cursor(nombre: string, x?: number, y?: number): void;
|
|
1315
|
+
|
|
1316
|
+
/** 🖲
|
|
1317
|
+
* Oculta el cursor dentro de los límites del lienzo.
|
|
1318
|
+
* @example
|
|
1319
|
+
* await crearLienzo(200, 100);
|
|
1320
|
+
* sinCursor();
|
|
1321
|
+
*/
|
|
1322
|
+
function sinCursor(): void;
|
|
1323
|
+
|
|
1324
|
+
/** 🖲
|
|
1325
|
+
* Define esta función para responder a eventos de la rueda del ratón.
|
|
1326
|
+
*
|
|
1327
|
+
* `event.deltaX` y `event.deltaY` son las cantidades de desplazamiento horizontal y vertical,
|
|
1328
|
+
* respectivamente.
|
|
1329
|
+
*
|
|
1330
|
+
* Devuelve true para permitir el comportamiento por defecto de desplazar la página.
|
|
1331
|
+
* @example
|
|
1332
|
+
* let x = (y = 0);
|
|
1333
|
+
* q5.dibujar = function () {
|
|
1334
|
+
* círculo(x, y, 10);
|
|
1335
|
+
* };
|
|
1336
|
+
* q5.ruedaRatón = function (e) {
|
|
1337
|
+
* x += e.deltaX;
|
|
1338
|
+
* y += e.deltaY;
|
|
1339
|
+
* return false;
|
|
1340
|
+
* };
|
|
1341
|
+
*/
|
|
1342
|
+
function ruedaRatón(): void;
|
|
1343
|
+
|
|
1344
|
+
/** 🖲
|
|
1345
|
+
* Solicita que el puntero se bloquee al cuerpo del documento, ocultando
|
|
1346
|
+
* el cursor y permitiendo un movimiento ilimitado.
|
|
1347
|
+
*
|
|
1348
|
+
* Los sistemas operativos habilitan la aceleración del ratón por defecto, lo cual es útil cuando a veces quieres un movimiento lento y preciso (piensa en cómo usarías un paquete de gráficos), pero también quieres moverte grandes distancias con un movimiento de ratón más rápido (piensa en desplazarte y seleccionar varios archivos). Para algunos juegos, sin embargo, se prefieren los datos de entrada de ratón sin procesar para controlar la rotación de la cámara — donde el mismo movimiento de distancia, rápido o lento, resulta en la misma rotación.
|
|
1349
|
+
*
|
|
1350
|
+
* Para salir del modo de bloqueo de puntero, llama a `document.exitPointerLock()`.
|
|
1351
|
+
* @param {boolean} movimientoNoAjustado establecer a true para deshabilitar la aceleración del ratón a nivel de SO y acceder a la entrada de ratón sin procesar
|
|
1352
|
+
* @example
|
|
1353
|
+
* q5.dibujar = function () {
|
|
1354
|
+
* círculo(ratónX / 10, ratónY / 10, 10);
|
|
1355
|
+
* };
|
|
1356
|
+
*
|
|
1357
|
+
* q5.dobleClic = function () {
|
|
1358
|
+
* if (!document.pointerLockElement) {
|
|
1359
|
+
* bloqueoPuntero();
|
|
1360
|
+
* } else {
|
|
1361
|
+
* document.exitPointerLock();
|
|
1362
|
+
* }
|
|
1363
|
+
* };
|
|
1364
|
+
*/
|
|
1365
|
+
function bloqueoPuntero(movimientoNoAjustado: boolean): void;
|
|
1366
|
+
|
|
1367
|
+
// 🎨 color
|
|
1368
|
+
|
|
1369
|
+
/** 🎨
|
|
1370
|
+
* Dibuja sobre todo el lienzo con un color o una imagen.
|
|
1371
|
+
*
|
|
1372
|
+
* Al igual que la función [`color`](https://q5js.org/learn/#color),
|
|
1373
|
+
* esta función puede aceptar colores en una amplia gama de formatos:
|
|
1374
|
+
* cadena de color CSS, valor de escala de grises y valores de componentes de color.
|
|
1375
|
+
* @param {Color | Q5.Image} relleno un color o una imagen para dibujar
|
|
1376
|
+
* @example
|
|
1377
|
+
* await crearLienzo(200, 100);
|
|
1378
|
+
* fondo('crimson');
|
|
1379
|
+
* @example
|
|
1380
|
+
* q5.dibujar = function () {
|
|
1381
|
+
* fondo(0.5, 0.2);
|
|
1382
|
+
* círculo(mouseX, mouseY, 20);
|
|
1383
|
+
* };
|
|
1384
|
+
*/
|
|
1385
|
+
function fondo(relleno: Color | Q5.Imagen): void;
|
|
1386
|
+
|
|
1387
|
+
function color(c0: string | number | Color | number[], c1?: number, c2?: number, c3?: number): Color;
|
|
1388
|
+
|
|
1389
|
+
function modoColor(modo: 'rgb' | 'oklch', formato: 1 | 255, gama: 'srgb' | 'display-p3'): void;
|
|
1390
|
+
|
|
1391
|
+
const RGB: 'rgb';
|
|
1392
|
+
|
|
1393
|
+
const OKLCH: 'oklch';
|
|
1394
|
+
|
|
1395
|
+
const HSL: 'hsl';
|
|
1396
|
+
|
|
1397
|
+
const HSB: 'hsb';
|
|
1398
|
+
|
|
1399
|
+
const SRGB: 'srgb';
|
|
1400
|
+
|
|
1401
|
+
const DISPLAY_P3: 'display-p3';
|
|
1402
|
+
|
|
1403
|
+
class Color {
|
|
1404
|
+
constructor(c0: number, c1: number, c2: number, c3: number);
|
|
1405
|
+
|
|
1406
|
+
igual(otro: Color): boolean;
|
|
1407
|
+
|
|
1408
|
+
esMismoColor(otro: Color): boolean;
|
|
1409
|
+
|
|
1410
|
+
toString(): string;
|
|
1411
|
+
|
|
1412
|
+
niveles: number[];
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// 💅 styles
|
|
1416
|
+
|
|
1417
|
+
/** 💅
|
|
1418
|
+
* Establece el color de relleno. El defecto es blanco.
|
|
1419
|
+
*
|
|
1420
|
+
* Como la función [`color`](https://q5js.org/learn/#color), esta función
|
|
1421
|
+
* puede aceptar colores en una amplia gama de formatos: como una cadena de color CSS,
|
|
1422
|
+
* un objeto `Color`, valor de escala de grises, o valores de componentes de color.
|
|
1423
|
+
* @param {Color} color color de relleno
|
|
1424
|
+
* @example
|
|
1425
|
+
* await crearLienzo(200);
|
|
1426
|
+
* fondo(0.8);
|
|
1427
|
+
*
|
|
1428
|
+
* relleno('red');
|
|
1429
|
+
* círculo(-20, -20, 80);
|
|
1430
|
+
*
|
|
1431
|
+
* relleno('lime');
|
|
1432
|
+
* cuadrado(-20, -20, 80);
|
|
1433
|
+
*/
|
|
1434
|
+
function relleno(color: Color): void;
|
|
1435
|
+
|
|
1436
|
+
/** 💅
|
|
1437
|
+
* Establece el color del trazo (contorno). El defecto es negro.
|
|
1438
|
+
*
|
|
1439
|
+
* Como la función [`color`](https://q5js.org/learn/#color), esta función
|
|
1440
|
+
* puede aceptar colores en una amplia gama de formatos: como una cadena de color CSS,
|
|
1441
|
+
* un objeto `Color`, valor de escala de grises, o valores de componentes de color.
|
|
1442
|
+
* @param {Color} color color de trazo
|
|
1443
|
+
* @example
|
|
1444
|
+
* await crearLienzo(200);
|
|
1445
|
+
* fondo(0.8);
|
|
1446
|
+
* relleno(0.14);
|
|
1447
|
+
*
|
|
1448
|
+
* trazo('red');
|
|
1449
|
+
* círculo(-20, -20, 80);
|
|
1450
|
+
*
|
|
1451
|
+
* trazo('lime');
|
|
1452
|
+
* cuadrado(-20, -20, 80);
|
|
1453
|
+
*/
|
|
1454
|
+
function trazo(color: Color): void;
|
|
1455
|
+
|
|
1456
|
+
/** 💅
|
|
1457
|
+
* Después de llamar a esta función, el dibujo no será rellenado.
|
|
1458
|
+
* @example
|
|
1459
|
+
* await crearLienzo(200);
|
|
1460
|
+
* fondo(0.8);
|
|
1461
|
+
*
|
|
1462
|
+
* sinRelleno();
|
|
1463
|
+
*
|
|
1464
|
+
* trazo('red');
|
|
1465
|
+
* círculo(-20, -20, 80);
|
|
1466
|
+
* trazo('lime');
|
|
1467
|
+
* cuadrado(-20, -20, 80);
|
|
1468
|
+
*/
|
|
1469
|
+
function sinRelleno(): void;
|
|
1470
|
+
|
|
1471
|
+
/** 💅
|
|
1472
|
+
* Después de llamar a esta función, el dibujo no tendrá un trazo (contorno).
|
|
1473
|
+
* @example
|
|
1474
|
+
* await crearLienzo(200);
|
|
1475
|
+
* fondo(0.8);
|
|
1476
|
+
* relleno(0.14);
|
|
1477
|
+
* trazo('red');
|
|
1478
|
+
* círculo(-20, -20, 80);
|
|
1479
|
+
*
|
|
1480
|
+
* sinTrazo();
|
|
1481
|
+
* cuadrado(-20, -20, 80);
|
|
1482
|
+
*/
|
|
1483
|
+
function sinTrazo(): void;
|
|
1484
|
+
|
|
1485
|
+
/** 💅
|
|
1486
|
+
* Establece el tamaño del trazo usado para líneas y el borde alrededor de dibujos.
|
|
1487
|
+
* @param {number} grosor tamaño del trazo en píxeles
|
|
1488
|
+
* @example
|
|
1489
|
+
* await crearLienzo(200);
|
|
1490
|
+
* fondo(0.8);
|
|
1491
|
+
* trazo('red');
|
|
1492
|
+
* círculo(-50, 0, 80);
|
|
1493
|
+
*
|
|
1494
|
+
* grosorTrazo(12);
|
|
1495
|
+
* círculo(50, 0, 80);
|
|
1496
|
+
*/
|
|
1497
|
+
function grosorTrazo(grosor: number): void;
|
|
1498
|
+
|
|
1499
|
+
/** 💅
|
|
1500
|
+
* Establece la opacidad global, que afecta a todas las operaciones de dibujo posteriores, excepto `fondo`. El defecto es 1, totalmente opaco.
|
|
1501
|
+
*
|
|
1502
|
+
* En q5 WebGPU esta función solo afecta a imágenes.
|
|
1503
|
+
* @param {number} alfa nivel de opacidad, variando de 0 a 1
|
|
1504
|
+
* @example
|
|
1505
|
+
* await crearLienzo(200);
|
|
1506
|
+
* fondo(0.8);
|
|
1507
|
+
*
|
|
1508
|
+
* opacidad(1);
|
|
1509
|
+
* círculo(-20, -20, 80);
|
|
1510
|
+
*
|
|
1511
|
+
* opacidad(0.2);
|
|
1512
|
+
* cuadrado(-20, -20, 80);
|
|
1513
|
+
*/
|
|
1514
|
+
function opacidad(alfa: number): void;
|
|
1515
|
+
|
|
1516
|
+
/** 💅
|
|
1517
|
+
* Establece el color de la sombra. El defecto es transparente (sin sombra).
|
|
1518
|
+
*
|
|
1519
|
+
* Las sombras se aplican a cualquier cosa dibujada en el lienzo, incluyendo formas rellenas,
|
|
1520
|
+
* trazos, texto, e imágenes.
|
|
1521
|
+
*
|
|
1522
|
+
* Como la función [`color`](https://q5js.org/learn/#color), esta función
|
|
1523
|
+
* puede aceptar colores en una amplia gama de formatos: como una cadena de color CSS,
|
|
1524
|
+
* un objeto `Color`, valor de escala de grises, o valores de componentes de color.
|
|
1525
|
+
*
|
|
1526
|
+
* No disponible en q5 WebGPU.
|
|
1527
|
+
* @param {Color} color color de sombra
|
|
1528
|
+
*/
|
|
1529
|
+
function sombra(color: string | Color): void;
|
|
1530
|
+
|
|
1531
|
+
/** 💅
|
|
1532
|
+
* Deshabilita el efecto de sombra.
|
|
1533
|
+
*
|
|
1534
|
+
* No disponible en q5 WebGPU.
|
|
1535
|
+
*/
|
|
1536
|
+
function sinSombra(): void;
|
|
1537
|
+
|
|
1538
|
+
/** 💅
|
|
1539
|
+
* Establece el desplazamiento de la sombra y el radio de desenfoque.
|
|
1540
|
+
*
|
|
1541
|
+
* Cuando q5 comienza, el desplazamiento de la sombra es (10, 10) con un desenfoque de 10.
|
|
1542
|
+
*
|
|
1543
|
+
* No disponible en q5 WebGPU.
|
|
1544
|
+
* @param {number} offsetX desplazamiento horizontal de la sombra
|
|
1545
|
+
* @param {number} offsetY desplazamiento vertical de la sombra, por defecto es el mismo que offsetX
|
|
1546
|
+
* @param {number} desenfoque radio de desenfoque de la sombra, por defecto es 0
|
|
1547
|
+
*/
|
|
1548
|
+
function cajaSombra(offsetX: number, offsetY: number, desenfoque: number): void;
|
|
1549
|
+
|
|
1550
|
+
/** 💅
|
|
1551
|
+
* Establece la operación de composición global para el contexto del lienzo.
|
|
1552
|
+
*
|
|
1553
|
+
* No disponible en q5 WebGPU.
|
|
1554
|
+
* @param {string} val operación de composición
|
|
1555
|
+
*/
|
|
1556
|
+
function modoMezcla(val: string): void;
|
|
1557
|
+
|
|
1558
|
+
/** 💅
|
|
1559
|
+
* Establece el estilo de terminación de línea a `ROUND`, `SQUARE`, o `PROJECT`.
|
|
1560
|
+
*
|
|
1561
|
+
* No disponible en q5 WebGPU.
|
|
1562
|
+
* @param {CanvasLineCap} val estilo de terminación de línea
|
|
1563
|
+
*/
|
|
1564
|
+
function terminaciónTrazo(): void;
|
|
1565
|
+
|
|
1566
|
+
/** 💅
|
|
1567
|
+
* Establece el estilo de unión de línea a `ROUND`, `BEVEL`, o `MITER`.
|
|
1568
|
+
*
|
|
1569
|
+
* No disponible en q5 WebGPU.
|
|
1570
|
+
* @param {CanvasLineJoin} val estilo de unión de línea
|
|
1571
|
+
*/
|
|
1572
|
+
function uniónTrazo(): void;
|
|
1573
|
+
|
|
1574
|
+
/** 💅
|
|
1575
|
+
* Establece el lienzo en modo borrar, donde las formas borrarán lo que está
|
|
1576
|
+
* debajo de ellas en lugar de dibujar sobre ello.
|
|
1577
|
+
*
|
|
1578
|
+
* No disponible en q5 WebGPU.
|
|
1579
|
+
* @param {number} [rellenoAlfa] nivel de opacidad del color de relleno
|
|
1580
|
+
* @param {number} [trazoAlfa] nivel de opacidad del color de trazo
|
|
1581
|
+
*/
|
|
1582
|
+
function borrar(rellenoAlfa?: number, trazoAlfa?: number): void;
|
|
1583
|
+
|
|
1584
|
+
/** 💅
|
|
1585
|
+
* Reinicia el lienzo del modo borrar al modo de dibujo normal.
|
|
1586
|
+
*
|
|
1587
|
+
* No disponible en q5 WebGPU.
|
|
1588
|
+
*/
|
|
1589
|
+
function noBorrar(): void;
|
|
1590
|
+
|
|
1591
|
+
/** 💅
|
|
1592
|
+
* Guarda la configuración de estilo de dibujo actual.
|
|
1593
|
+
*
|
|
1594
|
+
* Esto incluye el relleno, trazo, grosor de trazo, tinte, modo de imagen,
|
|
1595
|
+
* modo de rectángulo, modo de elipse, tamaño de texto, alineación de texto, línea base de texto, y
|
|
1596
|
+
* configuración de sombra.
|
|
1597
|
+
* @example
|
|
1598
|
+
* await crearLienzo(200);
|
|
1599
|
+
* fondo(0.8);
|
|
1600
|
+
*
|
|
1601
|
+
* guardarEstilos();
|
|
1602
|
+
* relleno('blue');
|
|
1603
|
+
* círculo(-50, -50, 80);
|
|
1604
|
+
*
|
|
1605
|
+
* recuperarEstilos();
|
|
1606
|
+
* círculo(50, 50, 80);
|
|
1607
|
+
*/
|
|
1608
|
+
function guardarEstilos(): void;
|
|
1609
|
+
|
|
1610
|
+
/** 💅
|
|
1611
|
+
* Restaura la configuración de estilo de dibujo guardada previamente.
|
|
1612
|
+
* @example
|
|
1613
|
+
* await crearLienzo(200);
|
|
1614
|
+
* fondo(0.8);
|
|
1615
|
+
*
|
|
1616
|
+
* guardarEstilos();
|
|
1617
|
+
* relleno('blue');
|
|
1618
|
+
* círculo(-50, -50, 80);
|
|
1619
|
+
*
|
|
1620
|
+
* recuperarEstilos();
|
|
1621
|
+
* círculo(50, 50, 80);
|
|
1622
|
+
*/
|
|
1623
|
+
function recuperarEstilos(): void;
|
|
1624
|
+
|
|
1625
|
+
/** 💅
|
|
1626
|
+
* Limpia el lienzo, haciendo que cada píxel sea completamente transparente.
|
|
1627
|
+
*
|
|
1628
|
+
* Ten en cuenta que el lienzo solo se puede ver a través si tiene un canal alfa.
|
|
1629
|
+
*
|
|
1630
|
+
* #### webgpu
|
|
1631
|
+
*/
|
|
1632
|
+
function limpiar(): void;
|
|
1633
|
+
|
|
1634
|
+
/** 💅
|
|
1635
|
+
* Comprueba si un punto dado está dentro del área de relleno del camino actual.
|
|
1636
|
+
*
|
|
1637
|
+
* No disponible en q5 WebGPU.
|
|
1638
|
+
* @param {number} x coordenada-x del punto
|
|
1639
|
+
* @param {number} y coordenada-y del punto
|
|
1640
|
+
* @returns {boolean} verdadero si el punto está dentro del área de relleno, falso de lo contrario
|
|
1641
|
+
*/
|
|
1642
|
+
function enRelleno(x: number, y: number): boolean;
|
|
1643
|
+
|
|
1644
|
+
/** 💅
|
|
1645
|
+
* Comprueba si un punto dado está dentro del trazo del camino actual.
|
|
1646
|
+
*
|
|
1647
|
+
* No disponible en q5 WebGPU.
|
|
1648
|
+
* @param {number} x coordenada-x del punto
|
|
1649
|
+
* @param {number} y coordenada-y del punto
|
|
1650
|
+
* @returns {boolean} verdadero si el punto está dentro del trazo, falso de lo contrario
|
|
1651
|
+
*/
|
|
1652
|
+
function enTrazo(x: number, y: number): boolean;
|
|
1653
|
+
|
|
1654
|
+
// 🦋 transforms
|
|
1655
|
+
|
|
1656
|
+
/** 🦋
|
|
1657
|
+
* Traslada el origen del contexto de dibujo.
|
|
1658
|
+
* @param {number} x traslación a lo largo del eje x
|
|
1659
|
+
* @param {number} y traslación a lo largo del eje y
|
|
1660
|
+
* @example
|
|
1661
|
+
* q5.dibujar = function () {
|
|
1662
|
+
* fondo(0.8);
|
|
1663
|
+
*
|
|
1664
|
+
* trasladar(50, 50);
|
|
1665
|
+
* círculo(0, 0, 80);
|
|
1666
|
+
* };
|
|
1667
|
+
*/
|
|
1668
|
+
function trasladar(x: number, y: number): void;
|
|
1669
|
+
|
|
1670
|
+
/** 🦋
|
|
1671
|
+
* Rota el contexto de dibujo.
|
|
1672
|
+
* @param {number} angulo ángulo de rotación en radianes
|
|
1673
|
+
* @example
|
|
1674
|
+
* q5.dibujar = function () {
|
|
1675
|
+
* fondo(0.8);
|
|
1676
|
+
*
|
|
1677
|
+
* rotar(ratónX / 50);
|
|
1678
|
+
*
|
|
1679
|
+
* modoRect(CENTER);
|
|
1680
|
+
* cuadrado(0, 0, 120);
|
|
1681
|
+
* };
|
|
1682
|
+
*/
|
|
1683
|
+
function rotar(angulo: number): void;
|
|
1684
|
+
|
|
1685
|
+
/** 🦋
|
|
1686
|
+
* Escala el contexto de dibujo.
|
|
1687
|
+
*
|
|
1688
|
+
* Si solo se proporciona un parámetro de entrada,
|
|
1689
|
+
* el contexto de dibujo se escalará uniformemente.
|
|
1690
|
+
* @param {number} x factor de escala a lo largo del eje x
|
|
1691
|
+
* @param {number} [y] factor de escala a lo largo del eje y
|
|
1692
|
+
* @example
|
|
1693
|
+
* q5.dibujar = function () {
|
|
1694
|
+
* fondo(0.8);
|
|
1695
|
+
*
|
|
1696
|
+
* escalar(ratónX / 10);
|
|
1697
|
+
* círculo(0, 0, 20);
|
|
1698
|
+
* };
|
|
1699
|
+
*/
|
|
1700
|
+
function escalar(x: number, y?: number): void;
|
|
1701
|
+
|
|
1702
|
+
/** 🦋
|
|
1703
|
+
* Cizalla el contexto de dibujo a lo largo del eje x.
|
|
1704
|
+
* @param {number} angulo ángulo de cizallamiento en radianes
|
|
1705
|
+
* @example
|
|
1706
|
+
* q5.dibujar = function () {
|
|
1707
|
+
* fondo(0.8);
|
|
1708
|
+
*
|
|
1709
|
+
* trasladar(-75, -40);
|
|
1710
|
+
* cizallarX(ratónX / 100);
|
|
1711
|
+
* cuadrado(0, 0, 80);
|
|
1712
|
+
* };
|
|
1713
|
+
*/
|
|
1714
|
+
function cizallarX(angulo: number): void;
|
|
1715
|
+
|
|
1716
|
+
/** 🦋
|
|
1717
|
+
* Cizalla el contexto de dibujo a lo largo del eje y.
|
|
1718
|
+
* @param {number} angulo ángulo de cizallamiento en radianes
|
|
1719
|
+
* @example
|
|
1720
|
+
* q5.dibujar = function () {
|
|
1721
|
+
* fondo(0.8);
|
|
1722
|
+
*
|
|
1723
|
+
* trasladar(-75, -40);
|
|
1724
|
+
* cizallarY(ratónX / 100);
|
|
1725
|
+
* cuadrado(0, 0, 80);
|
|
1726
|
+
* };
|
|
1727
|
+
*/
|
|
1728
|
+
function cizallarY(angulo: number): void;
|
|
1729
|
+
|
|
1730
|
+
/** 🦋
|
|
1731
|
+
* Aplica una matriz de transformación.
|
|
1732
|
+
*
|
|
1733
|
+
* Acepta una matriz de 3x3 como un array o múltiples argumentos.
|
|
1734
|
+
*
|
|
1735
|
+
* Ten en cuenta que en q5 WebGPU, la matriz de identidad (por defecto)
|
|
1736
|
+
* tiene una escala y negativa para voltear el eje y para coincidir con
|
|
1737
|
+
* el renderizador Canvas2D.
|
|
1738
|
+
* @param {number} a
|
|
1739
|
+
* @param {number} b
|
|
1740
|
+
* @param {number} c
|
|
1741
|
+
* @param {number} d
|
|
1742
|
+
* @param {number} e
|
|
1743
|
+
* @param {number} f
|
|
1744
|
+
* @example
|
|
1745
|
+
* q5.dibujar = function () {
|
|
1746
|
+
* fondo(0.8);
|
|
1747
|
+
*
|
|
1748
|
+
* aplicarMatriz(2, -1, 1, -1);
|
|
1749
|
+
* círculo(0, 0, 80);
|
|
1750
|
+
* };
|
|
1751
|
+
*/
|
|
1752
|
+
function aplicarMatriz(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
1753
|
+
|
|
1754
|
+
/** 🦋
|
|
1755
|
+
* Reinicia la matriz de transformación.
|
|
1756
|
+
*
|
|
1757
|
+
* q5 ejecuta esta función antes de cada vez que se ejecuta la función `dibujar`,
|
|
1758
|
+
* para que las transformaciones no se trasladen al siguiente fotograma.
|
|
1759
|
+
* @example
|
|
1760
|
+
* await crearLienzo(200);
|
|
1761
|
+
* fondo(0.8);
|
|
1762
|
+
*
|
|
1763
|
+
* trasladar(50, 50);
|
|
1764
|
+
* círculo(0, 0, 80);
|
|
1765
|
+
*
|
|
1766
|
+
* reiniciarMatriz();
|
|
1767
|
+
* cuadrado(0, 0, 50);
|
|
1768
|
+
*/
|
|
1769
|
+
function reiniciarMatriz(): void;
|
|
1770
|
+
|
|
1771
|
+
/** 🦋
|
|
1772
|
+
* Guarda la matriz de transformación actual.
|
|
1773
|
+
* @example
|
|
1774
|
+
* await crearLienzo(200);
|
|
1775
|
+
* fondo(0.8);
|
|
1776
|
+
*
|
|
1777
|
+
* guardarMatriz();
|
|
1778
|
+
* rotar(CUARTO_PI);
|
|
1779
|
+
* elipse(0, 0, 120, 40);
|
|
1780
|
+
* recuperarMatriz();
|
|
1781
|
+
*
|
|
1782
|
+
* elipse(0, 0, 120, 40);
|
|
1783
|
+
*/
|
|
1784
|
+
function guardarMatriz(): void;
|
|
1785
|
+
|
|
1786
|
+
/** 🦋
|
|
1787
|
+
* Restaura la matriz de transformación guardada previamente.
|
|
1788
|
+
* @example
|
|
1789
|
+
* await crearLienzo(200);
|
|
1790
|
+
* fondo(0.8);
|
|
1791
|
+
*
|
|
1792
|
+
* guardarMatriz();
|
|
1793
|
+
* rotar(CUARTO_PI);
|
|
1794
|
+
* elipse(0, 0, 120, 40);
|
|
1795
|
+
* recuperarMatriz();
|
|
1796
|
+
*
|
|
1797
|
+
* elipse(0, 0, 120, 40);
|
|
1798
|
+
*/
|
|
1799
|
+
function recuperarMatriz(): void;
|
|
1800
|
+
|
|
1801
|
+
/** 🦋
|
|
1802
|
+
* Guarda la configuración de estilo de dibujo y transformaciones actuales.
|
|
1803
|
+
* @example
|
|
1804
|
+
* await crearLienzo(200);
|
|
1805
|
+
*
|
|
1806
|
+
* guardar();
|
|
1807
|
+
* relleno('blue');
|
|
1808
|
+
* trasladar(50, 50);
|
|
1809
|
+
* círculo(0, 0, 80);
|
|
1810
|
+
* recuperar();
|
|
1811
|
+
*
|
|
1812
|
+
* cuadrado(0, 0, 50);
|
|
1813
|
+
*/
|
|
1814
|
+
function guardar(datos?: object, nombreArchivo?: string): void;
|
|
1815
|
+
|
|
1816
|
+
/** 🦋
|
|
1817
|
+
* Restaura la configuración de estilo de dibujo y transformaciones guardadas previamente.
|
|
1818
|
+
* @example
|
|
1819
|
+
* await crearLienzo(200);
|
|
1820
|
+
*
|
|
1821
|
+
* guardar();
|
|
1822
|
+
* relleno('blue');
|
|
1823
|
+
* trasladar(50, 50);
|
|
1824
|
+
* círculo(0, 0, 80);
|
|
1825
|
+
* recuperar();
|
|
1826
|
+
*
|
|
1827
|
+
* cuadrado(0, 0, 50);
|
|
1828
|
+
*/
|
|
1829
|
+
function recuperar(): void;
|
|
1830
|
+
|
|
1831
|
+
// 💻 display
|
|
1832
|
+
|
|
1833
|
+
/** 💻
|
|
1834
|
+
* El ancho de la ventana (cantidad de píxeles). Atajo para `window.innerWidth`.
|
|
1835
|
+
*/
|
|
1836
|
+
var anchoVentana: number;
|
|
1837
|
+
|
|
1838
|
+
/** 💻
|
|
1839
|
+
* El alto de la ventana (cantidad de píxeles). Atajo para `window.innerHeight`.
|
|
1840
|
+
*/
|
|
1841
|
+
var altoVentana: number;
|
|
1842
|
+
|
|
1843
|
+
/** 💻
|
|
1844
|
+
* Número del cuadro actual, es decir, la cantidad de cuadros que se han dibujado desde que se inició el sketch.
|
|
1845
|
+
*/
|
|
1846
|
+
var cuadroActual: number;
|
|
1847
|
+
|
|
1848
|
+
/** 💻
|
|
1849
|
+
* Detiene el bucle de dibujo.
|
|
1850
|
+
*/
|
|
1851
|
+
function pausar(): void;
|
|
1852
|
+
|
|
1853
|
+
/** 💻
|
|
1854
|
+
* Dibuja el lienzo `n` veces. Si no recibe parametro, se dibuja una sola vez. Útil para controlar animaciones con el bucle pausado.
|
|
1855
|
+
* @param {number} [n] cantidad de veces que se volverá a dibujar el lienzo, por defecto es 1
|
|
1856
|
+
*/
|
|
1857
|
+
function redibujar(n?: number): void;
|
|
1858
|
+
|
|
1859
|
+
/** 💻
|
|
1860
|
+
* Vuelve a activar el bucle de dibujo en caso de que estuviera pausado.
|
|
1861
|
+
*/
|
|
1862
|
+
function reanudar(): void;
|
|
1863
|
+
|
|
1864
|
+
/** 💻
|
|
1865
|
+
* Si recibe un parámetro, establece la cantidad ideal de cuadros que se intentarán dibujar por cada segundo (es decir, la tasa de refresco, la frecuencia del bucle).
|
|
1866
|
+
*
|
|
1867
|
+
* Retorna la frecuencia real alcanzada durante el último segundo de ejecución. Incluso si nunca se modifica explícitamente la frecuencia, el valor real suele fluctuar entre el ideal y 0. Para un mejor análisis del rendimiento usar las herramientas del navegador (DevTools).
|
|
1868
|
+
* @param `hz` {number} [frecuencia] cantidad ideal de cuadros a dibujar en un segundo, por defecto es 60
|
|
1869
|
+
* @returns {number} frecuencia real del bucle en el último segundo
|
|
1870
|
+
*/
|
|
1871
|
+
function frecuenciaRefresco(hertz?: number): number;
|
|
1872
|
+
|
|
1873
|
+
/** 💻
|
|
1874
|
+
* Retorna la cantidad ideal de cuadros que se intentan dibujar por segundo.
|
|
1875
|
+
*/
|
|
1876
|
+
function frecuenciaIdeal(): void;
|
|
1877
|
+
|
|
1878
|
+
/** 💻
|
|
1879
|
+
* Retorna la cantidad maxima de cuadros que se podrían estar dibujando en cada segundo.
|
|
1880
|
+
*
|
|
1881
|
+
* Es un valor teórico que depende del estado del dispositivo. Para un mejor análisis del rendimiento usar las herramientas del navegador (DevTools).
|
|
1882
|
+
* @returns {number} cantidad máxima teorica de cuadros por segundo
|
|
1883
|
+
*/
|
|
1884
|
+
function frecuenciaMaxima(): void;
|
|
1885
|
+
|
|
1886
|
+
/** 💻
|
|
1887
|
+
* Funcion a declarar. Se ejecuta después de cada llamada a `dibujar` y de los `hooks de dibujo`, pero antes de dibujar realmente el lienzo.
|
|
1888
|
+
*
|
|
1889
|
+
* Útil para agregar efectos finales cuando es difícil hacerlo en la función de dibujo. Por ejemplo, al usar extensiones como p5play que dibujan capas superpuestas al lienzo.
|
|
1890
|
+
*/
|
|
1891
|
+
function retocarDibujo(): void;
|
|
1892
|
+
|
|
1893
|
+
/** 💻
|
|
1894
|
+
* Milisegundos que han pasado desde el último cuadro dibujado. Con la frecuencia por defecto a 60 hz, el tiempo aproximado es 16.6 ms o mas.
|
|
1895
|
+
*
|
|
1896
|
+
* Útil para mantener las animaciones sincronizadas con precisión, sobretodo si existen momentos en que la ejecución se ralentiza por sobrecarga del dispositivo. En casos en que la frecuencia real del bucle sea considerablemente mas baja, es recomendable reducir la frecuencia ideal.
|
|
1897
|
+
*/
|
|
1898
|
+
function ultimoTiempo(): void;
|
|
1899
|
+
|
|
1900
|
+
const MAXIMIZADO: 'maxed';
|
|
1901
|
+
|
|
1902
|
+
const SUAVE: 'smooth';
|
|
1903
|
+
|
|
1904
|
+
const PIXELADO: 'pixelated';
|
|
1905
|
+
|
|
1906
|
+
function pantallaCompleta(v?: boolean): void;
|
|
1907
|
+
|
|
1908
|
+
var ancho: number;
|
|
1909
|
+
|
|
1910
|
+
var alto: number;
|
|
1911
|
+
|
|
1912
|
+
var medioAncho: number;
|
|
1913
|
+
|
|
1914
|
+
var medioAlto: number;
|
|
1915
|
+
|
|
1916
|
+
var lienzo: HTMLCanvasElement;
|
|
1917
|
+
|
|
1918
|
+
function redimensionarLienzo(w: number, h: number): void;
|
|
1919
|
+
|
|
1920
|
+
function obtenerTasaFotogramasObjetivo(): number;
|
|
1921
|
+
|
|
1922
|
+
function obtenerFPS(): number;
|
|
1923
|
+
|
|
1924
|
+
function postProcesar(): void;
|
|
1925
|
+
|
|
1926
|
+
var deltaTiempo: number;
|
|
1927
|
+
|
|
1928
|
+
var contextoDibujo: CanvasRenderingContext2D;
|
|
1929
|
+
|
|
1930
|
+
// 🧮 math
|
|
1931
|
+
|
|
1932
|
+
/** 🧮
|
|
1933
|
+
* Genera un valor aleatorio.
|
|
1934
|
+
*
|
|
1935
|
+
* - Si no se proporcionan entradas, devuelve un número entre 0 y 1.
|
|
1936
|
+
* - Si se proporciona una entrada numérica, devuelve un número entre 0 y el valor proporcionado.
|
|
1937
|
+
* - Si se proporcionan dos entradas numéricas, devuelve un número entre los dos valores.
|
|
1938
|
+
* - Si se proporciona un array, devuelve un elemento aleatorio del array.
|
|
1939
|
+
* @param {number | any[]} [bajo] límite inferior (inclusivo) o un array
|
|
1940
|
+
* @param {number} [alto] límite superior (exclusivo)
|
|
1941
|
+
* @returns {number | any} un número o elemento aleatorio
|
|
1942
|
+
* @example
|
|
1943
|
+
* await crearLienzo(200);
|
|
1944
|
+
* fondo(0.8);
|
|
1945
|
+
* frecuenciaRefresco(5);
|
|
1946
|
+
*
|
|
1947
|
+
* q5.dibujar = function () {
|
|
1948
|
+
* círculo(0, 0, aleatorio(200));
|
|
1949
|
+
* };
|
|
1950
|
+
* @example
|
|
1951
|
+
* q5.dibujar = function () {
|
|
1952
|
+
* círculo(aleatorio(-100, 100), aleatorio(-100, 100), 10);
|
|
1953
|
+
* };
|
|
1954
|
+
*/
|
|
1955
|
+
function aleatorio(bajo?: number | any[], alto?: number): number | any;
|
|
1956
|
+
|
|
1957
|
+
/** 🧮
|
|
1958
|
+
* Genera un número aleatorio dentro de un rango simétrico alrededor de cero.
|
|
1959
|
+
*
|
|
1960
|
+
* Se puede usar para crear un efecto de fluctuación (desplazamiento aleatorio).
|
|
1961
|
+
*
|
|
1962
|
+
* Equivalente a `aleatorio(-cantidad, cantidad)`.
|
|
1963
|
+
* @param {number} cantidad cantidad máxima absoluta de fluctuación, por defecto es 1
|
|
1964
|
+
* @returns {number} número aleatorio entre -val y val
|
|
1965
|
+
* @example
|
|
1966
|
+
* q5.dibujar = function () {
|
|
1967
|
+
* círculo(ratónX + flu(3), ratónY + flu(3), 5);
|
|
1968
|
+
* };
|
|
1969
|
+
* @example
|
|
1970
|
+
* await crearLienzo(200);
|
|
1971
|
+
*
|
|
1972
|
+
* q5.dibujar = function () {
|
|
1973
|
+
* círculo(flu(50), 0, aleatorio(50));
|
|
1974
|
+
* };
|
|
1975
|
+
*/
|
|
1976
|
+
function flu(cantidad: number): number;
|
|
1977
|
+
|
|
1978
|
+
/** 🧮
|
|
1979
|
+
* Genera un valor de ruido basado en las entradas x, y, y z.
|
|
1980
|
+
*
|
|
1981
|
+
* Usa [Ruido Perlin](https://es.wikipedia.org/wiki/Ruido_Perlin) por defecto.
|
|
1982
|
+
* @param {number} [x] entrada coordenada-x
|
|
1983
|
+
* @param {number} [y] entrada coordenada-y
|
|
1984
|
+
* @param {number} [z] entrada coordenada-z
|
|
1985
|
+
* @returns {number} un valor de ruido
|
|
1986
|
+
* @example
|
|
1987
|
+
* q5.dibujar = function () {
|
|
1988
|
+
* fondo(0.8);
|
|
1989
|
+
* let n = ruido(frameCount * 0.01);
|
|
1990
|
+
* círculo(0, 0, n * 200);
|
|
1991
|
+
* };
|
|
1992
|
+
* @example
|
|
1993
|
+
* q5.dibujar = function () {
|
|
1994
|
+
* fondo(0.8);
|
|
1995
|
+
* let t = (frameCount + ratónX) * 0.02;
|
|
1996
|
+
* for (let x = -5; x < 220; x += 10) {
|
|
1997
|
+
* let n = ruido(t, x * 0.1);
|
|
1998
|
+
* círculo(x - 100, 0, n * 40);
|
|
1999
|
+
* }
|
|
2000
|
+
* };
|
|
2001
|
+
* @example
|
|
2002
|
+
* q5.dibujar = function () {
|
|
2003
|
+
* sinTrazo();
|
|
2004
|
+
* let t = millis() * 0.002;
|
|
2005
|
+
* for (let x = -100; x < 100; x += 5) {
|
|
2006
|
+
* for (let y = -100; y < 100; y += 5) {
|
|
2007
|
+
* relleno(ruido(t, (ratónX + x) * 0.05, y * 0.05));
|
|
2008
|
+
* cuadrado(x, y, 5);
|
|
2009
|
+
* }
|
|
2010
|
+
* }
|
|
2011
|
+
* };
|
|
2012
|
+
*/
|
|
2013
|
+
function ruido(x?: number, y?: number, z?: number): number;
|
|
2014
|
+
|
|
2015
|
+
/** 🧮
|
|
2016
|
+
* Calcula la distancia entre dos puntos.
|
|
2017
|
+
*
|
|
2018
|
+
* Esta función también acepta dos objetos con propiedades `x` e `y`.
|
|
2019
|
+
* @param {number} x1 coordenada-x del primer punto
|
|
2020
|
+
* @param {number} y1 coordenada-y del primer punto
|
|
2021
|
+
* @param {number} x2 coordenada-x del segundo punto
|
|
2022
|
+
* @param {number} y2 coordenada-y del segundo punto
|
|
2023
|
+
* @returns {number} distancia entre los puntos
|
|
2024
|
+
* @example
|
|
2025
|
+
* q5.dibujar = function () {
|
|
2026
|
+
* fondo(0.8);
|
|
2027
|
+
* línea(0, 0, ratónX, ratónY);
|
|
2028
|
+
*
|
|
2029
|
+
* let d = dist(0, 0, ratónX, ratónY);
|
|
2030
|
+
* texto(redondear(d), -80, -80);
|
|
2031
|
+
* };
|
|
2032
|
+
*/
|
|
2033
|
+
function dist(x1: number, y1: number, x2: number, y2: number): number;
|
|
2034
|
+
|
|
2035
|
+
/** 🧮
|
|
2036
|
+
* Mapea un número de un rango a otro.
|
|
2037
|
+
* @param {number} val valor entrante a convertir
|
|
2038
|
+
* @param {number} inicio1 límite inferior del rango actual del valor
|
|
2039
|
+
* @param {number} fin1 límite superior del rango actual del valor
|
|
2040
|
+
* @param {number} inicio2 límite inferior del rango objetivo del valor
|
|
2041
|
+
* @param {number} fin2 límite superior del rango objetivo del valor
|
|
2042
|
+
* @returns {number} valor mapeado
|
|
2043
|
+
*/
|
|
2044
|
+
function mapa(val: number, inicio1: number, fin1: number, inicio2: number, fin2: number): number;
|
|
2045
|
+
|
|
2046
|
+
/** 🧮
|
|
2047
|
+
* Establece el modo para interpretar y dibujar ángulos. Puede ser 'degrees' (grados) o 'radians' (radianes).
|
|
2048
|
+
* @param {'degrees' | 'radians'} modo modo a establecer para la interpretación de ángulos
|
|
2049
|
+
*/
|
|
2050
|
+
function modoÁngulo(): void;
|
|
2051
|
+
|
|
2052
|
+
/** 🧮
|
|
2053
|
+
* Convierte grados a radianes.
|
|
2054
|
+
* @param {number} grados ángulo en grados
|
|
2055
|
+
* @returns {number} ángulo en radianes
|
|
2056
|
+
*/
|
|
2057
|
+
function radianes(grados: number): number;
|
|
2058
|
+
|
|
2059
|
+
/** 🧮
|
|
2060
|
+
* Convierte radianes a grados.
|
|
2061
|
+
* @param {number} radianes ángulo en radianes
|
|
2062
|
+
* @returns {number} ángulo en grados
|
|
2063
|
+
*/
|
|
2064
|
+
function grados(radianes: number): number;
|
|
2065
|
+
|
|
2066
|
+
/** 🧮
|
|
2067
|
+
* Calcula un número entre dos números en un incremento específico.
|
|
2068
|
+
* @param {number} inicio primer número
|
|
2069
|
+
* @param {number} fin segundo número
|
|
2070
|
+
* @param {number} cant cantidad a interpolar entre los dos valores
|
|
2071
|
+
* @returns {number} número interpolado
|
|
2072
|
+
*/
|
|
2073
|
+
function interpolar(inicio: number, fin: number, cant: number): number;
|
|
2074
|
+
|
|
2075
|
+
/** 🧮
|
|
2076
|
+
* Restringe un valor entre un valor mínimo y máximo.
|
|
2077
|
+
* @param {number} n número a restringir
|
|
2078
|
+
* @param {number} bajo límite inferior
|
|
2079
|
+
* @param {number} alto límite superior
|
|
2080
|
+
* @returns {number} valor restringido
|
|
2081
|
+
*/
|
|
2082
|
+
function constreñir(): void;
|
|
2083
|
+
|
|
2084
|
+
/** 🧮
|
|
2085
|
+
* Normaliza un número de otro rango en un valor entre 0 y 1.
|
|
2086
|
+
* @param {number} n número a normalizar
|
|
2087
|
+
* @param {number} inicio límite inferior del rango
|
|
2088
|
+
* @param {number} fin límite superior del rango
|
|
2089
|
+
* @returns {number} número normalizado
|
|
2090
|
+
*/
|
|
2091
|
+
function norm(n: number, inicio: number, fin: number): number;
|
|
2092
|
+
|
|
2093
|
+
/** 🧮
|
|
2094
|
+
* Calcula la parte fraccionaria de un número.
|
|
2095
|
+
* @param {number} n un número
|
|
2096
|
+
* @returns {number} parte fraccionaria del número
|
|
2097
|
+
*/
|
|
2098
|
+
function frac(n: number): number;
|
|
2099
|
+
|
|
2100
|
+
/** 🧮
|
|
2101
|
+
* Calcula el valor absoluto de un número.
|
|
2102
|
+
* @param {number} n un número
|
|
2103
|
+
* @returns {number} valor absoluto del número
|
|
2104
|
+
*/
|
|
2105
|
+
function abs(n: number): number;
|
|
2106
|
+
|
|
2107
|
+
/** 🧮
|
|
2108
|
+
* Redondea un número.
|
|
2109
|
+
* @param {number} n número a redondear
|
|
2110
|
+
* @param {number} [d] número de lugares decimales a redondear
|
|
2111
|
+
* @returns {number} número redondeado
|
|
2112
|
+
* @example
|
|
2113
|
+
* await crearLienzo(200, 100);
|
|
2114
|
+
* fondo(0.8);
|
|
2115
|
+
* tamañoTexto(32);
|
|
2116
|
+
* texto(redondear(PI, 5), -90, 10);
|
|
2117
|
+
*/
|
|
2118
|
+
function redondear(n: number, d: number): number;
|
|
2119
|
+
|
|
2120
|
+
/** 🧮
|
|
2121
|
+
* Redondea un número hacia arriba.
|
|
2122
|
+
* @param {number} n un número
|
|
2123
|
+
* @returns {number} número redondeado
|
|
2124
|
+
* @example
|
|
2125
|
+
* await crearLienzo(200, 100);
|
|
2126
|
+
* fondo(0.8);
|
|
2127
|
+
* tamañoTexto(32);
|
|
2128
|
+
* texto(techo(PI), -90, 10);
|
|
2129
|
+
*/
|
|
2130
|
+
function techo(n: number): number;
|
|
2131
|
+
|
|
2132
|
+
/** 🧮
|
|
2133
|
+
* Redondea un número hacia abajo.
|
|
2134
|
+
* @param {number} n un número
|
|
2135
|
+
* @returns {number} número redondeado
|
|
2136
|
+
* @example
|
|
2137
|
+
* await crearLienzo(200, 100);
|
|
2138
|
+
* fondo(0.8);
|
|
2139
|
+
* tamañoTexto(32);
|
|
2140
|
+
* texto(piso(-PI), -90, 10);
|
|
2141
|
+
*/
|
|
2142
|
+
function piso(n: number): number;
|
|
2143
|
+
|
|
2144
|
+
/** 🧮
|
|
2145
|
+
* Devuelve el valor más pequeño en una secuencia de números.
|
|
2146
|
+
* @param {...number} args números a comparar
|
|
2147
|
+
* @returns {number} mínimo
|
|
2148
|
+
* @example
|
|
2149
|
+
* q5.dibujar = function () {
|
|
2150
|
+
* fondo(min(-ratónX / 100, 0.5));
|
|
2151
|
+
* círculo(min(ratónX, 0), 0, 80);
|
|
2152
|
+
* };
|
|
2153
|
+
*/
|
|
2154
|
+
function min(...args: number[]): number;
|
|
2155
|
+
|
|
2156
|
+
/** 🧮
|
|
2157
|
+
* Devuelve el valor más grande en una secuencia de números.
|
|
2158
|
+
* @param {...number} args números a comparar
|
|
2159
|
+
* @returns {number} máximo
|
|
2160
|
+
* @example
|
|
2161
|
+
* q5.dibujar = function () {
|
|
2162
|
+
* fondo(max(-ratónX / 100, 0.5));
|
|
2163
|
+
* círculo(max(ratónX, 0), 0, 80);
|
|
2164
|
+
* };
|
|
2165
|
+
*/
|
|
2166
|
+
function max(...args: number[]): number;
|
|
2167
|
+
|
|
2168
|
+
/** 🧮
|
|
2169
|
+
* Calcula el valor de una base elevada a una potencia.
|
|
2170
|
+
*
|
|
2171
|
+
* Por ejemplo, `pot(2, 3)` calcula 2 _ 2 _ 2 que es 8.
|
|
2172
|
+
* @param {number} base base
|
|
2173
|
+
* @param {number} exponente exponente
|
|
2174
|
+
* @returns {number} base elevada a la potencia del exponente
|
|
2175
|
+
*/
|
|
2176
|
+
function pot(base: number, exponente: number): number;
|
|
2177
|
+
|
|
2178
|
+
/** 🧮
|
|
2179
|
+
* Calcula el cuadrado de un número.
|
|
2180
|
+
* @param {number} n número a elevar al cuadrado
|
|
2181
|
+
* @returns {number} cuadrado del número
|
|
2182
|
+
*/
|
|
2183
|
+
function cuad(n: number): number;
|
|
2184
|
+
|
|
2185
|
+
/** 🧮
|
|
2186
|
+
* Calcula la raíz cuadrada de un número.
|
|
2187
|
+
* @param {number} n un número
|
|
2188
|
+
* @returns {number} raíz cuadrada del número
|
|
2189
|
+
*/
|
|
2190
|
+
function raiz(n: number): number;
|
|
2191
|
+
|
|
2192
|
+
/** 🧮
|
|
2193
|
+
* Calcula el logaritmo natural (base e) de un número.
|
|
2194
|
+
* @param {number} n un número
|
|
2195
|
+
* @returns {number} logaritmo natural del número
|
|
2196
|
+
*/
|
|
2197
|
+
function loge(n: number): number;
|
|
2198
|
+
|
|
2199
|
+
/** 🧮
|
|
2200
|
+
* Calcula e elevado a la potencia de un número.
|
|
2201
|
+
* @param {number} exponente potencia a la que elevar e
|
|
2202
|
+
* @returns {number} e elevado a la potencia del exponente
|
|
2203
|
+
*/
|
|
2204
|
+
function exp(exponente: number): number;
|
|
2205
|
+
|
|
2206
|
+
/** 🧮
|
|
2207
|
+
* Establece la semilla para el generador de números aleatorios.
|
|
2208
|
+
* @param {number} semilla valor de la semilla
|
|
2209
|
+
*/
|
|
2210
|
+
function semillaAleatoria(semilla: number): void;
|
|
2211
|
+
|
|
2212
|
+
/** 🧮
|
|
2213
|
+
* Establece el método de generación de números aleatorios.
|
|
2214
|
+
* @param {any} metodo método a usar para la generación de números aleatorios
|
|
2215
|
+
*/
|
|
2216
|
+
function generadorAleatorio(metodo: any): void;
|
|
2217
|
+
|
|
2218
|
+
/** 🧮
|
|
2219
|
+
* Genera un número aleatorio siguiendo una distribución Gaussiana (normal).
|
|
2220
|
+
* @param {number} media media (centro) de la distribución
|
|
2221
|
+
* @param {number} std desviación estándar (dispersión o "ancho") de la distribución
|
|
2222
|
+
* @returns {number} un número aleatorio siguiendo una distribución Gaussiana
|
|
2223
|
+
*/
|
|
2224
|
+
function aleatorioGaussiano(media: number, std: number): number;
|
|
2225
|
+
|
|
2226
|
+
/** 🧮
|
|
2227
|
+
* Genera un número aleatorio siguiendo una distribución exponencial.
|
|
2228
|
+
* @returns {number} un número aleatorio siguiendo una distribución exponencial
|
|
2229
|
+
*/
|
|
2230
|
+
function aleatorioExponencial(): number;
|
|
2231
|
+
|
|
2232
|
+
/** 🧮
|
|
2233
|
+
* Establece el modo de generación de ruido.
|
|
2234
|
+
*
|
|
2235
|
+
* Solo el modo por defecto, "perlin", está incluido en q5.js. El uso de los
|
|
2236
|
+
* otros modos requiere el módulo q5-noiser.
|
|
2237
|
+
* @param {'perlin' | 'simplex' | 'blocky'} modo modo de generación de ruido
|
|
2238
|
+
*/
|
|
2239
|
+
function modoRuido(modo: 'perlin' | 'simplex' | 'blocky'): void;
|
|
2240
|
+
|
|
2241
|
+
/** 🧮
|
|
2242
|
+
* Establece el valor de la semilla para la generación de ruido.
|
|
2243
|
+
* @param {number} semilla valor de la semilla
|
|
2244
|
+
*/
|
|
2245
|
+
function semillaRuido(semilla: number): void;
|
|
2246
|
+
|
|
2247
|
+
/** 🧮
|
|
2248
|
+
* Establece el nivel de detalle para la generación de ruido.
|
|
2249
|
+
* @param {number} lod nivel de detalle (número de octavas)
|
|
2250
|
+
* @param {number} caida tasa de caída para cada octava
|
|
2251
|
+
*/
|
|
2252
|
+
function detalleRuido(lod: number, caida: number): void;
|
|
2253
|
+
|
|
2254
|
+
/** 🧮
|
|
2255
|
+
* La relación de la circunferencia de un círculo a su diámetro.
|
|
2256
|
+
* Aproximadamente 3.14159.
|
|
2257
|
+
*/
|
|
2258
|
+
const DOS_PI: number;
|
|
2259
|
+
|
|
2260
|
+
/** 🧮
|
|
2261
|
+
* 2 \* PI.
|
|
2262
|
+
* Aproximadamente 6.28319.
|
|
2263
|
+
*/
|
|
2264
|
+
const DOS_PI: number;
|
|
2265
|
+
|
|
2266
|
+
/** 🧮
|
|
2267
|
+
* 2 \* PI.
|
|
2268
|
+
* Aproximadamente 6.28319.
|
|
2269
|
+
*/
|
|
2270
|
+
function TAU(): void;
|
|
2271
|
+
|
|
2272
|
+
/** 🧮
|
|
2273
|
+
* Mitad de PI.
|
|
2274
|
+
* Aproximadamente 1.5708.
|
|
2275
|
+
*/
|
|
2276
|
+
const MEDIO_PI: number;
|
|
2277
|
+
|
|
2278
|
+
/** 🧮
|
|
2279
|
+
* Un cuarto de PI.
|
|
2280
|
+
* Aproximadamente 0.7854.
|
|
2281
|
+
*/
|
|
2282
|
+
const CUARTO_PI: number;
|
|
2283
|
+
|
|
2284
|
+
// 🔊 sound
|
|
2285
|
+
|
|
2286
|
+
/**
|
|
2287
|
+
* q5 incluye reproducción de sonido de baja latencia y capacidades básicas de mezcla
|
|
2288
|
+
* impulsadas por WebAudio.
|
|
2289
|
+
*
|
|
2290
|
+
* Para filtrado de audio, síntesis y análisis, considera usar el
|
|
2291
|
+
* addon [p5.sound](https://p5js.org/reference/p5.sound/) con q5.
|
|
2292
|
+
*/
|
|
2293
|
+
|
|
2294
|
+
/** 🔊
|
|
2295
|
+
* Carga datos de audio desde un archivo y devuelve un objeto `Sonido`.
|
|
2296
|
+
*
|
|
2297
|
+
* Usa funciones como `reproducir`, `pausar`, y `detener` para
|
|
2298
|
+
* controlar la reproducción. ¡Ten en cuenta que los sonidos solo pueden reproducirse después de la
|
|
2299
|
+
* primera interacción del usuario con la página!
|
|
2300
|
+
*
|
|
2301
|
+
* Establece `volumen` a un valor entre 0 (silencio) y 1 (volumen completo).
|
|
2302
|
+
* Establece `pan` a un valor entre -1 (izquierda) y 1 (derecha) para ajustar
|
|
2303
|
+
* la posición estéreo del sonido. Establece `bucle` a true para repetir el sonido.
|
|
2304
|
+
*
|
|
2305
|
+
* Usa `cargado`, `pausado`, y `terminado` para comprobar el estado del sonido.
|
|
2306
|
+
*
|
|
2307
|
+
* El archivo de sonido completo debe cargarse antes de que la reproducción pueda comenzar, usa `await` para esperar a que un sonido se cargue. Para transmitir archivos de audio más grandes usa la función `cargarAudio` en su lugar.
|
|
2308
|
+
* @param {string} url archivo de sonido
|
|
2309
|
+
* @returns {Sonido & PromiseLike<Sonido>} sonido
|
|
2310
|
+
* @example
|
|
2311
|
+
* await crearLienzo(200);
|
|
2312
|
+
*
|
|
2313
|
+
* let sonido = cargarSonido('/assets/jump.wav');
|
|
2314
|
+
* sonido.volumen = 0.3;
|
|
2315
|
+
*
|
|
2316
|
+
* q5.alPresionarRatón = function () {
|
|
2317
|
+
* sonido.reproducir();
|
|
2318
|
+
* };
|
|
2319
|
+
*/
|
|
2320
|
+
function cargarSonido(url: string): Sonido & PromiseLike<Sonido>;
|
|
2321
|
+
|
|
2322
|
+
/** 🔊
|
|
2323
|
+
* Carga datos de audio desde un archivo y devuelve un [HTMLAudioElement](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement).
|
|
2324
|
+
*
|
|
2325
|
+
* El audio se considera cargado cuando se dispara el [evento canplaythrough](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/canplaythrough_event).
|
|
2326
|
+
*
|
|
2327
|
+
* ¡Ten en cuenta que el audio solo puede reproducirse después de la primera interacción
|
|
2328
|
+
* del usuario con la página!
|
|
2329
|
+
* @param url archivo de audio
|
|
2330
|
+
* @returns {HTMLAudioElement & PromiseLike<HTMLAudioElement>} un HTMLAudioElement
|
|
2331
|
+
* @example
|
|
2332
|
+
* await crearLienzo(200);
|
|
2333
|
+
*
|
|
2334
|
+
* let audio = cargarAudio('/assets/retro.flac');
|
|
2335
|
+
* audio.volume = 0.4;
|
|
2336
|
+
*
|
|
2337
|
+
* q5.alPresionarRatón = function () {
|
|
2338
|
+
* audio.play();
|
|
2339
|
+
* };
|
|
2340
|
+
*/
|
|
2341
|
+
function cargarAudio(url: string): HTMLAudioElement & PromiseLike<HTMLAudioElement>;
|
|
2342
|
+
|
|
2343
|
+
/** 🔊
|
|
2344
|
+
* Devuelve el AudioContext en uso o undefined si no existe.
|
|
2345
|
+
* @returns {AudioContext} instancia de AudioContext
|
|
2346
|
+
*/
|
|
2347
|
+
function obtenerContextoAudio(): AudioContext | void;
|
|
2348
|
+
|
|
2349
|
+
/** 🔊
|
|
2350
|
+
* Crea un nuevo AudioContext o lo reanuda si estaba suspendido.
|
|
2351
|
+
* @returns {Promise<void>} una promesa que se resuelve cuando el AudioContext se reanuda
|
|
2352
|
+
*/
|
|
2353
|
+
function iniciarAudioUsuario(): Promise<void>;
|
|
2354
|
+
|
|
2355
|
+
class Sonido {
|
|
2356
|
+
|
|
2357
|
+
/** 🔊
|
|
2358
|
+
* Crea un nuevo objeto `Q5.Sonido`.
|
|
2359
|
+
*/
|
|
2360
|
+
constructor();
|
|
2361
|
+
|
|
2362
|
+
/** 🔊
|
|
2363
|
+
* Establece el volumen del sonido a un valor entre
|
|
2364
|
+
* 0 (silencio) y 1 (volumen completo).
|
|
2365
|
+
*/
|
|
2366
|
+
volumen: number;
|
|
2367
|
+
|
|
2368
|
+
/** 🔊
|
|
2369
|
+
* Establece la posición estéreo del sonido entre -1 (izquierda) y 1 (derecha).
|
|
2370
|
+
*/
|
|
2371
|
+
pan: number;
|
|
2372
|
+
|
|
2373
|
+
/** 🔊
|
|
2374
|
+
* Establece a true para hacer que el sonido se repita continuamente.
|
|
2375
|
+
*/
|
|
2376
|
+
bucle: boolean;
|
|
2377
|
+
|
|
2378
|
+
/** 🔊
|
|
2379
|
+
* Verdadero si los datos de sonido han terminado de cargarse.
|
|
2380
|
+
*/
|
|
2381
|
+
cargado: boolean;
|
|
2382
|
+
|
|
2383
|
+
/** 🔊
|
|
2384
|
+
* Verdadero si el sonido está actualmente pausado.
|
|
2385
|
+
*/
|
|
2386
|
+
pausado: boolean;
|
|
2387
|
+
|
|
2388
|
+
/** 🔊
|
|
2389
|
+
* Verdadero si el sonido ha terminado de reproducirse.
|
|
2390
|
+
*/
|
|
2391
|
+
terminado: boolean;
|
|
2392
|
+
|
|
2393
|
+
/** 🔊
|
|
2394
|
+
* Reproduce el sonido.
|
|
2395
|
+
*
|
|
2396
|
+
* Si esta función se ejecuta cuando el sonido ya se está reproduciendo,
|
|
2397
|
+
* comenzará una nueva reproducción, causando un efecto de capas.
|
|
2398
|
+
*
|
|
2399
|
+
* Si esta función se ejecuta cuando el sonido está pausado,
|
|
2400
|
+
* todas las instancias de reproducción se reanudarán.
|
|
2401
|
+
*
|
|
2402
|
+
* Usa `await` para esperar a que el sonido termine de reproducirse.
|
|
2403
|
+
* @returns {Promise<void>} una promesa que se resuelve cuando el sonido termina de reproducirse
|
|
2404
|
+
*/
|
|
2405
|
+
reproducir(): void;
|
|
2406
|
+
|
|
2407
|
+
/** 🔊
|
|
2408
|
+
* Pausa el sonido, permitiendo que sea reanudado.
|
|
2409
|
+
*/
|
|
2410
|
+
pausar(): void;
|
|
2411
|
+
|
|
2412
|
+
/** 🔊
|
|
2413
|
+
* Detiene el sonido, reiniciando su posición de reproducción
|
|
2414
|
+
* al principio.
|
|
2415
|
+
*
|
|
2416
|
+
* Elimina todas las instancias de reproducción.
|
|
2417
|
+
*/
|
|
2418
|
+
detener(): void;
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
// 📑 dom
|
|
2422
|
+
|
|
2423
|
+
/**
|
|
2424
|
+
* El Modelo de Objetos del Documento (DOM) es una interfaz para
|
|
2425
|
+
* crear y editar páginas web con JavaScript.
|
|
2426
|
+
*/
|
|
2427
|
+
|
|
2428
|
+
/** 📑
|
|
2429
|
+
* Crea un nuevo elemento HTML y lo añade a la página. `createEl` es
|
|
2430
|
+
* un alias.
|
|
2431
|
+
*
|
|
2432
|
+
* Modifica el [`style`](https://developer.mozilla.org/docs/Web/API/HTMLElement/style) CSS del elemento para cambiar su apariencia.
|
|
2433
|
+
*
|
|
2434
|
+
* Usa [`addEventListener`](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) para responder a eventos como:
|
|
2435
|
+
*
|
|
2436
|
+
* - "click": cuando se hace clic en el elemento
|
|
2437
|
+
* - "mouseover": cuando el ratón pasa sobre el elemento
|
|
2438
|
+
* - "mouseout": cuando el ratón deja de pasar sobre el elemento
|
|
2439
|
+
* - "input": cuando el valor de un elemento de formulario cambia
|
|
2440
|
+
*
|
|
2441
|
+
* q5 añade alguna funcionalidad extra a los elementos que crea:
|
|
2442
|
+
*
|
|
2443
|
+
* - la función `position` facilita colocar el elemento
|
|
2444
|
+
* relativo al lienzo
|
|
2445
|
+
* - la función `size` establece el ancho y alto del elemento
|
|
2446
|
+
* - alternativamente, usa las propiedades `x`, `y`, `width`, y `height` del elemento
|
|
2447
|
+
* @param {string} etiqueta nombre de la etiqueta del elemento
|
|
2448
|
+
* @param {string} [contenido] contenido del elemento
|
|
2449
|
+
* @returns {HTMLElement} elemento
|
|
2450
|
+
* @example
|
|
2451
|
+
* await crearLienzo(200);
|
|
2452
|
+
*
|
|
2453
|
+
* let el = crearElemento('div', '*');
|
|
2454
|
+
* el.position(50, 50);
|
|
2455
|
+
* el.size(100, 100);
|
|
2456
|
+
* el.style.fontSize = '136px';
|
|
2457
|
+
* el.style.textAlign = 'center';
|
|
2458
|
+
* el.style.backgroundColor = 'blue';
|
|
2459
|
+
* el.style.color = 'white';
|
|
2460
|
+
*/
|
|
2461
|
+
function crearElemento(etiqueta: string, contenido?: string): HTMLElement;
|
|
2462
|
+
|
|
2463
|
+
/** 📑
|
|
2464
|
+
* Crea un elemento de enlace.
|
|
2465
|
+
* @param {string} href url
|
|
2466
|
+
* @param {string} [texto] contenido de texto
|
|
2467
|
+
* @param {boolean} [nuevaPestaña] si abrir el enlace en una nueva pestaña
|
|
2468
|
+
* @example
|
|
2469
|
+
* await crearLienzo(200);
|
|
2470
|
+
*
|
|
2471
|
+
* let enlace = crearA('https://q5js.org', 'q5.js');
|
|
2472
|
+
* enlace.position(16, 42);
|
|
2473
|
+
* enlace.style.fontSize = '80px';
|
|
2474
|
+
*
|
|
2475
|
+
* enlace.addEventListener('mouseover', () => {
|
|
2476
|
+
* fondo('cyan');
|
|
2477
|
+
* });
|
|
2478
|
+
*/
|
|
2479
|
+
function crearA(href: string, texto?: string): HTMLAnchorElement;
|
|
2480
|
+
|
|
2481
|
+
/** 📑
|
|
2482
|
+
* Crea un elemento de botón.
|
|
2483
|
+
* @param {string} [contenido] contenido de texto
|
|
2484
|
+
* @example
|
|
2485
|
+
* await crearLienzo(200, 100);
|
|
2486
|
+
*
|
|
2487
|
+
* let btn = crearBotón('Click me!');
|
|
2488
|
+
*
|
|
2489
|
+
* btn.addEventListener('click', () => {
|
|
2490
|
+
* fondo(aleatorio(0.4, 1));
|
|
2491
|
+
* });
|
|
2492
|
+
*/
|
|
2493
|
+
function crearBotón(): void;
|
|
2494
|
+
|
|
2495
|
+
/** 📑
|
|
2496
|
+
* Crea un elemento de casilla de verificación (checkbox).
|
|
2497
|
+
*
|
|
2498
|
+
* Usa la propiedad `checked` para obtener o establecer el estado de la casilla.
|
|
2499
|
+
*
|
|
2500
|
+
* La propiedad `label` es el elemento de etiqueta de texto junto a la casilla.
|
|
2501
|
+
* @param {string} [etiqueta] etiqueta de texto colocada junto a la casilla
|
|
2502
|
+
* @param {boolean} [marcado] estado inicial
|
|
2503
|
+
* @example
|
|
2504
|
+
* await crearLienzo(200, 100);
|
|
2505
|
+
*
|
|
2506
|
+
* let casilla = crearCasilla('Check me!');
|
|
2507
|
+
* casilla.label.style.color = 'lime';
|
|
2508
|
+
*
|
|
2509
|
+
* casilla.addEventListener('input', () => {
|
|
2510
|
+
* if (casilla.checked) fondo('lime');
|
|
2511
|
+
* else fondo('black');
|
|
2512
|
+
* });
|
|
2513
|
+
*/
|
|
2514
|
+
function crearCasilla(etiqueta?: string, marcado?: boolean): HTMLInputElement;
|
|
2515
|
+
|
|
2516
|
+
/** 📑
|
|
2517
|
+
* Crea un elemento de entrada de color.
|
|
2518
|
+
*
|
|
2519
|
+
* Usa la propiedad `value` para obtener o establecer el valor del color.
|
|
2520
|
+
* @param {string} [valor] valor de color inicial
|
|
2521
|
+
* @example
|
|
2522
|
+
* await crearLienzo(200, 100);
|
|
2523
|
+
*
|
|
2524
|
+
* let selector = crearSelectorColor();
|
|
2525
|
+
* selector.value = '#fd7575';
|
|
2526
|
+
*
|
|
2527
|
+
* q5.dibujar = function () {
|
|
2528
|
+
* fondo(selector.value);
|
|
2529
|
+
* };
|
|
2530
|
+
*/
|
|
2531
|
+
function crearSelectorColor(valor?: string): HTMLInputElement;
|
|
2532
|
+
|
|
2533
|
+
/** 📑
|
|
2534
|
+
* Crea un elemento de imagen.
|
|
2535
|
+
* @param {string} src url de la imagen
|
|
2536
|
+
* @example
|
|
2537
|
+
* await crearLienzo(200, 100);
|
|
2538
|
+
*
|
|
2539
|
+
* let img = crearImg('/assets/p5play_logo.webp');
|
|
2540
|
+
* img.position(0, 0).size(100, 100);
|
|
2541
|
+
*/
|
|
2542
|
+
function crearImg(src: string): HTMLImageElement;
|
|
2543
|
+
|
|
2544
|
+
/** 📑
|
|
2545
|
+
* Crea un elemento de entrada (input).
|
|
2546
|
+
*
|
|
2547
|
+
* Usa la propiedad `value` para obtener o establecer el valor de la entrada.
|
|
2548
|
+
*
|
|
2549
|
+
* Usa la propiedad `placeholder` para establecer el texto de etiqueta que aparece
|
|
2550
|
+
* dentro de la entrada cuando está vacía.
|
|
2551
|
+
*
|
|
2552
|
+
* Mira la [documentación de input](https://developer.mozilla.org/docs/Web/HTML/Element/input#input_types) de MDN para la lista completa de tipos de entrada.
|
|
2553
|
+
* @param {string} [valor] valor inicial
|
|
2554
|
+
* @param {string} [tipo] tipo de entrada de texto, puede ser 'text', 'password', 'email', 'number', 'range', 'search', 'tel', 'url'
|
|
2555
|
+
* @example
|
|
2556
|
+
* await crearLienzo(200, 100);
|
|
2557
|
+
* tamañoTexto(64);
|
|
2558
|
+
*
|
|
2559
|
+
* let entrada = crearEntrada();
|
|
2560
|
+
* entrada.placeholder = 'Type here!';
|
|
2561
|
+
* entrada.size(200, 32);
|
|
2562
|
+
*
|
|
2563
|
+
* entrada.addEventListener('input', () => {
|
|
2564
|
+
* fondo('orange');
|
|
2565
|
+
* texto(entrada.value, -90, 30);
|
|
2566
|
+
* });
|
|
2567
|
+
*/
|
|
2568
|
+
function crearEntrada(valor?: string, tipo?: string): HTMLInputElement;
|
|
2569
|
+
|
|
2570
|
+
/** 📑
|
|
2571
|
+
* Crea un elemento de párrafo.
|
|
2572
|
+
* @param {string} [contenido] contenido de texto
|
|
2573
|
+
* @example
|
|
2574
|
+
* await crearLienzo(200, 50);
|
|
2575
|
+
* fondo('coral');
|
|
2576
|
+
*
|
|
2577
|
+
* let p = crearP('Hello, world!');
|
|
2578
|
+
* p.style.color = 'pink';
|
|
2579
|
+
*/
|
|
2580
|
+
function crearP(contenido?: string): HTMLParagraphElement;
|
|
2581
|
+
|
|
2582
|
+
/** 📑
|
|
2583
|
+
* Crea un grupo de botones de radio.
|
|
2584
|
+
*
|
|
2585
|
+
* Usa la función `option(etiqueta, valor)` para añadir nuevos botones de radio
|
|
2586
|
+
* al grupo.
|
|
2587
|
+
*
|
|
2588
|
+
* Usa la propiedad `value` para obtener o establecer el valor del botón de radio seleccionado.
|
|
2589
|
+
* @param {string} [nombreGrupo]
|
|
2590
|
+
* @example
|
|
2591
|
+
* await crearLienzo(200, 160);
|
|
2592
|
+
*
|
|
2593
|
+
* let radio = crearOpciónes();
|
|
2594
|
+
* radio.option('square', '1').option('circle', '2');
|
|
2595
|
+
*
|
|
2596
|
+
* q5.dibujar = function () {
|
|
2597
|
+
* fondo(0.8);
|
|
2598
|
+
* if (radio.value == '1') cuadrado(-40, -40, 80);
|
|
2599
|
+
* if (radio.value == '2') círculo(0, 0, 80);
|
|
2600
|
+
* };
|
|
2601
|
+
*/
|
|
2602
|
+
function crearOpciónes(): void;
|
|
2603
|
+
|
|
2604
|
+
/** 📑
|
|
2605
|
+
* Crea un elemento de selección (select).
|
|
2606
|
+
*
|
|
2607
|
+
* Usa la función `option(etiqueta, valor)` para añadir nuevas opciones al
|
|
2608
|
+
* elemento de selección.
|
|
2609
|
+
*
|
|
2610
|
+
* Establece `multiple` a `true` para permitir seleccionar múltiples opciones.
|
|
2611
|
+
*
|
|
2612
|
+
* Usa la propiedad `value` para obtener o establecer el valor de la opción seleccionada.
|
|
2613
|
+
*
|
|
2614
|
+
* Usa la propiedad `selected` para obtener las etiquetas de las opciones
|
|
2615
|
+
* seleccionadas o establecer las opciones seleccionadas por etiqueta. Puede ser una sola
|
|
2616
|
+
* cadena o un array de cadenas.
|
|
2617
|
+
* @param {string} [placeholder] texto opcional que aparece antes de que se seleccione una opción
|
|
2618
|
+
* @example
|
|
2619
|
+
* await crearLienzo(200, 100);
|
|
2620
|
+
*
|
|
2621
|
+
* let sel = crearSelección('Select a color');
|
|
2622
|
+
* sel.option('Red', '#f55').option('Green', '#5f5');
|
|
2623
|
+
*
|
|
2624
|
+
* sel.addEventListener('change', () => {
|
|
2625
|
+
* fondo(sel.value);
|
|
2626
|
+
* });
|
|
2627
|
+
*/
|
|
2628
|
+
function crearSelección(): void;
|
|
2629
|
+
|
|
2630
|
+
/** 📑
|
|
2631
|
+
* Crea un elemento deslizador (slider).
|
|
2632
|
+
*
|
|
2633
|
+
* Usa la propiedad `value` para obtener o establecer el valor del deslizador.
|
|
2634
|
+
*
|
|
2635
|
+
* Usa la función `val` para obtener el valor del deslizador como un número.
|
|
2636
|
+
* @param {number} min valor mínimo
|
|
2637
|
+
* @param {number} max valor máximo
|
|
2638
|
+
* @param {number} [valor] valor inicial
|
|
2639
|
+
* @param {number} [paso] tamaño del paso
|
|
2640
|
+
* @example
|
|
2641
|
+
* await crearLienzo(200);
|
|
2642
|
+
*
|
|
2643
|
+
* let deslizador = crearDeslizador(0, 1, 0.5, 0.1);
|
|
2644
|
+
* deslizador.position(10, 10).size(180);
|
|
2645
|
+
*
|
|
2646
|
+
* q5.dibujar = function () {
|
|
2647
|
+
* fondo(deslizador.val());
|
|
2648
|
+
* };
|
|
2649
|
+
*/
|
|
2650
|
+
function crearDeslizador(min: number, max: number, valor?: number, paso?: number): HTMLInputElement;
|
|
2651
|
+
|
|
2652
|
+
/** 📑
|
|
2653
|
+
* Crea un elemento de video.
|
|
2654
|
+
*
|
|
2655
|
+
* Ten en cuenta que los videos deben estar silenciados para reproducirse automáticamente y las funciones `play` y
|
|
2656
|
+
* `pause` solo pueden ejecutarse después de una interacción del usuario.
|
|
2657
|
+
*
|
|
2658
|
+
* El elemento de video puede ocultarse y su contenido puede
|
|
2659
|
+
* mostrarse en el lienzo usando la función `imagen`.
|
|
2660
|
+
* @param {string} src url del video
|
|
2661
|
+
* @returns {HTMLVideoElement & PromiseLike<HTMLVideoElement>} un nuevo elemento de video
|
|
2662
|
+
* @example
|
|
2663
|
+
* await crearLienzo(1);
|
|
2664
|
+
*
|
|
2665
|
+
* let vid = crearVideo('/assets/apollo4.mp4');
|
|
2666
|
+
* vid.size(200, 150);
|
|
2667
|
+
* vid.autoplay = vid.muted = vid.loop = true;
|
|
2668
|
+
* vid.controls = true;
|
|
2669
|
+
* @example
|
|
2670
|
+
* await crearLienzo(200, 150);
|
|
2671
|
+
* let vid = crearVideo('/assets/apollo4.mp4');
|
|
2672
|
+
* vid.hide();
|
|
2673
|
+
*
|
|
2674
|
+
* q5.alPresionarRatón = function () {
|
|
2675
|
+
* vid.currentTime = 0;
|
|
2676
|
+
* vid.play();
|
|
2677
|
+
* };
|
|
2678
|
+
* q5.dibujar = function () {
|
|
2679
|
+
* imagen(vid, -100, -75, 200, 150);
|
|
2680
|
+
* // filtro(HUE_ROTATE, 90);
|
|
2681
|
+
* };
|
|
2682
|
+
*/
|
|
2683
|
+
function crearVideo(src: string): HTMLVideoElement & PromiseLike<HTMLVideoElement>;
|
|
2684
|
+
|
|
2685
|
+
/** 📑
|
|
2686
|
+
* Crea una captura desde una cámara conectada, como una webcam.
|
|
2687
|
+
*
|
|
2688
|
+
* El elemento de video de captura puede ocultarse y su contenido puede
|
|
2689
|
+
* mostrarse en el lienzo usando la función `imagen`.
|
|
2690
|
+
*
|
|
2691
|
+
* Puede precargarse para asegurar que la captura esté lista para usar cuando tu
|
|
2692
|
+
* sketch comience.
|
|
2693
|
+
*
|
|
2694
|
+
* Solicita la resolución de video más alta de la cámara frontal del usuario
|
|
2695
|
+
* por defecto. El primer parámetro de esta función se puede usar para
|
|
2696
|
+
* especificar las restricciones para la captura. Mira [`getUserMedia`](https://developer.mozilla.org/docs/Web/API/MediaDevices/getUserMedia)
|
|
2697
|
+
* para más información.
|
|
2698
|
+
* @param {string} [tipo] tipo de captura, puede ser solo `VIDEO` o solo `AUDIO`, el defecto es usar ambos video y audio
|
|
2699
|
+
* @param {boolean} [volteado] si reflejar el video verticalmente, true por defecto
|
|
2700
|
+
* @returns {HTMLVideoElement & PromiseLike<HTMLVideoElement>} un nuevo elemento de video
|
|
2701
|
+
* @example
|
|
2702
|
+
* q5.alPresionarRatón = function () {
|
|
2703
|
+
* let cap = crearCaptura(VIDEO);
|
|
2704
|
+
* cap.size(200, 112.5);
|
|
2705
|
+
* canvas.remove();
|
|
2706
|
+
* };
|
|
2707
|
+
* @example
|
|
2708
|
+
* let cap;
|
|
2709
|
+
* q5.alPresionarRatón = function () {
|
|
2710
|
+
* cap = crearCaptura(VIDEO);
|
|
2711
|
+
* cap.hide();
|
|
2712
|
+
* };
|
|
2713
|
+
*
|
|
2714
|
+
* q5.dibujar = function () {
|
|
2715
|
+
* let y = (frameCount % 200) - 100;
|
|
2716
|
+
* imagen(cap, -100, y, 200, 200);
|
|
2717
|
+
* };
|
|
2718
|
+
* @example
|
|
2719
|
+
* q5.alPresionarRatón = function () {
|
|
2720
|
+
* let cap = crearCaptura({
|
|
2721
|
+
* video: { width: 640, height: 480 }
|
|
2722
|
+
* });
|
|
2723
|
+
* cap.size(200, 150);
|
|
2724
|
+
* canvas.remove();
|
|
2725
|
+
* };
|
|
2726
|
+
*/
|
|
2727
|
+
function crearCaptura(tipo?: string, volteado?: boolean): HTMLVideoElement & PromiseLike<HTMLVideoElement>;
|
|
2728
|
+
|
|
2729
|
+
/** 📑
|
|
2730
|
+
* Encuentra el primer elemento en el DOM que coincide con el [selector CSS](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors) dado.
|
|
2731
|
+
* @param {string} selector
|
|
2732
|
+
* @returns {HTMLElement} elemento
|
|
2733
|
+
*/
|
|
2734
|
+
function encontrarElemento(selector: string): HTMLElement;
|
|
2735
|
+
|
|
2736
|
+
/** 📑
|
|
2737
|
+
* Encuentra todos los elementos en el DOM que coinciden con el [selector CSS](https://developer.mozilla.org/docs/Learn_web_development/Core/Styling_basics/Basic_selectors) dado.
|
|
2738
|
+
* @param {string} selector
|
|
2739
|
+
* @returns {HTMLElement[]} elementos
|
|
2740
|
+
*/
|
|
2741
|
+
function encontrarElementos(selector: string): HTMLElement[];
|
|
2742
|
+
|
|
2743
|
+
// 🎞 record
|
|
2744
|
+
|
|
2745
|
+
/** 🎞
|
|
2746
|
+
* Crea una grabadora. ¡Simplemente presiona grabar para empezar a grabar!
|
|
2747
|
+
*
|
|
2748
|
+
* Las siguientes propiedades se pueden establecer a través de la UI de la grabadora o
|
|
2749
|
+
* programáticamente.
|
|
2750
|
+
*
|
|
2751
|
+
* - `format` se establece a "H.264" por defecto.
|
|
2752
|
+
* - `bitrate` es un número en megabits por segundo (mbps). Su valor por defecto
|
|
2753
|
+
* está determinado por la altura del lienzo. Aumentar la
|
|
2754
|
+
* tasa de bits aumentará la calidad y el tamaño del archivo de la grabación.
|
|
2755
|
+
* - `captureAudio` se establece a true por defecto. Establecer a false para deshabilitar
|
|
2756
|
+
* la grabación de audio.
|
|
2757
|
+
*
|
|
2758
|
+
* Ten en cuenta que las grabaciones se hacen a una tasa de fotogramas variable (VFR), lo que
|
|
2759
|
+
* hace que el video de salida sea incompatible con algún software de edición.
|
|
2760
|
+
* Para más información, mira la página wiki
|
|
2761
|
+
* ["Recording the Canvas"](https://github.com/q5js/q5.js/wiki/Recording-the-Canvas).
|
|
2762
|
+
* @returns {HTMLElement} una grabadora, elemento DOM de q5
|
|
2763
|
+
* @example
|
|
2764
|
+
* await crearLienzo(200);
|
|
2765
|
+
*
|
|
2766
|
+
* let grab = crearGrabadora();
|
|
2767
|
+
* grab.bitrate = 10;
|
|
2768
|
+
*
|
|
2769
|
+
* q5.dibujar = function () {
|
|
2770
|
+
* círculo(ratónX, flu(medioAlto), 10);
|
|
2771
|
+
* };
|
|
2772
|
+
*/
|
|
2773
|
+
function crearGrabadora(): HTMLElement;
|
|
2774
|
+
|
|
2775
|
+
/** 🎞
|
|
2776
|
+
* Comienza a grabar el lienzo o reanuda la grabación si estaba pausada.
|
|
2777
|
+
*
|
|
2778
|
+
* Si no existe grabadora, se crea una pero no se muestra.
|
|
2779
|
+
*/
|
|
2780
|
+
function grabar(): void;
|
|
2781
|
+
|
|
2782
|
+
/** 🎞
|
|
2783
|
+
* Pausa la grabación del lienzo, si hay una en progreso.
|
|
2784
|
+
*/
|
|
2785
|
+
function pausarGrabación(): void;
|
|
2786
|
+
|
|
2787
|
+
/** 🎞
|
|
2788
|
+
* Descarta la grabación actual.
|
|
2789
|
+
*/
|
|
2790
|
+
function borrarGrabación(): void;
|
|
2791
|
+
|
|
2792
|
+
/** 🎞
|
|
2793
|
+
* Guarda la grabación actual como un archivo de video.
|
|
2794
|
+
* @param {string} nombreArchivo
|
|
2795
|
+
* @example
|
|
2796
|
+
* q5.dibujar = function () {
|
|
2797
|
+
* cuadrado(ratónX, flu(100), 10);
|
|
2798
|
+
* };
|
|
2799
|
+
*
|
|
2800
|
+
* q5.alPresionarRatón = function () {
|
|
2801
|
+
* if (!grabando) grabar();
|
|
2802
|
+
* else guardarGrabación('squares');
|
|
2803
|
+
* };
|
|
2804
|
+
*/
|
|
2805
|
+
function guardarGrabación(): void;
|
|
2806
|
+
|
|
2807
|
+
/** 🎞
|
|
2808
|
+
* Verdadero si el lienzo está siendo grabado actualmente.
|
|
2809
|
+
*/
|
|
2810
|
+
var grabando: boolean;
|
|
2811
|
+
|
|
2812
|
+
// 🛠 utilities
|
|
2813
|
+
|
|
2814
|
+
/** 🛠
|
|
2815
|
+
* Carga un archivo o múltiples archivos.
|
|
2816
|
+
*
|
|
2817
|
+
* El tipo de archivo se determina por la extensión del archivo. q5 soporta cargar
|
|
2818
|
+
* archivos de texto, json, csv, fuente, audio, e imagen.
|
|
2819
|
+
*
|
|
2820
|
+
* Por defecto, los recursos se cargan en paralelo antes de que q5 ejecute `dibujar`. Usa `await` para esperar a que los recursos se carguen.
|
|
2821
|
+
* @param {...string} urls
|
|
2822
|
+
* @returns {Promise<any[]>} una promesa que se resuelve con objetos
|
|
2823
|
+
* @example
|
|
2824
|
+
* await crearLienzo(200);
|
|
2825
|
+
*
|
|
2826
|
+
* let logo = cargar('/q5js_logo.avif');
|
|
2827
|
+
*
|
|
2828
|
+
* q5.dibujar = function () {
|
|
2829
|
+
* imagen(logo, -100, -100, 200, 200);
|
|
2830
|
+
* };
|
|
2831
|
+
* @example
|
|
2832
|
+
* await crearLienzo(200);
|
|
2833
|
+
* fondo(0.8);
|
|
2834
|
+
*
|
|
2835
|
+
* await cargar('/assets/Robotica.ttf');
|
|
2836
|
+
*
|
|
2837
|
+
* tamañoTexto(28);
|
|
2838
|
+
* texto('Hello, world!', -97, 100);
|
|
2839
|
+
* @example
|
|
2840
|
+
* await crearLienzo(200);
|
|
2841
|
+
*
|
|
2842
|
+
* let [salto, retro] = await cargar('/assets/jump.wav', '/assets/retro.flac');
|
|
2843
|
+
*
|
|
2844
|
+
* q5.alPresionarRatón = function () {
|
|
2845
|
+
* botónRatón == 'left' ? salto.reproducir() : retro.reproducir();
|
|
2846
|
+
* };
|
|
2847
|
+
* @example
|
|
2848
|
+
* await crearLienzo(200);
|
|
2849
|
+
* fondo(0.8);
|
|
2850
|
+
* tamañoTexto(32);
|
|
2851
|
+
*
|
|
2852
|
+
* let miXML = await cargar('/assets/animals.xml');
|
|
2853
|
+
* let mamiferos = miXML.getElementsByTagName('mammal');
|
|
2854
|
+
* let y = -100;
|
|
2855
|
+
* for (let mamifero of mamiferos) {
|
|
2856
|
+
* texto(mamifero.textContent, -100, (y += 32));
|
|
2857
|
+
* }
|
|
2858
|
+
*/
|
|
2859
|
+
function cargar(...urls: string[]): PromiseLike<any[]>;
|
|
2860
|
+
|
|
2861
|
+
/** 🛠
|
|
2862
|
+
* Guarda datos en un archivo.
|
|
2863
|
+
*
|
|
2864
|
+
* Si no se especifican datos, se guardará el lienzo.
|
|
2865
|
+
*
|
|
2866
|
+
* Si no se proporcionan argumentos, el lienzo se guardará como
|
|
2867
|
+
* un archivo de imagen llamado "untitled.png".
|
|
2868
|
+
* @param {object} [datos] lienzo, imagen, u objeto JS
|
|
2869
|
+
* @param {string} [nombreArchivo] nombre de archivo para guardar como
|
|
2870
|
+
* @example
|
|
2871
|
+
* await crearLienzo(200);
|
|
2872
|
+
* fondo(0.8);
|
|
2873
|
+
* círculo(0, 0, 50);
|
|
2874
|
+
*
|
|
2875
|
+
* q5.alPresionarRatón = function () {
|
|
2876
|
+
* guardar('circle.png');
|
|
2877
|
+
* };
|
|
2878
|
+
* @example
|
|
2879
|
+
* await crearLienzo(200);
|
|
2880
|
+
* fondo(0.8);
|
|
2881
|
+
* texto('save me?', -90, 0);
|
|
2882
|
+
* tamañoTexto(180);
|
|
2883
|
+
* let rayo = crearImagenTexto('⚡️');
|
|
2884
|
+
*
|
|
2885
|
+
* q5.alPresionarRatón = function () {
|
|
2886
|
+
* guardar(rayo, 'bolt.png');
|
|
2887
|
+
* };
|
|
2888
|
+
*/
|
|
2889
|
+
function guardar(datos?: object, nombreArchivo?: string): void;
|
|
2890
|
+
|
|
2891
|
+
/** 🛠
|
|
2892
|
+
* Carga un archivo de texto desde la url especificada.
|
|
2893
|
+
*
|
|
2894
|
+
* Se recomienda usar `await` para obtener el texto cargado como una cadena.
|
|
2895
|
+
* @param {string} url archivo de texto
|
|
2896
|
+
* @returns {object & PromiseLike<string>} un objeto conteniendo el texto cargado en la propiedad `obj.text` o usa `await` para obtener la cadena de texto directamente
|
|
2897
|
+
*/
|
|
2898
|
+
function cargarTexto(url: string): object & PromiseLike<string>;
|
|
2899
|
+
|
|
2900
|
+
/** 🛠
|
|
2901
|
+
* Carga un archivo JSON desde la url especificada.
|
|
2902
|
+
*
|
|
2903
|
+
* Se recomienda usar `await` para obtener el objeto o array JSON cargado.
|
|
2904
|
+
* @param {string} url archivo JSON
|
|
2905
|
+
* @returns {any & PromiseLike<any>} un objeto o array conteniendo el JSON cargado
|
|
2906
|
+
*/
|
|
2907
|
+
function cargarJSON(url: string): any & PromiseLike<any>;
|
|
2908
|
+
|
|
2909
|
+
/** 🛠
|
|
2910
|
+
* Carga un archivo CSV desde la url especificada.
|
|
2911
|
+
*
|
|
2912
|
+
* Se recomienda usar `await` para obtener el CSV cargado como un array de objetos.
|
|
2913
|
+
* @param {string} url archivo CSV
|
|
2914
|
+
* @returns {object[] & PromiseLike<object[]>} un array de objetos conteniendo el CSV cargado
|
|
2915
|
+
*/
|
|
2916
|
+
function cargarCSV(url: string): object[] & PromiseLike<object[]>;
|
|
2917
|
+
|
|
2918
|
+
/** 🛠
|
|
2919
|
+
* Carga un archivo xml desde la url especificada.
|
|
2920
|
+
*
|
|
2921
|
+
* Se recomienda usar `await` para obtener el Elemento XML cargado.
|
|
2922
|
+
* @param {string} url archivo xml
|
|
2923
|
+
* @returns {Element & PromiseLike<Element>} un objeto conteniendo el Elemento XML cargado en una propiedad llamada `obj.DOM` o usa await para obtener el Elemento XML directamente
|
|
2924
|
+
* @example
|
|
2925
|
+
* await crearLienzo(200);
|
|
2926
|
+
* fondo(200);
|
|
2927
|
+
* tamañoTexto(32);
|
|
2928
|
+
*
|
|
2929
|
+
* let animales = await cargarXML('/assets/animals.xml');
|
|
2930
|
+
*
|
|
2931
|
+
* let mamiferos = animales.getElementsByTagName('mammal');
|
|
2932
|
+
* let y = 64;
|
|
2933
|
+
* for (let mamifero of mamiferos) {
|
|
2934
|
+
* texto(mamifero.textContent, 20, (y += 32));
|
|
2935
|
+
* }
|
|
2936
|
+
*/
|
|
2937
|
+
function cargarXML(url: string): object & PromiseLike<Element>;
|
|
2938
|
+
|
|
2939
|
+
/** 🛠
|
|
2940
|
+
* Espera a que cualquier recurso que comenzó a cargarse termine de cargarse. Por defecto q5 ejecuta esto antes de hacer bucle en dibujar (lo cual se llama precarga), pero se puede usar incluso después de que dibujar comience a hacer bucle.
|
|
2941
|
+
* @returns {PromiseLike<any[]>} una promesa que se resuelve con objetos cargados
|
|
2942
|
+
*/
|
|
2943
|
+
function cargarTodo(): PromiseLike<any[]>;
|
|
2944
|
+
|
|
2945
|
+
/** 🛠
|
|
2946
|
+
* Deshabilita la precarga automática de recursos antes de que dibujar comience a hacer bucle. Esto permite que dibujar comience inmediatamente, y los recursos se pueden cargar perezosamente o se puede usar `cargarTodo()` para esperar a que los recursos terminen de cargarse más tarde.
|
|
2947
|
+
*/
|
|
2948
|
+
function deshabilitarPrecarga(): void;
|
|
2949
|
+
|
|
2950
|
+
/** 🛠
|
|
2951
|
+
* nf es la abreviatura de formato de número. Formatea un número
|
|
2952
|
+
* a una cadena con un número especificado de dígitos.
|
|
2953
|
+
* @param {number} num número a formatear
|
|
2954
|
+
* @param {number} digitos número de dígitos a formatear
|
|
2955
|
+
* @returns {string} número formateado
|
|
2956
|
+
* @example
|
|
2957
|
+
* await crearLienzo(200, 100);
|
|
2958
|
+
* fondo(0.8);
|
|
2959
|
+
*
|
|
2960
|
+
* tamañoTexto(32);
|
|
2961
|
+
* texto(nf(PI, 4, 5), -90, 10);
|
|
2962
|
+
*/
|
|
2963
|
+
function nf(num: number, digitos: number): string;
|
|
2964
|
+
|
|
2965
|
+
/** 🛠
|
|
2966
|
+
* Baraja los elementos de un array.
|
|
2967
|
+
* @param {any[]} arr array a barajar
|
|
2968
|
+
* @param {boolean} [modificar] si modificar el array original, falso por defecto lo cual copia el array antes de barajar
|
|
2969
|
+
* @returns {any[]} array barajado
|
|
2970
|
+
*/
|
|
2971
|
+
function barajar(arr: any[]): any[];
|
|
2972
|
+
|
|
2973
|
+
/** 🛠
|
|
2974
|
+
* Almacena un ítem en localStorage.
|
|
2975
|
+
* @param {string} clave clave bajo la cual almacenar el ítem
|
|
2976
|
+
* @param {string} val valor a almacenar
|
|
2977
|
+
*/
|
|
2978
|
+
function guardarItem(clave: string, val: string): void;
|
|
2979
|
+
|
|
2980
|
+
/** 🛠
|
|
2981
|
+
* Recupera un ítem de localStorage.
|
|
2982
|
+
* @param {string} clave clave del ítem a recuperar
|
|
2983
|
+
* @returns {string} valor del ítem recuperado
|
|
2984
|
+
*/
|
|
2985
|
+
function obtenerItem(clave: string): string;
|
|
2986
|
+
|
|
2987
|
+
/** 🛠
|
|
2988
|
+
* Elimina un ítem de localStorage.
|
|
2989
|
+
* @param {string} clave clave del ítem a eliminar
|
|
2990
|
+
*/
|
|
2991
|
+
function eliminarItem(clave: string): void;
|
|
2992
|
+
|
|
2993
|
+
/** 🛠
|
|
2994
|
+
* Limpia todos los ítems de localStorage.
|
|
2995
|
+
*/
|
|
2996
|
+
function limpiarAlmacenamiento(): void;
|
|
2997
|
+
|
|
2998
|
+
/** 🛠
|
|
2999
|
+
* Devuelve el año actual.
|
|
3000
|
+
* @returns {number} año actual
|
|
3001
|
+
*/
|
|
3002
|
+
function año(): void;
|
|
3003
|
+
|
|
3004
|
+
/** 🛠
|
|
3005
|
+
* Devuelve el día actual del mes.
|
|
3006
|
+
* @returns {number} día actual
|
|
3007
|
+
*/
|
|
3008
|
+
function día(): void;
|
|
3009
|
+
|
|
3010
|
+
/** 🛠
|
|
3011
|
+
* Devuelve la hora actual.
|
|
3012
|
+
* @returns {number} hora actual
|
|
3013
|
+
*/
|
|
3014
|
+
function hora(): number;
|
|
3015
|
+
|
|
3016
|
+
/** 🛠
|
|
3017
|
+
* Devuelve el minuto actual.
|
|
3018
|
+
* @returns {number} minuto actual
|
|
3019
|
+
*/
|
|
3020
|
+
function minuto(): number;
|
|
3021
|
+
|
|
3022
|
+
/** 🛠
|
|
3023
|
+
* Devuelve el segundo actual.
|
|
3024
|
+
* @returns {number} segundo actual
|
|
3025
|
+
*/
|
|
3026
|
+
function segundo(): number;
|
|
3027
|
+
|
|
3028
|
+
// ↗ vector
|
|
3029
|
+
|
|
3030
|
+
/** ↗
|
|
3031
|
+
* Crea un nuevo objeto Vector.
|
|
3032
|
+
* @param {number} [x] componente x del vector
|
|
3033
|
+
* @param {number} [y] componente y del vector
|
|
3034
|
+
* @param {number} [z] componente z del vector
|
|
3035
|
+
* @param {number} [w] componente w del vector
|
|
3036
|
+
* @returns {Vector} nuevo objeto Vector
|
|
3037
|
+
* @example
|
|
3038
|
+
* await crearLienzo(200);
|
|
3039
|
+
* fondo(0.8);
|
|
3040
|
+
*
|
|
3041
|
+
* let v = crearVector(100, 100);
|
|
3042
|
+
* círculo(v.x, v.y, 50);
|
|
3043
|
+
*/
|
|
3044
|
+
function crearVector(): void;
|
|
3045
|
+
|
|
3046
|
+
/** ↗
|
|
3047
|
+
* Una clase para describir un vector bidimensional o tridimensional, específicamente un vector euclidiano (también conocido como geométrico). Un vector es una entidad que tiene tanto magnitud como dirección. El tipo de datos almacena los componentes del vector (x, y para 2D, y z para 3D). La magnitud y dirección se pueden acceder a través de los métodos `mag()` y `heading()`.
|
|
3048
|
+
* @param {number} [x] componente x del vector
|
|
3049
|
+
* @param {number} [y] componente y del vector
|
|
3050
|
+
* @param {number} [z] componente z del vector
|
|
3051
|
+
* @param {number} [w] componente w del vector
|
|
3052
|
+
* @returns {Vector} este vector
|
|
3053
|
+
* @returns {Vector} copia del vector
|
|
3054
|
+
* @param {number | Vector} x componente x del vector o Vector a sumar
|
|
3055
|
+
* @param {number} [y] componente y del vector
|
|
3056
|
+
* @param {number} [z] componente z del vector
|
|
3057
|
+
* @returns {Vector} este vector
|
|
3058
|
+
* @param {number | Vector} x componente x del vector o Vector a restar
|
|
3059
|
+
* @param {number} [y] componente y del vector
|
|
3060
|
+
* @param {number} [z] componente z del vector
|
|
3061
|
+
* @returns {Vector} este vector
|
|
3062
|
+
* @param {number} n escalar por el cual multiplicar
|
|
3063
|
+
* @returns {Vector} este vector
|
|
3064
|
+
* @param {number} n escalar por el cual dividir
|
|
3065
|
+
* @returns {Vector} este vector
|
|
3066
|
+
* @returns {number} magnitud del vector
|
|
3067
|
+
* @returns {number} magnitud del vector al cuadrado
|
|
3068
|
+
* @param {Vector} v vector con el cual hacer producto punto
|
|
3069
|
+
* @returns {number} producto punto
|
|
3070
|
+
* @param {Vector} v vector con el cual hacer producto cruz
|
|
3071
|
+
* @returns {Vector} producto cruz
|
|
3072
|
+
* @param {Vector} v vector al cual calcular distancia
|
|
3073
|
+
* @returns {number} distancia
|
|
3074
|
+
* @returns {Vector} este vector
|
|
3075
|
+
* @param {number} max magnitud máxima
|
|
3076
|
+
* @returns {Vector} este vector
|
|
3077
|
+
* @param {number} len nueva longitud para este vector
|
|
3078
|
+
* @returns {Vector} este vector
|
|
3079
|
+
* @returns {number} el ángulo de rotación
|
|
3080
|
+
* @param {number} ángulo ángulo de rotación
|
|
3081
|
+
* @returns {Vector} este vector
|
|
3082
|
+
* @param {Vector} v el vector x, y, z
|
|
3083
|
+
* @returns {number} el ángulo entre
|
|
3084
|
+
* @param {Vector} v el vector x, y, z
|
|
3085
|
+
* @param {number} amt la cantidad de interpolación; 0.0 es el vector antiguo, 1.0 es el nuevo vector, 0.5 está a mitad de camino
|
|
3086
|
+
* @returns {Vector} este vector
|
|
3087
|
+
* @param {Vector} superficieNormal el vector normal a la superficie
|
|
3088
|
+
* @returns {Vector} este vector
|
|
3089
|
+
* @returns {number[]} array de flotantes
|
|
3090
|
+
* @param {Vector} v el vector a comparar
|
|
3091
|
+
* @returns {boolean} verdadero si los vectores son iguales
|
|
3092
|
+
* @param {number} ángulo el ángulo deseado
|
|
3093
|
+
* @param {number} [longitud] longitud del nuevo vector (por defecto a 1)
|
|
3094
|
+
* @returns {Vector} nuevo objeto Vector
|
|
3095
|
+
* @returns {Vector} nuevo objeto Vector
|
|
3096
|
+
* @returns {Vector} nuevo objeto Vector
|
|
3097
|
+
*/
|
|
3098
|
+
class Vector {
|
|
3099
|
+
|
|
3100
|
+
// 🖌 shaping
|
|
3101
|
+
|
|
3102
|
+
/** 🖌
|
|
3103
|
+
* Dibuja un arco, que es una sección de una elipse.
|
|
3104
|
+
*
|
|
3105
|
+
* `modoEliptico` afecta cómo se dibuja el arco.
|
|
3106
|
+
*
|
|
3107
|
+
* q5 WebGPU solo soporta el modo por defecto `PIE_OPEN`.
|
|
3108
|
+
* @param {number} x coordenada-x
|
|
3109
|
+
* @param {number} y coordenada-y
|
|
3110
|
+
* @param {number} w ancho de la elipse
|
|
3111
|
+
* @param {number} h alto de la elipse
|
|
3112
|
+
* @param {number} inicio ángulo para empezar el arco
|
|
3113
|
+
* @param {number} fin ángulo para terminar el arco
|
|
3114
|
+
* @param {number} [modo] configuración de estilo de forma y trazo, por defecto es `PIE_OPEN` para una forma de pastel con un trazo no cerrado, puede ser `PIE`, `CHORD`, o `CHORD_OPEN`
|
|
3115
|
+
* @example
|
|
3116
|
+
* await crearLienzo(200);
|
|
3117
|
+
* fondo(0.8);
|
|
3118
|
+
*
|
|
3119
|
+
* arco(0, 0, 160, 160, 0.8, -0.8);
|
|
3120
|
+
*/
|
|
3121
|
+
function arco(x: number, y: number, w: number, h: number, inicio: number, fin: number, modo?: number): void;
|
|
3122
|
+
|
|
3123
|
+
/** 🖌
|
|
3124
|
+
* Dibuja una curva.
|
|
3125
|
+
* @example
|
|
3126
|
+
* await crearLienzo(200, 100);
|
|
3127
|
+
* fondo(0.8);
|
|
3128
|
+
*
|
|
3129
|
+
* curva(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
3130
|
+
*/
|
|
3131
|
+
function curva(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
3132
|
+
|
|
3133
|
+
/** 🖌
|
|
3134
|
+
* Establece la cantidad de segmentos de línea recta usados para hacer una curva.
|
|
3135
|
+
*
|
|
3136
|
+
* Solo tiene efecto en q5 WebGPU.
|
|
3137
|
+
* @param {number} val nivel de detalle de la curva, por defecto es 20
|
|
3138
|
+
* @example
|
|
3139
|
+
* await crearLienzo(200);
|
|
3140
|
+
*
|
|
3141
|
+
* detalleCurva(4);
|
|
3142
|
+
*
|
|
3143
|
+
* grosorTrazo(10);
|
|
3144
|
+
* trazo(0, 1, 1);
|
|
3145
|
+
* curva(-100, -200, -50, 0, 50, 0, 100, -200);
|
|
3146
|
+
*/
|
|
3147
|
+
function detalleCurva(val: number): void;
|
|
3148
|
+
|
|
3149
|
+
/** 🖌
|
|
3150
|
+
* Comienza a almacenar vértices para una forma convexa.
|
|
3151
|
+
*/
|
|
3152
|
+
function empezarForma(): void;
|
|
3153
|
+
|
|
3154
|
+
/** 🖌
|
|
3155
|
+
* Termina de almacenar vértices para una forma convexa.
|
|
3156
|
+
*/
|
|
3157
|
+
function terminarForma(): void;
|
|
3158
|
+
|
|
3159
|
+
/** 🖌
|
|
3160
|
+
* Comienza a almacenar vértices para un contorno.
|
|
3161
|
+
*
|
|
3162
|
+
* No disponible en q5 WebGPU.
|
|
3163
|
+
*/
|
|
3164
|
+
function empezarContorno(): void;
|
|
3165
|
+
|
|
3166
|
+
/** 🖌
|
|
3167
|
+
* Termina de almacenar vértices para un contorno.
|
|
3168
|
+
*
|
|
3169
|
+
* No disponible en q5 WebGPU.
|
|
3170
|
+
*/
|
|
3171
|
+
function terminarContorno(): void;
|
|
3172
|
+
|
|
3173
|
+
/** 🖌
|
|
3174
|
+
* Especifica un vértice en una forma.
|
|
3175
|
+
* @param {number} x coordenada-x
|
|
3176
|
+
* @param {number} y coordenada-y
|
|
3177
|
+
*/
|
|
3178
|
+
function vértice(): void;
|
|
3179
|
+
|
|
3180
|
+
/** 🖌
|
|
3181
|
+
* Especifica un vértice Bezier en una forma.
|
|
3182
|
+
* @param {number} cp1x coordenada-x del primer punto de control
|
|
3183
|
+
* @param {number} cp1y coordenada-y del primer punto de control
|
|
3184
|
+
* @param {number} cp2x coordenada-x del segundo punto de control
|
|
3185
|
+
* @param {number} cp2y coordenada-y del segundo punto de control
|
|
3186
|
+
* @param {number} x coordenada-x del punto de anclaje
|
|
3187
|
+
* @param {number} y coordenada-y del punto de anclaje
|
|
3188
|
+
*/
|
|
3189
|
+
function vérticeBezier(): void;
|
|
3190
|
+
|
|
3191
|
+
/** 🖌
|
|
3192
|
+
* Especifica un vértice Bezier cuadrático en una forma.
|
|
3193
|
+
* @param {number} cp1x coordenada-x del punto de control
|
|
3194
|
+
* @param {number} cp1y coordenada-y del punto de control
|
|
3195
|
+
* @param {number} x coordenada-x del punto de anclaje
|
|
3196
|
+
* @param {number} y coordenada-y del punto de anclaje
|
|
3197
|
+
*/
|
|
3198
|
+
function vérticeCuadrático(): void;
|
|
3199
|
+
|
|
3200
|
+
/** 🖌
|
|
3201
|
+
* Dibuja una curva Bezier.
|
|
3202
|
+
* @param {number} x1 coordenada-x del primer punto de anclaje
|
|
3203
|
+
* @param {number} y1 coordenada-y del primer punto de anclaje
|
|
3204
|
+
* @param {number} x2 coordenada-x del primer punto de control
|
|
3205
|
+
* @param {number} y2 coordenada-y del primer punto de control
|
|
3206
|
+
* @param {number} x3 coordenada-x del segundo punto de control
|
|
3207
|
+
* @param {number} y3 coordenada-y del segundo punto de control
|
|
3208
|
+
* @param {number} x4 coordenada-x del segundo punto de anclaje
|
|
3209
|
+
* @param {number} y4 coordenada-y del segundo punto de anclaje
|
|
3210
|
+
*/
|
|
3211
|
+
function bezier(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
3212
|
+
|
|
3213
|
+
/** 🖌
|
|
3214
|
+
* Dibuja un triángulo.
|
|
3215
|
+
* @param {number} x1 coordenada-x del primer vértice
|
|
3216
|
+
* @param {number} y1 coordenada-y del primer vértice
|
|
3217
|
+
* @param {number} x2 coordenada-x del segundo vértice
|
|
3218
|
+
* @param {number} y2 coordenada-y del segundo vértice
|
|
3219
|
+
* @param {number} x3 coordenada-x del tercer vértice
|
|
3220
|
+
* @param {number} y3 coordenada-y del tercer vértice
|
|
3221
|
+
*/
|
|
3222
|
+
function triángulo(): void;
|
|
3223
|
+
|
|
3224
|
+
/** 🖌
|
|
3225
|
+
* Dibuja un cuadrilátero.
|
|
3226
|
+
* @param {number} x1 coordenada-x del primer vértice
|
|
3227
|
+
* @param {number} y1 coordenada-y del primer vértice
|
|
3228
|
+
* @param {number} x2 coordenada-x del segundo vértice
|
|
3229
|
+
* @param {number} y2 coordenada-y del segundo vértice
|
|
3230
|
+
* @param {number} x3 coordenada-x del tercer vértice
|
|
3231
|
+
* @param {number} y3 coordenada-y del tercer vértice
|
|
3232
|
+
* @param {number} x4 coordenada-x del cuarto vértice
|
|
3233
|
+
* @param {number} y4 coordenada-y del cuarto vértice
|
|
3234
|
+
*/
|
|
3235
|
+
function quad(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): void;
|
|
3236
|
+
|
|
3237
|
+
// ⚡ shaders
|
|
3238
|
+
|
|
3239
|
+
/**
|
|
3240
|
+
* ¡Shaders personalizados escritos en WGSL (WebGPU Shading Language) pueden ser
|
|
3241
|
+
* usados para crear efectos visuales avanzados en q5!
|
|
3242
|
+
*/
|
|
3243
|
+
|
|
3244
|
+
/** ⚡
|
|
3245
|
+
* Crea un shader que q5 puede usar para dibujar formas.
|
|
3246
|
+
*
|
|
3247
|
+
* Afecta a las siguientes funciones:
|
|
3248
|
+
* `triángulo`, `quad`, `plano`,
|
|
3249
|
+
* `curva`, `bezier`, `empezarForma`/`terminarForma`,
|
|
3250
|
+
* y `fondo` (a menos que se use una imagen).
|
|
3251
|
+
*
|
|
3252
|
+
* Usa esta función para personalizar una copia del
|
|
3253
|
+
* [shader de formas por defecto](https://github.com/q5js/q5.js/blob/main/src/shaders/shapes.wgsl).
|
|
3254
|
+
*
|
|
3255
|
+
* Para más información sobre los parámetros de entrada de las funciones de vértice y fragmento,
|
|
3256
|
+
* datos, y funciones auxiliares disponibles para usar
|
|
3257
|
+
* en tu código de shader personalizado, lee la página wiki
|
|
3258
|
+
* ["Custom Shaders in q5 WebGPU"](https://github.com/q5js/q5.js/wiki/Custom-Shaders-in-q5-WebGPU).
|
|
3259
|
+
* @param {string} codigo extracto de código shader WGSL
|
|
3260
|
+
* @returns {GPUShaderModule} un programa shader
|
|
3261
|
+
* @example
|
|
3262
|
+
* await crearLienzo(200);
|
|
3263
|
+
*
|
|
3264
|
+
* let wobble = crearShader(`
|
|
3265
|
+
* @vertex
|
|
3266
|
+
* fn vertexMain(v: VertexParams) -> FragParams {
|
|
3267
|
+
* var vert = transformVertex(v.pos, v.matrixIndex);
|
|
3268
|
+
*
|
|
3269
|
+
* let i = f32(v.vertexIndex) % 4 * 100;
|
|
3270
|
+
* vert.x += cos((q.time + i) * 0.01) * 0.1;
|
|
3271
|
+
*
|
|
3272
|
+
* var f: FragParams;
|
|
3273
|
+
* f.position = vert;
|
|
3274
|
+
* f.color = vec4f(1, 0, 0, 1);
|
|
3275
|
+
* return f;
|
|
3276
|
+
* }`);
|
|
3277
|
+
*
|
|
3278
|
+
* q5.dibujar = function () {
|
|
3279
|
+
* limpiar();
|
|
3280
|
+
* shader(wobble);
|
|
3281
|
+
* plano(0, 0, 100);
|
|
3282
|
+
* };
|
|
3283
|
+
* @example
|
|
3284
|
+
* await crearLienzo(200);
|
|
3285
|
+
*
|
|
3286
|
+
* let stripes = crearShader(`
|
|
3287
|
+
* @fragment
|
|
3288
|
+
* fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
3289
|
+
* let r = cos((q.mouseY + f.position.y) * 0.2);
|
|
3290
|
+
* return vec4(r, 0.0, 1, 1);
|
|
3291
|
+
* }`);
|
|
3292
|
+
*
|
|
3293
|
+
* q5.dibujar = function () {
|
|
3294
|
+
* shader(stripes);
|
|
3295
|
+
* triángulo(-50, -50, 0, 50, 50, -50);
|
|
3296
|
+
* };
|
|
3297
|
+
*/
|
|
3298
|
+
function crearShader(codigo: string): GPUShaderModule;
|
|
3299
|
+
|
|
3300
|
+
/** ⚡
|
|
3301
|
+
* Un plano es un rectángulo centrado sin trazo.
|
|
3302
|
+
* @param {number} x centro x
|
|
3303
|
+
* @param {number} y centro y
|
|
3304
|
+
* @param {number} w ancho o longitud del lado
|
|
3305
|
+
* @param {number} [h] alto
|
|
3306
|
+
* @example
|
|
3307
|
+
* await crearLienzo(200);
|
|
3308
|
+
* plano(0, 0, 100);
|
|
3309
|
+
*/
|
|
3310
|
+
function plano(x: number, y: number, w: number, h?: number): void;
|
|
3311
|
+
|
|
3312
|
+
/** ⚡
|
|
3313
|
+
* Aplica un shader.
|
|
3314
|
+
* @param {GPUShaderModule} moduloShader un programa shader
|
|
3315
|
+
*/
|
|
3316
|
+
function shader(moduloShader: GPUShaderModule): void;
|
|
3317
|
+
|
|
3318
|
+
/** ⚡
|
|
3319
|
+
* Hace que q5 use el shader de formas por defecto.
|
|
3320
|
+
* @example
|
|
3321
|
+
* await crearLienzo(200);
|
|
3322
|
+
*
|
|
3323
|
+
* let stripes = crearShader(`
|
|
3324
|
+
* @fragment
|
|
3325
|
+
* fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
3326
|
+
* let g = cos((q.mouseY + f.position.y) * 0.05);
|
|
3327
|
+
* return vec4(1, g, 0, 1);
|
|
3328
|
+
* }`);
|
|
3329
|
+
*
|
|
3330
|
+
* q5.dibujar = function () {
|
|
3331
|
+
* shader(stripes);
|
|
3332
|
+
* fondo(0);
|
|
3333
|
+
*
|
|
3334
|
+
* reiniciarShader();
|
|
3335
|
+
* triángulo(-50, -50, 0, 50, 50, -50);
|
|
3336
|
+
* };
|
|
3337
|
+
*/
|
|
3338
|
+
function reiniciarShader(): void;
|
|
3339
|
+
|
|
3340
|
+
/** ⚡
|
|
3341
|
+
* Hace que q5 use el shader de fotograma por defecto.
|
|
3342
|
+
*/
|
|
3343
|
+
function reiniciarShaderFotograma(): void;
|
|
3344
|
+
|
|
3345
|
+
/** ⚡
|
|
3346
|
+
* Hace que q5 use el shader de imagen por defecto.
|
|
3347
|
+
*/
|
|
3348
|
+
function reiniciarShaderImagen(): void;
|
|
3349
|
+
|
|
3350
|
+
/** ⚡
|
|
3351
|
+
* Hace que q5 use el shader de video por defecto.
|
|
3352
|
+
*/
|
|
3353
|
+
function reiniciarShaderVideo(): void;
|
|
3354
|
+
|
|
3355
|
+
/** ⚡
|
|
3356
|
+
* Hace que q5 use el shader de texto por defecto.
|
|
3357
|
+
*/
|
|
3358
|
+
function reiniciarShaderTexto(): void;
|
|
3359
|
+
|
|
3360
|
+
/** ⚡
|
|
3361
|
+
* Hace que q5 use todos los shaders por defecto.
|
|
3362
|
+
*/
|
|
3363
|
+
function reiniciarShaders(): void;
|
|
3364
|
+
|
|
3365
|
+
/** ⚡
|
|
3366
|
+
* Crea un shader que q5 puede usar para dibujar fotogramas.
|
|
3367
|
+
*
|
|
3368
|
+
* `crearLienzo` debe ejecutarse antes de usar esta función.
|
|
3369
|
+
*
|
|
3370
|
+
* Usa esta función para personalizar una copia del
|
|
3371
|
+
* [shader de fotograma por defecto](https://github.com/q5js/q5.js/blob/main/src/shaders/frame.wgsl).
|
|
3372
|
+
* @example
|
|
3373
|
+
* await crearLienzo(200);
|
|
3374
|
+
*
|
|
3375
|
+
* let boxy = crearShaderFotograma(`
|
|
3376
|
+
* @fragment
|
|
3377
|
+
* fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
3378
|
+
* let x = sin(f.texCoord.y * 4 + q.time * 0.002);
|
|
3379
|
+
* let y = cos(f.texCoord.x * 4 + q.time * 0.002);
|
|
3380
|
+
* let uv = f.texCoord + vec2f(x, y);
|
|
3381
|
+
* return textureSample(tex, samp, uv);
|
|
3382
|
+
* }`);
|
|
3383
|
+
*
|
|
3384
|
+
* q5.dibujar = function () {
|
|
3385
|
+
* trazo(1);
|
|
3386
|
+
* grosorTrazo(8);
|
|
3387
|
+
* línea(ratónX, ratónY, pRatónX, pRatónY);
|
|
3388
|
+
* ratónPresionado ? reiniciarShaders() : shader(boxy);
|
|
3389
|
+
* };
|
|
3390
|
+
*/
|
|
3391
|
+
function crearShaderFotograma(codigo: string): GPUShaderModule;
|
|
3392
|
+
|
|
3393
|
+
/** ⚡
|
|
3394
|
+
* Crea un shader que q5 puede usar para dibujar imágenes.
|
|
3395
|
+
*
|
|
3396
|
+
* Usa esta función para personalizar una copia del
|
|
3397
|
+
* [shader de imagen por defecto](https://github.com/q5js/q5.js/blob/main/src/shaders/image.wgsl).
|
|
3398
|
+
* @param {string} codigo extracto de código shader WGSL
|
|
3399
|
+
* @returns {GPUShaderModule} un programa shader
|
|
3400
|
+
* @example
|
|
3401
|
+
* await crearLienzo(200);
|
|
3402
|
+
* modoImagen(CENTER);
|
|
3403
|
+
*
|
|
3404
|
+
* let logo = cargarImagen('/q5js_logo.avif');
|
|
3405
|
+
*
|
|
3406
|
+
* let grate = crearShaderImagen(`
|
|
3407
|
+
* @fragment
|
|
3408
|
+
* fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
3409
|
+
* var texColor = textureSample(tex, samp, f.texCoord);
|
|
3410
|
+
* texColor.b += (q.mouseX + f.position.x) % 20 / 10;
|
|
3411
|
+
* return texColor;
|
|
3412
|
+
* }`);
|
|
3413
|
+
*
|
|
3414
|
+
* q5.dibujar = function () {
|
|
3415
|
+
* fondo(0.7);
|
|
3416
|
+
* shader(grate);
|
|
3417
|
+
* imagen(logo, 0, 0, 180, 180);
|
|
3418
|
+
* };
|
|
3419
|
+
*/
|
|
3420
|
+
function crearShaderImagen(codigo: string): GPUShaderModule;
|
|
3421
|
+
|
|
3422
|
+
/** ⚡
|
|
3423
|
+
* Crea un shader que q5 puede usar para dibujar fotogramas de video.
|
|
3424
|
+
*
|
|
3425
|
+
* Usa esta función para personalizar una copia del
|
|
3426
|
+
* [shader de video por defecto](https://github.com/q5js/q5.js/blob/main/src/shaders/video.wgsl).
|
|
3427
|
+
* @param {string} codigo extracto de código shader WGSL
|
|
3428
|
+
* @returns {GPUShaderModule} un programa shader
|
|
3429
|
+
* @example
|
|
3430
|
+
* await crearLienzo(200, 600);
|
|
3431
|
+
*
|
|
3432
|
+
* let vid = crearVideo('/assets/apollo4.mp4');
|
|
3433
|
+
* vid.hide();
|
|
3434
|
+
*
|
|
3435
|
+
* let flipper = crearShaderVideo(`
|
|
3436
|
+
* @vertex
|
|
3437
|
+
* fn vertexMain(v: VertexParams) -> FragParams {
|
|
3438
|
+
* var vert = transformVertex(v.pos, v.matrixIndex);
|
|
3439
|
+
*
|
|
3440
|
+
* var vi = f32(v.vertexIndex);
|
|
3441
|
+
* vert.y *= cos((q.frameCount + vi * 10) * 0.03);
|
|
3442
|
+
*
|
|
3443
|
+
* var f: FragParams;
|
|
3444
|
+
* f.position = vert;
|
|
3445
|
+
* f.texCoord = v.texCoord;
|
|
3446
|
+
* return f;
|
|
3447
|
+
* }
|
|
3448
|
+
*
|
|
3449
|
+
* @fragment
|
|
3450
|
+
* fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
3451
|
+
* var texColor =
|
|
3452
|
+
* textureSampleBaseClampToEdge(tex, samp, f.texCoord);
|
|
3453
|
+
* texColor.r = 0;
|
|
3454
|
+
* texColor.b *= 2;
|
|
3455
|
+
* return texColor;
|
|
3456
|
+
* }`);
|
|
3457
|
+
*
|
|
3458
|
+
* q5.dibujar = function () {
|
|
3459
|
+
* limpiar();
|
|
3460
|
+
* if (ratónPresionado) vid.play();
|
|
3461
|
+
* shader(flipper);
|
|
3462
|
+
* imagen(vid, -100, 150, 200, 150);
|
|
3463
|
+
* };
|
|
3464
|
+
*/
|
|
3465
|
+
function crearShaderVideo(codigo: string): GPUShaderModule;
|
|
3466
|
+
|
|
3467
|
+
/** ⚡
|
|
3468
|
+
* Crea un shader que q5 puede usar para dibujar texto.
|
|
3469
|
+
*
|
|
3470
|
+
* Usa esta función para personalizar una copia del
|
|
3471
|
+
* [shader de texto por defecto](https://github.com/q5js/q5.js/blob/main/src/shaders/text.wgsl).
|
|
3472
|
+
* @param {string} codigo extracto de código shader WGSL
|
|
3473
|
+
* @returns {GPUShaderModule} un programa shader
|
|
3474
|
+
* @example
|
|
3475
|
+
* await crearLienzo(200);
|
|
3476
|
+
* alineaciónTexto(CENTER, CENTER);
|
|
3477
|
+
*
|
|
3478
|
+
* let spin = crearShaderTexto(`
|
|
3479
|
+
* @vertex
|
|
3480
|
+
* fn vertexMain(v : VertexParams) -> FragParams {
|
|
3481
|
+
* let char = textChars[v.instanceIndex];
|
|
3482
|
+
* let text = textMetadata[i32(char.w)];
|
|
3483
|
+
* let fontChar = fontChars[i32(char.z)];
|
|
3484
|
+
* let pos = calcPos(v.vertexIndex, char, fontChar, text);
|
|
3485
|
+
*
|
|
3486
|
+
* var vert = transformVertex(pos, text.matrixIndex);
|
|
3487
|
+
*
|
|
3488
|
+
* let i = f32(v.instanceIndex + 1);
|
|
3489
|
+
* vert.y *= cos((q.frameCount - 5 * i) * 0.05);
|
|
3490
|
+
*
|
|
3491
|
+
* var f : FragParams;
|
|
3492
|
+
* f.position = vert;
|
|
3493
|
+
* f.texCoord = calcUV(v.vertexIndex, fontChar);
|
|
3494
|
+
* f.fillColor = colors[i32(text.fillIndex)];
|
|
3495
|
+
* f.strokeColor = colors[i32(text.strokeIndex)];
|
|
3496
|
+
* f.strokeWeight = text.strokeWeight;
|
|
3497
|
+
* f.edge = text.edge;
|
|
3498
|
+
* return f;
|
|
3499
|
+
* }`);
|
|
3500
|
+
*
|
|
3501
|
+
* q5.dibujar = function () {
|
|
3502
|
+
* limpiar();
|
|
3503
|
+
* shader(spin);
|
|
3504
|
+
* relleno(1, 0, 1);
|
|
3505
|
+
* tamañoTexto(32);
|
|
3506
|
+
* texto('Hello, World!', 0, 0);
|
|
3507
|
+
* };
|
|
3508
|
+
*/
|
|
3509
|
+
function crearShaderTexto(codigo: string): GPUShaderModule;
|
|
3510
|
+
|
|
3511
|
+
// ⚙ advanced
|
|
3512
|
+
|
|
3513
|
+
class Q5 {
|
|
3514
|
+
|
|
3515
|
+
/** ⚙
|
|
3516
|
+
* Funcion constructora. Crea una instancia de Q5.
|
|
3517
|
+
* @param {string | Function} [ambito]
|
|
3518
|
+
* @param {HTMLElement} [contenedor] elemento HTML dentro del cual se colocará el lienzo
|
|
3519
|
+
*/
|
|
3520
|
+
constructor(scope?: string | Function, parent?: HTMLElement);
|
|
3521
|
+
static deshabilitarErroresAmigables: boolean;
|
|
3522
|
+
|
|
3523
|
+
static toleranteErrores: boolean;
|
|
3524
|
+
|
|
3525
|
+
static soportaHDR: boolean;
|
|
3526
|
+
|
|
3527
|
+
static opcionesLienzo: object;
|
|
3528
|
+
|
|
3529
|
+
static MAX_RECTS: number;
|
|
3530
|
+
|
|
3531
|
+
static MAX_ELIPSES: number;
|
|
3532
|
+
|
|
3533
|
+
static MAX_TRANSFORMACIONES: number;
|
|
3534
|
+
|
|
3535
|
+
static MAX_CARACTERES: number;
|
|
3536
|
+
|
|
3537
|
+
static MAX_TEXTOS: number;
|
|
3538
|
+
|
|
3539
|
+
static WebGPU(): Q5;
|
|
3540
|
+
|
|
3541
|
+
static agregarHook(cicloVida: string, fn: Function): void;
|
|
3542
|
+
|
|
3543
|
+
static registrarAddon(addon: Function): void;
|
|
3544
|
+
|
|
3545
|
+
static modulos: object;
|
|
3546
|
+
|
|
3547
|
+
dibujar(): void;
|
|
3548
|
+
|
|
3549
|
+
postProcesar(): void;
|
|
3550
|
+
|
|
3551
|
+
actualizar(): void; //-
|
|
3552
|
+
|
|
3553
|
+
dibujarFotograma(): void; //-
|
|
3554
|
+
|
|
3555
|
+
static Imagen: {
|
|
3556
|
+
new (w: number, h: number, opt?: any): Q5.Imagen;
|
|
3557
|
+
};
|
|
3558
|
+
|
|
3559
|
+
}
|
|
3560
|
+
|
|
3561
|
+
namespace Q5 {
|
|
3562
|
+
interface Imagen {
|
|
3563
|
+
ancho: number;
|
|
3564
|
+
alto: number;
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
const q5: typeof Q5;
|
|
156
3569
|
|
|
157
3570
|
}
|
|
158
3571
|
|