// This file is auto-generated from JSDoc documentation
declare const RGB: 'rgb';
declare const __RGB: typeof RGB;
declare const RGBHDR: 'rgbhdr';
declare const __RGBHDR: typeof RGBHDR;
/**
* HSB (hue, saturation, brightness) is a type of color model.
* You can learn more about it at
* HSB.
*/
declare const HSB: 'hsb';
declare const __HSB: typeof HSB;
declare const HSL: 'hsl';
declare const __HSL: typeof HSL;
declare const HWB: 'hwb';
declare const __HWB: typeof HWB;
declare const LAB: 'lab';
declare const __LAB: typeof LAB;
declare const LCH: 'lch';
declare const __LCH: typeof LCH;
declare const OKLAB: 'oklab';
declare const __OKLAB: typeof OKLAB;
declare const OKLCH: 'oklch';
declare const __OKLCH: typeof OKLCH;
declare const RGBA: 'rgba';
declare const __RGBA: typeof RGBA;
/**
* Version of this p5.js.
*/
declare const VERSION: string;
declare const __VERSION: typeof VERSION;
/**
* The default, two-dimensional renderer in p5.js.
*
* Use this when calling (for example,
* `createCanvas(400, 400, P2D)`) to specify a 2D context.
*/
declare const P2D: 'p2d';
declare const __P2D: typeof P2D;
/**
* A high-dynamic-range (HDR) variant of the default, two-dimensional renderer.
*
* When available, this mode can allow for extended color ranges and more
* dynamic color representation. Use it similarly to `P2D`:
* `createCanvas(400, 400, P2DHDR)`.
*/
declare const P2DHDR: 'p2d-hdr';
declare const __P2DHDR: typeof P2DHDR;
/**
* One of the two render modes in p5.js, used for computationally intensive tasks like 3D rendering and shaders.
*
* `WEBGL` differs from the default `P2D` renderer in the following ways:
*
* - Coordinate System - When drawing in `WEBGL` mode, the origin point (0,0,0) is located at the center of the screen, not the top-left corner. See the tutorial page about coordinates and transformations.
*
* - 3D Shapes - `WEBGL` mode can be used to draw 3-dimensional shapes like box(), sphere(), cone(), and more. See the tutorial page about custom geometry to make more complex objects.
*
* - Shape Detail - When drawing in `WEBGL` mode, you can specify how smooth curves should be drawn by using a `detail` parameter. See the wiki section about shapes for a more information and an example.
*
* - Textures - A texture is like a skin that wraps onto a shape. See the wiki section about textures for examples of mapping images onto surfaces with textures.
*
* - Materials and Lighting - `WEBGL` offers different types of lights like ambientLight() to place around a scene. Materials like specularMaterial() reflect the lighting to convey shape and depth. See the tutorial page for styling and appearance to experiment with different combinations.
*
* - Camera - The viewport of a `WEBGL` sketch can be adjusted by changing camera attributes. See the tutorial page section about cameras for an explanation of camera controls.
*
* - Text - `WEBGL` requires opentype/truetype font files to be preloaded using loadFont(). See the wiki section about text for details, along with a workaround.
*
* - Shaders - Shaders are hardware accelerated programs that can be used for a variety of effects and graphics. See the introduction to shaders to get started with shaders in p5.js.
*
* - Graphics Acceleration - `WEBGL` mode uses the graphics card instead of the CPU, so it may help boost the performance of your sketch (example: drawing more shapes on the screen at once).
*
* To learn more about WEBGL mode, check out all the interactive WEBGL tutorials in the "Tutorials" section of this website, or read the wiki article "Getting started with WebGL in p5".
*/
declare const WEBGL: 'webgl';
declare const __WEBGL: typeof WEBGL;
/**
* One of the two possible values of a WebGL canvas (either WEBGL or WEBGL2),
* which can be used to determine what capabilities the rendering environment
* has.
*/
declare const WEBGL2: 'webgl2';
declare const __WEBGL2: typeof WEBGL2;
declare const ARROW: 'default';
declare const __ARROW: typeof ARROW;
declare const SIMPLE: string;
declare const __SIMPLE: typeof SIMPLE;
declare const FULL: string;
declare const __FULL: typeof FULL;
declare const CROSS: 'crosshair';
declare const __CROSS: typeof CROSS;
declare const HAND: 'pointer';
declare const __HAND: typeof HAND;
declare const MOVE: 'move';
declare const __MOVE: typeof MOVE;
declare const TEXT: 'text';
declare const __TEXT: typeof TEXT;
declare const WAIT: 'wait';
declare const __WAIT: typeof WAIT;
/**
* A `Number` constant that's approximately 1.5708.
*
* `HALF_PI` is half the value of the mathematical constant π. It's useful for
* many tasks that involve rotation and oscillation. For example, calling
* `rotate(HALF_PI)` rotates the coordinate system `HALF_PI` radians, which is
* a quarter turn (90˚).
*
* Note: `TWO_PI` radians equals 360˚, `PI` radians equals 180˚, `HALF_PI`
* radians equals 90˚, and `QUARTER_PI` radians equals 45˚.
*/
declare const HALF_PI: number;
declare const __HALF_PI: typeof HALF_PI;
/**
* A `Number` constant that's approximately 3.1416.
*
* `PI` is the mathematical constant π. It's useful for many tasks that
* involve rotation and oscillation. For example, calling `rotate(PI)` rotates
* the coordinate system `PI` radians, which is a half turn (180˚).
*
* Note: `TWO_PI` radians equals 360˚, `PI` radians equals 180˚, `HALF_PI`
* radians equals 90˚, and `QUARTER_PI` radians equals 45˚.
*/
declare const PI: number;
declare const __PI: typeof PI;
/**
* A `Number` constant that's approximately 0.7854.
*
* `QUARTER_PI` is one-fourth the value of the mathematical constant π. It's
* useful for many tasks that involve rotation and oscillation. For example,
* calling `rotate(QUARTER_PI)` rotates the coordinate system `QUARTER_PI`
* radians, which is an eighth of a turn (45˚).
*
* Note: `TWO_PI` radians equals 360˚, `PI` radians equals 180˚, `HALF_PI`
* radians equals 90˚, and `QUARTER_PI` radians equals 45˚.
*/
declare const QUARTER_PI: number;
declare const __QUARTER_PI: typeof QUARTER_PI;
/**
* A `Number` constant that's approximately 6.2382.
*
* `TAU` is twice the value of the mathematical constant π. It's useful for
* many tasks that involve rotation and oscillation. For example, calling
* `rotate(TAU)` rotates the coordinate system `TAU` radians, which is one
* full turn (360˚). `TAU` and `TWO_PI` are equal.
*
* Note: `TAU` radians equals 360˚, `PI` radians equals 180˚, `HALF_PI`
* radians equals 90˚, and `QUARTER_PI` radians equals 45˚.
*/
declare const TAU: number;
declare const __TAU: typeof TAU;
/**
* A `Number` constant that's approximately 6.2382.
*
* `TWO_PI` is twice the value of the mathematical constant π. It's useful for
* many tasks that involve rotation and oscillation. For example, calling
* `rotate(TWO_PI)` rotates the coordinate system `TWO_PI` radians, which is
* one full turn (360˚). `TWO_PI` and `TAU` are equal.
*
* Note: `TWO_PI` radians equals 360˚, `PI` radians equals 180˚, `HALF_PI`
* radians equals 90˚, and `QUARTER_PI` radians equals 45˚.
*/
declare const TWO_PI: number;
declare const __TWO_PI: typeof TWO_PI;
declare const DEG_TO_RAD: number;
declare const __DEG_TO_RAD: typeof DEG_TO_RAD;
declare const RAD_TO_DEG: number;
declare const __RAD_TO_DEG: typeof RAD_TO_DEG;
declare const CORNER: 'corner';
declare const __CORNER: typeof CORNER;
declare const CORNERS: 'corners';
declare const __CORNERS: typeof CORNERS;
declare const RADIUS: 'radius';
declare const __RADIUS: typeof RADIUS;
declare const RIGHT: 'right';
declare const __RIGHT: typeof RIGHT;
declare const LEFT: 'left';
declare const __LEFT: typeof LEFT;
declare const CENTER: 'center';
declare const __CENTER: typeof CENTER;
declare const TOP: 'top';
declare const __TOP: typeof TOP;
declare const BOTTOM: 'bottom';
declare const __BOTTOM: typeof BOTTOM;
declare const BASELINE: 'alphabetic';
declare const __BASELINE: typeof BASELINE;
declare const POINTS: 0;
declare const __POINTS: typeof POINTS;
declare const LINES: 1;
declare const __LINES: typeof LINES;
declare const LINE_STRIP: 3;
declare const __LINE_STRIP: typeof LINE_STRIP;
declare const LINE_LOOP: 2;
declare const __LINE_LOOP: typeof LINE_LOOP;
declare const TRIANGLES: 4;
declare const __TRIANGLES: typeof TRIANGLES;
declare const TRIANGLE_FAN: 6;
declare const __TRIANGLE_FAN: typeof TRIANGLE_FAN;
declare const TRIANGLE_STRIP: 5;
declare const __TRIANGLE_STRIP: typeof TRIANGLE_STRIP;
declare const QUADS: 'quads';
declare const __QUADS: typeof QUADS;
declare const QUAD_STRIP: 'quad_strip';
declare const __QUAD_STRIP: typeof QUAD_STRIP;
declare const TESS: 'tess';
declare const __TESS: typeof TESS;
declare const EMPTY_PATH: 7;
declare const __EMPTY_PATH: typeof EMPTY_PATH;
declare const PATH: 8;
declare const __PATH: typeof PATH;
declare const CLOSE: 'close';
declare const __CLOSE: typeof CLOSE;
declare const OPEN: 'open';
declare const __OPEN: typeof OPEN;
declare const CHORD: 'chord';
declare const __CHORD: typeof CHORD;
declare const PIE: 'pie';
declare const __PIE: typeof PIE;
declare const PROJECT: 'square';
declare const __PROJECT: typeof PROJECT;
declare const SQUARE: 'butt';
declare const __SQUARE: typeof SQUARE;
declare const ROUND: 'round';
declare const __ROUND: typeof ROUND;
declare const BEVEL: 'bevel';
declare const __BEVEL: typeof BEVEL;
declare const MITER: 'miter';
declare const __MITER: typeof MITER;
/**
* AUTO allows us to automatically set the width or height of an element (but not both),
* based on the current height and width of the element. Only one parameter can
* be passed to the size function as AUTO, at a time.
*/
declare const AUTO: 'auto';
declare const __AUTO: typeof AUTO;
declare const ALT: 'Alt';
declare const __ALT: typeof ALT;
declare const BACKSPACE: 'Backspace';
declare const __BACKSPACE: typeof BACKSPACE;
declare const CONTROL: 'Control' | 'Control';
declare const __CONTROL: typeof CONTROL;
declare const DELETE: 'Delete';
declare const __DELETE: typeof DELETE;
declare const DOWN_ARROW: 'ArrowDown';
declare const __DOWN_ARROW: typeof DOWN_ARROW;
declare const ENTER: 'Enter';
declare const __ENTER: typeof ENTER;
declare const ESCAPE: 'Escape';
declare const __ESCAPE: typeof ESCAPE;
declare const LEFT_ARROW: 'ArrowLeft';
declare const __LEFT_ARROW: typeof LEFT_ARROW;
declare const OPTION: 'Alt';
declare const __OPTION: typeof OPTION;
declare const RETURN: 'Enter';
declare const __RETURN: typeof RETURN;
declare const RIGHT_ARROW: 'ArrowRight';
declare const __RIGHT_ARROW: typeof RIGHT_ARROW;
declare const SHIFT: 'Shift';
declare const __SHIFT: typeof SHIFT;
declare const TAB: 'Tab';
declare const __TAB: typeof TAB;
declare const UP_ARROW: 'ArrowUp';
declare const __UP_ARROW: typeof UP_ARROW;
declare const BLEND: 'source-over';
declare const __BLEND: typeof BLEND;
declare const REMOVE: 'destination-out';
declare const __REMOVE: typeof REMOVE;
declare const ADD: 'lighter';
declare const __ADD: typeof ADD;
declare const DARKEST: 'darken';
declare const __DARKEST: typeof DARKEST;
declare const LIGHTEST: 'lighten';
declare const __LIGHTEST: typeof LIGHTEST;
declare const DIFFERENCE: 'difference';
declare const __DIFFERENCE: typeof DIFFERENCE;
declare const SUBTRACT: 'subtract';
declare const __SUBTRACT: typeof SUBTRACT;
declare const EXCLUSION: 'exclusion';
declare const __EXCLUSION: typeof EXCLUSION;
declare const MULTIPLY: 'multiply';
declare const __MULTIPLY: typeof MULTIPLY;
declare const SCREEN: 'screen';
declare const __SCREEN: typeof SCREEN;
declare const REPLACE: 'copy';
declare const __REPLACE: typeof REPLACE;
declare const OVERLAY: 'overlay';
declare const __OVERLAY: typeof OVERLAY;
declare const HARD_LIGHT: 'hard-light';
declare const __HARD_LIGHT: typeof HARD_LIGHT;
declare const SOFT_LIGHT: 'soft-light';
declare const __SOFT_LIGHT: typeof SOFT_LIGHT;
declare const DODGE: 'color-dodge';
declare const __DODGE: typeof DODGE;
declare const BURN: 'color-burn';
declare const __BURN: typeof BURN;
declare const THRESHOLD: 'threshold';
declare const __THRESHOLD: typeof THRESHOLD;
declare const GRAY: 'gray';
declare const __GRAY: typeof GRAY;
declare const OPAQUE: 'opaque';
declare const __OPAQUE: typeof OPAQUE;
declare const INVERT: 'invert';
declare const __INVERT: typeof INVERT;
declare const POSTERIZE: 'posterize';
declare const __POSTERIZE: typeof POSTERIZE;
declare const DILATE: 'dilate';
declare const __DILATE: typeof DILATE;
declare const ERODE: 'erode';
declare const __ERODE: typeof ERODE;
declare const BLUR: 'blur';
declare const __BLUR: typeof BLUR;
declare const NORMAL: 'normal';
declare const __NORMAL: typeof NORMAL;
declare const ITALIC: 'italic';
declare const __ITALIC: typeof ITALIC;
declare const BOLD: 'bold';
declare const __BOLD: typeof BOLD;
declare const BOLDITALIC: 'bold italic';
declare const __BOLDITALIC: typeof BOLDITALIC;
declare const CHAR: 'CHAR';
declare const __CHAR: typeof CHAR;
declare const WORD: 'WORD';
declare const __WORD: typeof WORD;
declare const LINEAR: 'linear';
declare const __LINEAR: typeof LINEAR;
declare const QUADRATIC: 'quadratic';
declare const __QUADRATIC: typeof QUADRATIC;
declare const BEZIER: 'bezier';
declare const __BEZIER: typeof BEZIER;
declare const CURVE: 'curve';
declare const __CURVE: typeof CURVE;
declare const STROKE: 'stroke';
declare const __STROKE: typeof STROKE;
declare const FILL: 'fill';
declare const __FILL: typeof FILL;
declare const TEXTURE: 'texture';
declare const __TEXTURE: typeof TEXTURE;
declare const IMMEDIATE: 'immediate';
declare const __IMMEDIATE: typeof IMMEDIATE;
declare const IMAGE: 'image';
declare const __IMAGE: typeof IMAGE;
declare const NEAREST: 'nearest';
declare const __NEAREST: typeof NEAREST;
declare const REPEAT: 'repeat';
declare const __REPEAT: typeof REPEAT;
declare const CLAMP: 'clamp';
declare const __CLAMP: typeof CLAMP;
declare const MIRROR: 'mirror';
declare const __MIRROR: typeof MIRROR;
declare const FLAT: 'flat';
declare const __FLAT: typeof FLAT;
declare const SMOOTH: 'smooth';
declare const __SMOOTH: typeof SMOOTH;
declare const LANDSCAPE: 'landscape';
declare const __LANDSCAPE: typeof LANDSCAPE;
declare const PORTRAIT: 'portrait';
declare const __PORTRAIT: typeof PORTRAIT;
declare const GRID: 'grid';
declare const __GRID: typeof GRID;
declare const AXES: 'axes';
declare const __AXES: typeof AXES;
declare const LABEL: 'label';
declare const __LABEL: typeof LABEL;
declare const FALLBACK: 'fallback';
declare const __FALLBACK: typeof FALLBACK;
declare const CONTAIN: 'contain';
declare const __CONTAIN: typeof CONTAIN;
declare const COVER: 'cover';
declare const __COVER: typeof COVER;
declare const UNSIGNED_BYTE: 'unsigned-byte';
declare const __UNSIGNED_BYTE: typeof UNSIGNED_BYTE;
declare const UNSIGNED_INT: 'unsigned-int';
declare const __UNSIGNED_INT: typeof UNSIGNED_INT;
declare const FLOAT: 'float';
declare const __FLOAT: typeof FLOAT;
declare const HALF_FLOAT: 'half-float';
declare const __HALF_FLOAT: typeof HALF_FLOAT;
/**
* The `splineProperty('ends')` mode where splines curve through
* their first and last points.
*/
declare const INCLUDE: Symbol;
declare const __INCLUDE: typeof INCLUDE;
/**
* The `splineProperty('ends')` mode where the first and last points in a spline
* affect the direction of the curve, but are not rendered.
*/
declare const EXCLUDE: Symbol;
declare const __EXCLUDE: typeof EXCLUDE;
/**
* A `Number` variable that tracks the number of frames drawn since the sketch
* started.
*
* `frameCount`'s value is 0 inside setup(). It
* increments by 1 each time the code in draw()
* finishes executing.
*/
declare const frameCount: number;
declare const __frameCount: typeof frameCount;
/**
* A `Number` variable that tracks the number of milliseconds it took to draw
* the last frame.
*
* `deltaTime` contains the amount of time it took
* draw() to execute during the previous frame. It's
* useful for simulating physics.
*/
declare const deltaTime: number;
declare const __deltaTime: typeof deltaTime;
/**
* A `Boolean` variable that's `true` if the browser is focused and `false` if
* not.
*
* Note: The browser window can only receive input if it's focused.
*/
declare const focused: boolean;
declare const __focused: typeof focused;
/**
* A `String` variable with the WebGL version in use.
*
* `webglVersion`'s value equals one of the following string constants:
*
* - `WEBGL2` whose value is `'webgl2'`,
*
* - `WEBGL` whose value is `'webgl'`, or
*
* - `P2D` whose value is `'p2d'`. This is the default for 2D sketches.
*
* - `P2DHDR` whose value is `'p2d-hdr'` (used for HDR 2D sketches, if available).
*
* See setAttributes() for ways to set the
* WebGL version.
*/
declare const webglVersion: 'webgl' | 'webgl2';
declare const __webglVersion: typeof webglVersion;
/**
* A `Number` variable that stores the width of the screen display.
*
* `displayWidth` is useful for running full-screen programs. Its value
* depends on the current pixelDensity().
*
* Note: The actual screen width can be computed as
* `displayWidth * pixelDensity()`.
*/
declare const displayWidth: number;
declare const __displayWidth: typeof displayWidth;
/**
* A `Number` variable that stores the height of the screen display.
*
* `displayHeight` is useful for running full-screen programs. Its value
* depends on the current pixelDensity().
*
* Note: The actual screen height can be computed as
* `displayHeight * pixelDensity()`.
*/
declare const displayHeight: number;
declare const __displayHeight: typeof displayHeight;
/**
* A `Number` variable that stores the width of the browser's viewport.
*
* The layout viewport
* is the area within the browser that's available for drawing.
*/
declare const windowWidth: number;
declare const __windowWidth: typeof windowWidth;
/**
* A `Number` variable that stores the height of the browser's viewport.
*
* The layout viewport
* is the area within the browser that's available for drawing.
*/
declare const windowHeight: number;
declare const __windowHeight: typeof windowHeight;
/**
* The system variable deviceOrientation always contains the orientation of
* the device. The value of this variable will either be set 'landscape'
* or 'portrait'. If no data is available it will be set to 'undefined'.
* either LANDSCAPE or PORTRAIT.
*/
declare const deviceOrientation: 'landscape' | 'portrait';
declare const __deviceOrientation: typeof deviceOrientation;
/**
* The system variable accelerationX always contains the acceleration of the
* device along the x axis. Value is represented as meters per second squared.
*/
declare const accelerationX: number;
declare const __accelerationX: typeof accelerationX;
/**
* The system variable accelerationY always contains the acceleration of the
* device along the y axis. Value is represented as meters per second squared.
*/
declare const accelerationY: number;
declare const __accelerationY: typeof accelerationY;
/**
* The system variable accelerationZ always contains the acceleration of the
* device along the z axis. Value is represented as meters per second squared.
*/
declare const accelerationZ: number;
declare const __accelerationZ: typeof accelerationZ;
/**
* The system variable pAccelerationX always contains the acceleration of the
* device along the x axis in the frame previous to the current frame. Value
* is represented as meters per second squared.
*/
declare const pAccelerationX: number;
declare const __pAccelerationX: typeof pAccelerationX;
/**
* The system variable pAccelerationY always contains the acceleration of the
* device along the y axis in the frame previous to the current frame. Value
* is represented as meters per second squared.
*/
declare const pAccelerationY: number;
declare const __pAccelerationY: typeof pAccelerationY;
/**
* The system variable pAccelerationZ always contains the acceleration of the
* device along the z axis in the frame previous to the current frame. Value
* is represented as meters per second squared.
*/
declare const pAccelerationZ: number;
declare const __pAccelerationZ: typeof pAccelerationZ;
/**
* The system variable rotationX always contains the rotation of the
* device along the x axis. If the sketch
* angleMode() is set to DEGREES, the value will be -180 to 180. If
* it is set to RADIANS, the value will be -PI to PI.
*
* Note: The order the rotations are called is important, ie. if used
* together, it must be called in the order Z-X-Y or there might be
* unexpected behaviour.
*/
declare const rotationX: number;
declare const __rotationX: typeof rotationX;
/**
* The system variable rotationY always contains the rotation of the
* device along the y axis. If the sketch
* angleMode() is set to DEGREES, the value will be -90 to 90. If
* it is set to RADIANS, the value will be -PI/2 to PI/2.
*
* Note: The order the rotations are called is important, ie. if used
* together, it must be called in the order Z-X-Y or there might be
* unexpected behaviour.
*/
declare const rotationY: number;
declare const __rotationY: typeof rotationY;
/**
* The system variable rotationZ always contains the rotation of the
* device along the z axis. If the sketch
* angleMode() is set to DEGREES, the value will be 0 to 360. If
* it is set to RADIANS, the value will be 0 to 2*PI.
*
* Unlike rotationX and rotationY, this variable is available for devices
* with a built-in compass only.
*
* Note: The order the rotations are called is important, ie. if used
* together, it must be called in the order Z-X-Y or there might be
* unexpected behaviour.
*/
declare const rotationZ: number;
declare const __rotationZ: typeof rotationZ;
/**
* The system variable pRotationX always contains the rotation of the
* device along the x axis in the frame previous to the current frame.
* If the sketch angleMode() is set to DEGREES,
* the value will be -180 to 180. If it is set to RADIANS, the value will
* be -PI to PI.
*
* pRotationX can also be used with rotationX to determine the rotate
* direction of the device along the X-axis.
*/
declare const pRotationX: number;
declare const __pRotationX: typeof pRotationX;
/**
* The system variable pRotationY always contains the rotation of the
* device along the y axis in the frame previous to the current frame.
* If the sketch angleMode() is set to DEGREES,
* the value will be -90 to 90. If it is set to RADIANS, the value will
* be -PI/2 to PI/2.
*
* pRotationY can also be used with rotationY to determine the rotate
* direction of the device along the Y-axis.
*/
declare const pRotationY: number;
declare const __pRotationY: typeof pRotationY;
/**
* The system variable pRotationZ always contains the rotation of the
* device along the z axis in the frame previous to the current frame.
* If the sketch angleMode() is set to DEGREES,
* the value will be 0 to 360. If it is set to RADIANS, the value will
* be 0 to 2*PI.
*
* pRotationZ can also be used with rotationZ to determine the rotate
* direction of the device along the Z-axis.
*/
declare const pRotationZ: number;
declare const __pRotationZ: typeof pRotationZ;
/**
* When a device is rotated, the axis that triggers the deviceTurned()
* method is stored in the turnAxis variable. The turnAxis variable is only defined within
* the scope of deviceTurned().
*/
declare const turnAxis: string;
declare const __turnAxis: typeof turnAxis;
/**
* A `Boolean` system variable that's `true` if any key is currently pressed
* and `false` if not.
*/
declare const keyIsPressed: boolean;
declare const __keyIsPressed: typeof keyIsPressed;
/**
* A `String` system variable that contains the value of the last key typed.
*
* The key variable is helpful for checking whether an
* ASCII
* key has been typed. For example, the expression `key === "a"` evaluates to
* `true` if the `a` key was typed and `false` if not. `key` doesn’t update
* for special keys such as `LEFT_ARROW` and `ENTER`. Use keyCode instead for
* special keys. The keyIsDown() function should
* be used to check for multiple different key presses at the same time.
*/
declare const key: string;
declare const __key: typeof key;
/**
* The `code` property represents a physical key on the keyboard (as opposed
* to the character generated by pressing the key). In other words, this
* property returns a value that isn't altered by keyboard layout or the state
* of the modifier keys.
*
* This property is useful when you want to handle keys based on their
* physical positions on the input device rather than the characters associated
* with those keys;
*
* Unlike key, the `code` property differentiates between
* physical keys that generate the same character—for example, `CtrlLeft` and
* `CtrlRight`—so each can be handled independently.
* Here's the MDN docs for KeyboardEvent.code
*
* Pressing the key physically labeled “A” always yields `KeyA`, regardless
* of the current keyboard layout (QWERTY, Dvorak, AZERTY, etc.) or the character
* that appears in a text field.
*
* The code property returns a plain string (e.g., 'ArrowRight'). You can
* compare it directly with string literals:
*
* `if (keyIsDown(RIGHT_ARROW)) {
* // …
* }
* // The line above is equivalent to:
* if (code === 'ArrowRight') {
* // …
* }
* if (key === 'ArrowRight') {
* // …
* }`The system variables `BACKSPACE`, `DELETE`, `ENTER`, `RETURN`, `TAB`,
* `ESCAPE`, `SHIFT`, `CONTROL`, `OPTION`, `ALT`, `UP_ARROW`, `DOWN_ARROW`,
* `LEFT_ARROW`, and `RIGHT_ARROW` are all helpful shorthands the key codes of
* special keys.
* These are simply shorthands for the same string values:
*
* `if (code === RIGHT_ARROW) {
* // ..
* }`
The table below summarizes how the main keyboard-related system variables changed between p5.js 1.x and 2.x.
*
*
*
*
Variable
*
p5.js 1.x
*
p5.js 2.x
*
*
*
*
*
key
*
Text string (e.g., "ArrowUp").
*
Text string (e.g., "ArrowUp", "f" or "F").
*
*
*
code
*
Not supported.
*
Text String (e.g., "ArrowUp", "KeyF").
*
*
*
keyCode
*
Number (e.g., 70).
*
Number (unchanged; e.g., 70).
*
*
*
System variables (BACKSPACE, UP_ARROW, …)
*
Number
*
Text String (e.g., "ArrowUp").
*
*
*
*/
declare const code: string;
declare const __code: typeof code;
/**
* A `Number` system variable that contains the code of the last key pressed.
*
* Every key has a numeric key code. For example, the letter `a` key has the key code 65.
* Use this key code to determine which key was pressed by comparing it to the numeric value
* of the desired key.
*
* For example, to detect when the Enter key is pressed:
*
* `if (keyCode === 13) { // Enter key
* // Code to run if the Enter key was pressed.
* }`Alternatively, you can use the key function to directly compare the key value:
*
* `if (key === 'Enter') { // Enter key
* // Code to run if the Enter key was pressed.
* }`Use the following numeric codes for the arrow keys:
*
* Up Arrow: 38
* Down Arrow: 40
* Left Arrow: 37
* Right Arrow: 39
*
* More key codes can be found at websites such as
* keycode.info.
*/
declare const keyCode: number;
declare const __keyCode: typeof keyCode;
/**
* A `Number` system variable that tracks the mouse's horizontal movement.
*
* `movedX` tracks how many pixels the mouse moves left or right between
* frames. `movedX` will have a negative value if the mouse moves left between
* frames and a positive value if it moves right. `movedX` can be calculated
* as `mouseX - pmouseX`.
*
* Note: `movedX` continues updating even when
* requestPointerLock() is active.
*/
declare const movedX: number;
declare const __movedX: typeof movedX;
/**
* A `Number` system variable that tracks the mouse's vertical movement.
*
* `movedY` tracks how many pixels the mouse moves up or down between
* frames. `movedY` will have a negative value if the mouse moves up between
* frames and a positive value if it moves down. `movedY` can be calculated
* as `mouseY - pmouseY`.
*
* Note: `movedY` continues updating even when
* requestPointerLock() is active.
*/
declare const movedY: number;
declare const __movedY: typeof movedY;
/**
* A `Number` system variable that tracks the mouse's horizontal position.
*
* `mouseX` keeps track of the mouse's position relative to the
* top-left corner of the canvas. For example, if the mouse is 50 pixels from
* the left edge of the canvas, then `mouseX` will be 50.
*
* If touch is used instead of the mouse, then `mouseX` will hold the
* x-coordinate of the most recent touch point.
*/
declare const mouseX: number;
declare const __mouseX: typeof mouseX;
/**
* A `Number` system variable that tracks the mouse's vertical position.
*
* `mouseY` keeps track of the mouse's position relative to the
* top-left corner of the canvas. For example, if the mouse is 50 pixels from
* the top edge of the canvas, then `mouseY` will be 50.
*
* If touch is used instead of the mouse, then `mouseY` will hold the
* y-coordinate of the most recent touch point.
*/
declare const mouseY: number;
declare const __mouseY: typeof mouseY;
/**
* A `Number` system variable that tracks the mouse's previous horizontal
* position.
*
* `pmouseX` keeps track of the mouse's position relative to the
* top-left corner of the canvas. Its value is
* mouseX from the previous frame. For example, if
* the mouse was 50 pixels from the left edge of the canvas during the last
* frame, then `pmouseX` will be 50.
*
* If touch is used instead of the mouse, then `pmouseX` will hold the
* x-coordinate of the last touch point.
*
* Note: `pmouseX` is reset to the current mouseX
* value at the start of each touch event.
*/
declare const pmouseX: number;
declare const __pmouseX: typeof pmouseX;
/**
* A `Number` system variable that tracks the mouse's previous vertical
* position.
*
* `pmouseY` keeps track of the mouse's position relative to the
* top-left corner of the canvas. Its value is
* mouseY from the previous frame. For example, if
* the mouse was 50 pixels from the top edge of the canvas during the last
* frame, then `pmouseY` will be 50.
*
* If touch is used instead of the mouse, then `pmouseY` will hold the
* y-coordinate of the last touch point.
*
* Note: `pmouseY` is reset to the current mouseY
* value at the start of each touch event.
*/
declare const pmouseY: number;
declare const __pmouseY: typeof pmouseY;
/**
* A `Number` variable that tracks the mouse's horizontal position within the
* browser.
*
* `winMouseX` keeps track of the mouse's position relative to the top-left
* corner of the browser window. For example, if the mouse is 50 pixels from
* the left edge of the browser, then `winMouseX` will be 50.
*
* On a touchscreen device, `winMouseX` will hold the x-coordinate of the most
* recent touch point.
*
* Note: Use mouseX to track the mouse’s
* x-coordinate within the canvas.
*/
declare const winMouseX: number;
declare const __winMouseX: typeof winMouseX;
/**
* A `Number` variable that tracks the mouse's vertical position within the
* browser.
*
* `winMouseY` keeps track of the mouse's position relative to the top-left
* corner of the browser window. For example, if the mouse is 50 pixels from
* the top edge of the browser, then `winMouseY` will be 50.
*
* On a touchscreen device, `winMouseY` will hold the y-coordinate of the most
* recent touch point.
*
* Note: Use mouseY to track the mouse’s
* y-coordinate within the canvas.
*/
declare const winMouseY: number;
declare const __winMouseY: typeof winMouseY;
/**
* A `Number` variable that tracks the mouse's previous horizontal position
* within the browser.
*
* `pwinMouseX` keeps track of the mouse's position relative to the top-left
* corner of the browser window. Its value is
* winMouseX from the previous frame. For
* example, if the mouse was 50 pixels from
* the left edge of the browser during the last frame, then `pwinMouseX` will
* be 50.
*
* On a touchscreen device, `pwinMouseX` will hold the x-coordinate of the most
* recent touch point. `pwinMouseX` is reset to the current
* winMouseX value at the start of each touch
* event.
*
* Note: Use pmouseX to track the mouse’s previous
* x-coordinate within the canvas.
*/
declare const pwinMouseX: number;
declare const __pwinMouseX: typeof pwinMouseX;
/**
* A `Number` variable that tracks the mouse's previous vertical position
* within the browser.
*
* `pwinMouseY` keeps track of the mouse's position relative to the top-left
* corner of the browser window. Its value is
* winMouseY from the previous frame. For
* example, if the mouse was 50 pixels from
* the top edge of the browser during the last frame, then `pwinMouseY` will
* be 50.
*
* On a touchscreen device, `pwinMouseY` will hold the y-coordinate of the most
* recent touch point. `pwinMouseY` is reset to the current
* winMouseY value at the start of each touch
* event.
*
* Note: Use pmouseY to track the mouse’s previous
* y-coordinate within the canvas.
*/
declare const pwinMouseY: number;
declare const __pwinMouseY: typeof pwinMouseY;
/**
* An object that tracks the current state of mouse buttons, showing which
* buttons are pressed at any given moment.
*
* The `mouseButton` object has three properties:
*
* - `left`: A boolean indicating whether the left mouse button is pressed.
*
* - `right`: A boolean indicating whether the right mouse button is pressed.
*
* - `center`: A boolean indicating whether the middle mouse button (scroll wheel button) is pressed.
*
* Note: Different browsers may track `mouseButton` differently. See
* MDN
* for more information.
*/
declare const mouseButton: object;
declare const __mouseButton: typeof mouseButton;
/**
* An `Array` of all the current touch points on a touchscreen device.
*
* The `touches` array is empty by default. When the user touches their
* screen, a new touch point is tracked and added to the array. Touch points
* are `Objects` with the following properties:
*
* `// Iterate over the touches array.
* for (let touch of touches) {
* // x-coordinate relative to the top-left
* // corner of the canvas.
* console.log(touch.x);
*
* // y-coordinate relative to the top-left
* // corner of the canvas.
* console.log(touch.y);
*
* // x-coordinate relative to the top-left
* // corner of the browser.
* console.log(touch.winX);
*
* // y-coordinate relative to the top-left
* // corner of the browser.
* console.log(touch.winY);
*
* // ID number
* console.log(touch.id);
* }`
*/
declare const touches: object[];
declare const __touches: typeof touches;
/**
* A `Boolean` system variable that's `true` if the mouse is pressed and
* `false` if not.
*/
declare const mouseIsPressed: boolean;
declare const __mouseIsPressed: typeof mouseIsPressed;
/**
* A `Number` variable that stores the width of the canvas in pixels.
*
* `width`'s default value is 100. Calling
* createCanvas() or
* resizeCanvas() changes the value of
* `width`. Calling noCanvas() sets its value to
* 0.
*/
declare const width: number;
declare const __width: typeof width;
/**
* A `Number` variable that stores the height of the canvas in pixels.
*
* `height`'s default value is 100. Calling
* createCanvas() or
* resizeCanvas() changes the value of
* `height`. Calling noCanvas() sets its value to
* 0.
*/
declare const height: number;
declare const __height: typeof height;
/**
* Turns off the parts of the Friendly Error System (FES) that impact performance.
*
* The FES
* can cause sketches to draw slowly because it does extra work behind the
* scenes. For example, the FES checks the arguments passed to functions,
* which takes time to process. Disabling the FES can significantly improve
* performance by turning off these checks.
*/
declare let disableFriendlyErrors: boolean;
declare let __disableFriendlyErrors: typeof disableFriendlyErrors;
/**
* A system variable that provides direct access to the sketch's
* `<canvas>` element.
*
* The `<canvas>` element provides many specialized features that aren't
* included in the p5.js library. The `drawingContext` system variable
* provides access to these features by exposing the sketch's
* CanvasRenderingContext2D
* object.
*/
declare const drawingContext: CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext;
declare const __drawingContext: typeof drawingContext;
declare const VIDEO: 'video';
declare const __VIDEO: typeof VIDEO;
declare const AUDIO: 'audio';
declare const __AUDIO: typeof AUDIO;
/**
* An array containing the color of each pixel on the canvas.
*
* Colors are stored as numbers representing red, green, blue, and alpha
* (RGBA) values. `pixels` is a one-dimensional array for performance reasons.
*
* Each pixel occupies four elements in the `pixels` array, one for each RGBA
* value. For example, the pixel at coordinates (0, 0) stores its RGBA values
* at `pixels[0]`, `pixels[1]`, `pixels[2]`, and `pixels[3]`, respectively.
* The next pixel at coordinates (1, 0) stores its RGBA values at `pixels[4]`,
* `pixels[5]`, `pixels[6]`, and `pixels[7]`. And so on. The `pixels` array
* for a 100×100 canvas has 100 × 100 × 4 = 40,000 elements.
*
* Some displays use several smaller pixels to set the color at a single
* point. The pixelDensity() function returns
* the pixel density of the canvas. High density displays often have a
* pixelDensity() of 2. On such a display, the
* `pixels` array for a 100×100 canvas has 200 × 200 × 4 =
* 160,000 elements.
*
* Accessing the RGBA values for a point on the canvas requires a little math
* as shown below. The loadPixels() function
* must be called before accessing the `pixels` array. The
* updatePixels() function must be called
* after any changes are made.
*/
declare const pixels: number[];
declare const __pixels: typeof pixels;
/**
* A `String` constant that's used to set the
* angleMode().
*
* By default, functions such as rotate() and
* sin() expect angles measured in units of radians.
* Calling `angleMode(DEGREES)` ensures that angles are measured in units of
* degrees.
*
* Note: `TWO_PI` radians equals 360˚.
*/
declare const DEGREES: 'degrees';
declare const __DEGREES: typeof DEGREES;
/**
* A `String` constant that's used to set the
* angleMode().
*
* By default, functions such as rotate() and
* sin() expect angles measured in units of radians.
* Calling `angleMode(RADIANS)` ensures that angles are measured in units of
* radians. Doing so can be useful if the
* angleMode() has been set to
* DEGREES.
*
* Note: `TWO_PI` radians equals 360˚.
*/
declare const RADIANS: 'radians';
declare const __RADIANS: typeof RADIANS;
declare class p5 {
constructor(sketch?: (p: p5) => void, node?: HTMLElement, sync?: boolean);
/**
* Loads a p5.js library.
*
* A library is a function that adds functionality to p5.js by adding methods
* and properties for sketches to use, or for automatically running code at
* different stages of the p5.js lifecycle. Take a look at the
* contributor docs for creating libraries
* to learn more about creating libraries.
* @param library The library function to register
*/
static registerAddon(library: Function): void;
/**
* Creates a screen reader-accessible description of the canvas.
*
* The first parameter, `text`, is the description of the canvas.
*
* The second parameter, `display`, is optional. It determines how the
* description is displayed. If `LABEL` is passed, as in
* `describe('A description.', LABEL)`, the description will be visible in
* a div element next to the canvas. If `FALLBACK` is passed, as in
* `describe('A description.', FALLBACK)`, the description will only be
* visible to screen readers. This is the default mode.
*
* Read
* Writing accessible canvas descriptions
* to learn more about making sketches accessible.
* @param text description of the canvas.
* @param display either LABEL or FALLBACK.
*/
describe(text: string, display?: typeof p5.FALLBACK | typeof p5.LABEL): void;
/**
* Creates a screen reader-accessible description of elements in the canvas.
*
* Elements are shapes or groups of shapes that create meaning together. For
* example, a few overlapping circles could make an "eye" element.
*
* The first parameter, `name`, is the name of the element.
*
* The second parameter, `text`, is the description of the element.
*
* The third parameter, `display`, is optional. It determines how the
* description is displayed. If `LABEL` is passed, as in
* `describe('A description.', LABEL)`, the description will be visible in
* a div element next to the canvas. Using `LABEL` creates unhelpful
* duplicates for screen readers. Only use `LABEL` during development. If
* `FALLBACK` is passed, as in `describe('A description.', FALLBACK)`, the
* description will only be visible to screen readers. This is the default
* mode.
*
* Read
* Writing accessible canvas descriptions
* to learn more about making sketches accessible.
* @param name name of the element.
* @param text description of the element.
* @param display either LABEL or FALLBACK.
*/
describeElement(name: string, text: string, display?: typeof p5.FALLBACK | typeof p5.LABEL): void;
/**
* Creates a screen reader-accessible description of shapes on the canvas.
*
* `textOutput()` adds a general description, list of shapes, and
* table of shapes to the web page. The general description includes the
* canvas size, canvas color, and number of shapes. For example,
* `Your output is a, 100 by 100 pixels, gray canvas containing the following 2 shapes:`.
*
* A list of shapes follows the general description. The list describes the
* color, location, and area of each shape. For example,
* `a red circle at middle covering 3% of the canvas`. Each shape can be
* selected to get more details.
*
* `textOutput()` uses its table of shapes as a list. The table describes the
* shape, color, location, coordinates and area. For example,
* `red circle location = middle area = 3%`. This is different from
* gridOutput(), which uses its table as a grid.
*
* The `display` parameter is optional. It determines how the description is
* displayed. If `LABEL` is passed, as in `textOutput(LABEL)`, the description
* will be visible in a div element next to the canvas. Using `LABEL` creates
* unhelpful duplicates for screen readers. Only use `LABEL` during
* development. If `FALLBACK` is passed, as in `textOutput(FALLBACK)`, the
* description will only be visible to screen readers. This is the default
* mode.
*
* Read
* Writing accessible canvas descriptions
* to learn more about making sketches accessible.
* @param display either FALLBACK or LABEL.
*/
textOutput(display?: typeof p5.FALLBACK | typeof p5.LABEL): void;
/**
* Creates a screen reader-accessible description of shapes on the canvas.
*
* `gridOutput()` adds a general description, table of shapes, and list of
* shapes to the web page. The general description includes the canvas size,
* canvas color, and number of shapes. For example,
* `gray canvas, 100 by 100 pixels, contains 2 shapes: 1 circle 1 square`.
*
* `gridOutput()` uses its table of shapes as a grid. Each shape in the grid
* is placed in a cell whose row and column correspond to the shape's location
* on the canvas. The grid cells describe the color and type of shape at that
* location. For example, `red circle`. These descriptions can be selected
* individually to get more details. This is different from
* textOutput(), which uses its table as a list.
*
* A list of shapes follows the table. The list describes the color, type,
* location, and area of each shape. For example,
* `red circle, location = middle, area = 3 %`.
*
* The `display` parameter is optional. It determines how the description is
* displayed. If `LABEL` is passed, as in `gridOutput(LABEL)`, the description
* will be visible in a div element next to the canvas. Using `LABEL` creates
* unhelpful duplicates for screen readers. Only use `LABEL` during
* development. If `FALLBACK` is passed, as in `gridOutput(FALLBACK)`, the
* description will only be visible to screen readers. This is the default
* mode.
*
* Read
* Writing accessible canvas descriptions
* to learn more about making sketches accessible.
* @param display either FALLBACK or LABEL.
*/
gridOutput(display?: typeof p5.FALLBACK | typeof p5.LABEL): void;
/**
* Removes the sketch from the web page.
*
* Calling `remove()` stops the draw loop and removes any HTML elements
* created by the sketch, including the canvas. A new sketch can be
* created by using the p5() constructor, as in
* `new p5()`.
*/
remove(): void;
remove(): void;
remove(): void;
remove(): void;
/**
* Creates a new sketch in "instance" mode.
*
* All p5.js sketches are instances of the `p5` class. Put another way, all
* p5.js sketches are objects with methods including `pInst.setup()`,
* `pInst.draw()`, `pInst.circle()`, and `pInst.fill()`. By default, sketches
* run in "global mode" to hide some of this complexity.
*
* In global mode, a default instance of the `p5` class is created
* automatically. The default `p5` instance searches the web page's source
* code for declarations of system functions such as `setup()`, `draw()`,
* and `mousePressed()`, then attaches those functions to itself as methods.
* Calling a function such as `circle()` in global mode actually calls the
* default `p5` object's `pInst.circle()` method.
*
* It's often helpful to isolate the code within sketches from the rest of the
* code on a web page. Two common use cases are web pages that use other
* JavaScript libraries and web pages with multiple sketches. "Instance mode"
* makes it easy to support both of these scenarios.
*
* Instance mode sketches support the same API as global mode sketches. They
* use a function to bundle, or encapsulate, an entire sketch. The function
* containing the sketch is then passed to the `p5()` constructor.
*
* The first parameter, `sketch`, is a function that contains the sketch. For
* example, the statement `new p5(mySketch)` would create a new instance mode
* sketch from a function named `mySketch`. The function should have one
* parameter, `p`, that's a `p5` object.
*
* The second parameter, `node`, is optional. If a string is passed, as in
* `new p5(mySketch, 'sketch-one')` the new instance mode sketch will become a
* child of the HTML element with the id `sketch-one`. If an HTML element is
* passed, as in `new p5(mySketch, myElement)`, then the new instance mode
* sketch will become a child of the `Element` object called `myElement`.
* @param sketch function containing the sketch.
* @param node ID or reference to the HTML element that will contain the sketch.
*/
p5(sketch: object, node: string | HTMLElement): void;
/**
* Creates a p5.Color object.
*
* By default, the parameters are interpreted as RGB values. Calling
* `color(255, 204, 0)` will return a bright yellow color. The way these
* parameters are interpreted may be changed with the
* colorMode() function.
*
* The version of `color()` with one parameter interprets the value one of two
* ways. If the parameter is a number, it's interpreted as a grayscale value.
* If the parameter is a string, it's interpreted as a CSS color string.
*
* The version of `color()` with two parameters interprets the first one as a
* grayscale value. The second parameter sets the alpha (transparency) value.
*
* The version of `color()` with three parameters interprets them as RGB, HSB,
* or HSL colors, depending on the current `colorMode()`.
*
* The version of `color()` with four parameters interprets them as RGBA, HSBA,
* or HSLA colors, depending on the current `colorMode()`. The last parameter
* sets the alpha (transparency) value.
* @param gray number specifying value between white and black.
* @param alpha alpha value relative to current color range
* (default is 0-255).
* @returns resulting color.
*/
color(gray: number, alpha?: number): p5.Color;
color(v1: number, v2: number, v3: number, alpha?: number): p5.Color;
color(value: string): p5.Color;
color(values: number[]): p5.Color;
color(color: p5.Color): p5.Color;
/**
* Gets the red value of a color.
*
* `red()` extracts the red value from a
* p5.Color object, an array of color components, or
* a CSS color string.
*
* By default, `red()` returns a color's red value in the range 0
* to 255. If the colorMode() is set to RGB, it
* returns the red value in the given range.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the red value.
*/
red(color: p5.Color | number[] | string): number;
/**
* Gets the green value of a color.
*
* `green()` extracts the green value from a
* p5.Color object, an array of color components, or
* a CSS color string.
*
* By default, `green()` returns a color's green value in the range 0
* to 255. If the colorMode() is set to RGB, it
* returns the green value in the given range.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the green value.
*/
green(color: p5.Color | number[] | string): number;
/**
* Gets the blue value of a color.
*
* `blue()` extracts the blue value from a
* p5.Color object, an array of color components, or
* a CSS color string.
*
* By default, `blue()` returns a color's blue value in the range 0
* to 255. If the colorMode() is set to RGB, it
* returns the blue value in the given range.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the blue value.
*/
blue(color: p5.Color | number[] | string): number;
/**
* Gets the alpha (transparency) value of a color.
*
* `alpha()` extracts the alpha value from a
* p5.Color object, an array of color components, or
* a CSS color string.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the alpha value.
*/
alpha(color: p5.Color | number[] | string): number;
/**
* Gets the hue value of a color.
*
* `hue()` extracts the hue value from a
* p5.Color object, an array of color components, or
* a CSS color string.
*
* Hue describes a color's position on the color wheel. By default, `hue()`
* returns a color's HSL hue in the range 0 to 360. If the
* colorMode() is set to HSB or HSL, it returns the hue
* value in the given mode.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the hue value.
*/
hue(color: p5.Color | number[] | string): number;
/**
* Gets the saturation value of a color.
*
* `saturation()` extracts the saturation value from a
* p5.Color object, an array of color components, or
* a CSS color string.
*
* Saturation is scaled differently in HSB and HSL. By default, `saturation()`
* returns a color's HSL saturation in the range 0 to 100. If the
* colorMode() is set to HSB or HSL, it returns the
* saturation value in the given mode.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the saturation value
*/
saturation(color: p5.Color | number[] | string): number;
/**
* Gets the brightness value of a color.
*
* `brightness()` extracts the HSB brightness value from a
* p5.Color object, an array of color components, or
* a CSS color string.
*
* By default, `brightness()` returns a color's HSB brightness in the range 0
* to 100. If the colorMode() is set to HSB, it
* returns the brightness value in the given range.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the brightness value.
*/
brightness(color: p5.Color | number[] | string): number;
/**
* Gets the lightness value of a color.
*
* `lightness()` extracts the HSL lightness value from a
* p5.Color object, an array of color components, or
* a CSS color string.
*
* By default, `lightness()` returns a color's HSL lightness in the range 0
* to 100. If the colorMode() is set to HSL, it
* returns the lightness value in the given range.
* @param color p5.Color object, array of
* color components, or CSS color string.
* @returns the lightness value.
*/
lightness(color: p5.Color | number[] | string): number;
/**
* Blends two colors to find a third color between them.
*
* The `amt` parameter specifies the amount to interpolate between the two
* values. 0 is equal to the first color, 0.1 is very near the first color,
* 0.5 is halfway between the two colors, and so on. Negative numbers are set
* to 0. Numbers greater than 1 are set to 1. This differs from the behavior of
* lerp. It's necessary because numbers outside of the
* interval [0, 1] will produce strange and unexpected colors.
*
* The way that colors are interpolated depends on the current
* colorMode().
* @param c1 interpolate from this color.
* @param c2 interpolate to this color.
* @param amt number between 0 and 1.
* @returns interpolated color.
*/
lerpColor(c1: p5.Color, c2: p5.Color, amt: number): p5.Color;
/**
* Blends multiple colors to find a color between them.
*
* The `amt` parameter specifies the amount to interpolate between the color
* stops which are colors at each `amt` value "location" with `amt` values
* that are between 2 color stops interpolating between them based on its relative
* distance to both.
*
* The way that colors are interpolated depends on the current
* colorMode().
* @param colors_stops color stops to interpolate from
* @param amt number to use to interpolate relative to color stops
* @returns interpolated color.
*/
paletteLerp(colors_stops: [p5.Color | string | number | number[], number][], amt: number): p5.Color;
/**
* Starts defining a shape that will mask any shapes drawn afterward.
*
* Any shapes drawn between `beginClip()` and
* endClip() will add to the mask shape. The mask
* will apply to anything drawn after endClip().
*
* The parameter, `options`, is optional. If an object with an `invert`
* property is passed, as in `beginClip({ invert: true })`, it will be used to
* set the masking mode. `{ invert: true }` inverts the mask, creating holes
* in shapes that are masked. `invert` is `false` by default.
*
* Masks can be contained between the
* push() and pop() functions.
* Doing so allows unmasked shapes to be drawn after masked shapes.
*
* Masks can also be defined in a callback function that's passed to
* clip().
* @param options an object containing clip settings.
*/
beginClip(options?: { invert?: boolean }): void;
/**
* Ends defining a mask that was started with
* beginClip().
*/
endClip(): void;
/**
* Defines a shape that will mask any shapes drawn afterward.
*
* The first parameter, `callback`, is a function that defines the mask.
* Any shapes drawn in `callback` will add to the mask shape. The mask
* will apply to anything drawn after `clip()` is called.
*
* The second parameter, `options`, is optional. If an object with an `invert`
* property is passed, as in `beginClip({ invert: true })`, it will be used to
* set the masking mode. `{ invert: true }` inverts the mask, creating holes
* in shapes that are masked. `invert` is `false` by default.
*
* Masks can be contained between the
* push() and pop() functions.
* Doing so allows unmasked shapes to be drawn after masked shapes.
*
* Masks can also be defined with beginClip()
* and endClip().
* @param callback a function that draws the mask shape.
* @param options an object containing clip settings.
*/
clip(callback: Function, options?: { invert?: boolean }): void;
/**
* Sets the color used for the background of the canvas.
*
* By default, the background is transparent. `background()` is typically used
* within draw() to clear the display window at the
* beginning of each frame. It can also be used inside
* setup() to set the background on the first frame
* of animation.
*
* The version of `background()` with one parameter interprets the value one
* of four ways. If the parameter is a `Number`, it's interpreted as a grayscale
* value. If the parameter is a `String`, it's interpreted as a CSS color string.
* RGB, RGBA, HSL, HSLA, hex, and named color strings are supported. If the
* parameter is a p5.Color object, it will be used as
* the background color. If the parameter is a
* p5.Image object, it will be used as the background
* image.
*
* The version of `background()` with two parameters interprets the first one
* as a grayscale value. The second parameter sets the alpha (transparency)
* value.
*
* The version of `background()` with three parameters interprets them as RGB,
* HSB, or HSL colors, depending on the current
* colorMode(). By default, colors are specified
* in RGB values. Calling `background(255, 204, 0)` sets the background a bright
* yellow color.
*
* The version of `background()` with four parameters interprets them as RGBA,
* HSBA, or HSLA colors, depending on the current
* colorMode(). The last parameter sets the alpha
* (transparency) value.
* @param color any value created by the color() function
*/
background(color: p5.Color): void;
background(colorstring: string, a?: number): void;
background(gray: number, a?: number): void;
background(v1: number, v2: number, v3: number, a?: number): void;
background(values: number[]): void;
background(image: p5.Image, a?: number): void;
/**
* Clears the pixels on the canvas.
*
* `clear()` makes every pixel 100% transparent. Calling `clear()` doesn't
* clear objects created by `createX()` functions such as
* createGraphics(),
* createVideo(), and
* createImg(). These objects will remain
* unchanged after calling `clear()` and can be redrawn.
*
* In WebGL mode, this function can clear the screen to a specific color. It
* interprets four numeric parameters as normalized RGBA color values. It also
* clears the depth buffer. If you are not using the WebGL renderer, these
* parameters will have no effect.
* @param r normalized red value.
* @param g normalized green value.
* @param b normalized blue value.
* @param a normalized alpha value.
*/
clear(r?: number, g?: number, b?: number, a?: number): void;
clear(): void;
/**
* Changes the way color values are interpreted.
*
* By default, the `Number` parameters for fill(),
* stroke(),
* background(), and
* color() are defined by values between 0 and 255
* using the RGB color model. This is equivalent to calling
* `colorMode(RGB, 255)`. Pure red is `color(255, 0, 0)` in this model.
*
* Calling `colorMode(RGB, 100)` sets colors to use RGB color values
* between 0 and 100. Pure red is `color(100, 0, 0)` in this model.
*
* Calling `colorMode(HSB)` or `colorMode(HSL)` changes to HSB or HSL systems instead of RGB.
* Pure red is `color(0, 100, 100)` in HSB and `color(0, 100, 50)` in HSL.
*
* Some additional color modes that p5.js supports are:
*
* `RGBHDR` - High Dynamic Range RGB defined within the Display P3 color space.
* Colors are expressed with an extended dynamic range. To render these colors
* accurately, you must use the HDR canvas.
*
* `HWB` - Hue, Whiteness, Blackness.
* Similar to HSB and HSL, this mode uses a hue angle.
* Instead of saturation and lightness, HWB defines colors based on the percentage
* of whiteness and blackness. This is the color model used by Chrome's GUI color picker.
* Pure red in HWB is represented as `color(0, 0, 0)` (i.e., hue 0 with 0% whiteness and 0% blackness).
*
* ` ``LAB` - Also known as CIE Lab, this color mode defines colors with Lightness, Alpha, and Beta.
* It is widely used in professional color measurement contexts due to its perceptual uniformity.
*
* `LCH` - A more intuitive representation of the CIE Lab color space using Lightness, Chroma, and Hue.
* This mode separates the color's chromatic intensity (chroma) from its lightness,
* simplifying color selection and manipulation.
*
* `OKLAB` - A variant of the CIE Lab color space that corrects for non-uniformities inherent in LAB.
* The adjustment provides a more perceptually accurate and uniform representation,
* which is particularly beneficial for smooth color transitions.
*
* `OKLCH` - An easier-to-use representation of OKLAB, expressing colors in terms of Lightness, Chroma, and Hue.
* This mode retains the perceptual benefits of OKLAB while offering a more intuitive format for color manipulation.
*
* p5.Color objects remember the mode that they were
* created in. Changing modes doesn't affect their appearance.
*
* `Single-value (Grayscale) Colors`:
* When a color is specified with only one parameter (e.g., `color(g)`), p5.js will interpret it
* as a grayscale color. However, how that single parameter translates into a grayscale value
* depends on the color mode:
*
* - `RGB, HSB, and HSL`: In RGB, the single value is interpreted using the “blue” maximum
* (i.e., the single parameter is mapped to the blue channel's max).
* In HSB and HSL, the single value is mapped to Brightness and Lightness max respectively with hue=0 .
* and saturation=0.
*
* - `LAB, LCH, OKLAB, and OKLCH`: The single value is taken to be the `lightness (L)` component,
* with the specified max range for that channel.
*
* - `HWB`: Grayscale relies on both the `whiteness (W)` and `blackness (B)` channels. Since
* a single value cannot directly account for two distinct channels, the library uses an
* average of their max values to interpret the single grayscale parameter. For instance,
* if W has a max of 50 and B has a max of 100, then the single grayscale parameter
* is mapped using (50 + 100) / 2 = 75 as its effective maximum. More complex or negative
* ranges are currently not handled, so results in those cases may be ambiguous.
* @param mode either RGB, HSB, HSL,
* or one of the extended modes described above.
* @param max range for all values.
* @returns The current color mode.
*/
colorMode(mode: typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH, max?: number): typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH;
colorMode(mode: typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH, max1: number, max2: number, max3: number, maxA?: number): typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH;
colorMode(): typeof p5.RGB | typeof p5.HSB | typeof p5.HSL | typeof p5.RGBHDR | typeof p5.HWB | typeof p5.LAB | typeof p5.LCH | typeof p5.OKLAB | typeof p5.OKLCH;
/**
* Sets the color used to fill shapes.
*
* Calling `fill(255, 165, 0)` or `fill('orange')` means all shapes drawn
* after the fill command will be filled with the color orange.
*
* The version of `fill()` with one parameter interprets the value one of
* three ways. If the parameter is a `Number`, it's interpreted as a grayscale
* value. If the parameter is a `String`, it's interpreted as a CSS color
* string. A p5.Color object can also be provided to
* set the fill color.
*
* The version of `fill()` with three parameters interprets them as RGB, HSB,
* or HSL colors, depending on the current
* colorMode(). The default color space is RGB,
* with each value in the range from 0 to 255.
*
* The version of `fill()` with four parameters interprets them as `RGBA`, `HSBA`,
* or `HSLA` colors, depending on the current colorMode(). The last parameter
* sets the alpha (transparency) value.
* @param v1 red value if color mode is RGB or hue value if color mode is HSB.
* @param v2 green value if color mode is RGB or saturation value if color mode is HSB.
* @param v3 blue value if color mode is RGB or brightness value if color mode is HSB.
* @param alpha alpha value, controls transparency (0 - transparent, 255 - opaque).
*/
fill(v1: number, v2: number, v3: number, alpha?: number): void;
fill(value: string): void;
fill(gray: number, alpha?: number): void;
fill(values: number[]): void;
fill(color: p5.Color): void;
/**
* Disables setting the fill color for shapes.
*
* Calling `noFill()` is the same as making the fill completely transparent,
* as in `fill(0, 0)`. If both noStroke() and
* `noFill()` are called, nothing will be drawn to the screen.
*/
noFill(): void;
/**
* Disables drawing points, lines, and the outlines of shapes.
*
* Calling `noStroke()` is the same as making the stroke completely transparent,
* as in `stroke(0, 0)`. If both `noStroke()` and
* noFill() are called, nothing will be drawn to the
* screen.
*/
noStroke(): void;
/**
* Sets the color used to draw points, lines, and the outlines of shapes.
*
* Calling `stroke(255, 165, 0)` or `stroke('orange')` means all shapes drawn
* after calling `stroke()` will be outlined with the color orange. The way
* these parameters are interpreted may be changed with the
* colorMode() function.
*
* The version of `stroke()` with one parameter interprets the value one of
* three ways. If the parameter is a `Number`, it's interpreted as a grayscale
* value. If the parameter is a `String`, it's interpreted as a CSS color
* string. A p5.Color object can also be provided to
* set the stroke color.
*
* The version of `stroke()` with two parameters interprets the first one as a
* grayscale value. The second parameter sets the alpha (transparency) value.
*
* The version of `stroke()` with three parameters interprets them as RGB, HSB,
* or HSL colors, depending on the current `colorMode()`.
*
* The version of `stroke()` with four parameters interprets them as RGBA, HSBA,
* or HSLA colors, depending on the current `colorMode()`. The last parameter
* sets the alpha (transparency) value.
* @param v1 red value if color mode is RGB or hue value if color mode is HSB.
* @param v2 green value if color mode is RGB or saturation value if color mode is HSB.
* @param v3 blue value if color mode is RGB or brightness value if color mode is HSB.
* @param alpha alpha value, controls transparency (0 - transparent, 255 - opaque).
*/
stroke(v1: number, v2: number, v3: number, alpha?: number): void;
stroke(value: string): void;
stroke(gray: number, alpha?: number): void;
stroke(values: number[]): void;
stroke(color: p5.Color): void;
/**
* Starts using shapes to erase parts of the canvas.
*
* All drawing that follows `erase()` will subtract from the canvas, revealing
* the web page underneath. The erased areas will become transparent, allowing
* the content behind the canvas to show through. The
* fill(), stroke(), and
* blendMode() have no effect once `erase()` is
* called.
*
* The `erase()` function has two optional parameters. The first parameter
* sets the strength of erasing by the shape's interior. A value of 0 means
* that no erasing will occur. A value of 255 means that the shape's interior
* will fully erase the content underneath. The default value is 255
* (full strength).
*
* The second parameter sets the strength of erasing by the shape's edge. A
* value of 0 means that no erasing will occur. A value of 255 means that the
* shape's edge will fully erase the content underneath. The default value is
* 255 (full strength).
*
* To cancel the erasing effect, use the noErase()
* function.
*
* `erase()` has no effect on drawing done with the
* image() and
* background() functions.
* @param strengthFill a number (0-255) for the strength of erasing under a shape's interior.
* Defaults to 255, which is full strength.
* @param strengthStroke a number (0-255) for the strength of erasing under a shape's edge.
* Defaults to 255, which is full strength.
*/
erase(strengthFill?: number, strengthStroke?: number): void;
/**
* Ends erasing that was started with erase().
*
* The fill(), stroke(), and
* blendMode() settings will return to what they
* were prior to calling erase().
*/
noErase(): void;
/**
* Sets the way colors blend when added to the canvas.
*
* By default, drawing with a solid color paints over the current pixel values
* on the canvas. `blendMode()` offers many options for blending colors.
*
* Shapes, images, and text can be used as sources for drawing to the canvas.
* A source pixel changes the color of the canvas pixel where it's drawn. The
* final color results from blending the source pixel's color with the canvas
* pixel's color. RGB color values from the source and canvas pixels are
* compared, added, subtracted, multiplied, and divided to create different
* effects. Red values with red values, greens with greens, and blues with
* blues.
*
* The parameter, `mode`, sets the blend mode. For example, calling
* `blendMode(ADD)` sets the blend mode to `ADD`. The following blend modes
* are available in both 2D and WebGL mode:
*
* - `BLEND`: color values from the source overwrite the canvas. This is the default mode.
*
* - `ADD`: color values from the source are added to values from the canvas.
*
* - `DARKEST`: keeps the darkest color value.
*
* - `LIGHTEST`: keeps the lightest color value.
*
* - `EXCLUSION`: similar to `DIFFERENCE` but with less contrast.
*
* - `MULTIPLY`: color values from the source are multiplied with values from the canvas. The result is always darker.
*
* - `SCREEN`: all color values are inverted, then multiplied, then inverted again. The result is always lighter. (Opposite of `MULTIPLY`)
*
* - `REPLACE`: the last source drawn completely replaces the rest of the canvas.
*
* - `REMOVE`: overlapping pixels are removed by making them completely transparent.
*
* The following blend modes are only available in 2D mode:
*
* - `DIFFERENCE`: color values from the source are subtracted from the values from the canvas. If the difference is a negative number, it's made positive.
*
* - `OVERLAY`: combines `MULTIPLY` and `SCREEN`. Dark values in the canvas get darker and light values get lighter.
*
* - `HARD_LIGHT`: combines `MULTIPLY` and `SCREEN`. Dark values in the source get darker and light values get lighter.
*
* - `SOFT_LIGHT`: a softer version of `HARD_LIGHT`.
*
* - `DODGE`: lightens light tones and increases contrast. Divides the canvas color values by the inverted color values from the source.
*
* - `BURN`: darkens dark tones and increases contrast. Divides the source color values by the inverted color values from the canvas, then inverts the result.
*
* The following blend modes are only available in WebGL mode:
*
* - `SUBTRACT`: RGB values from the source are subtracted from the values from the canvas. If the difference is a negative number, it's made positive. Alpha (transparency) values from the source and canvas are added.
* @param mode blend mode to set.
* either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY,
* EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,
* SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT
*/
blendMode(mode: typeof p5.BLEND | typeof p5.DARKEST | typeof p5.LIGHTEST | typeof p5.DIFFERENCE | typeof p5.MULTIPLY | typeof p5.EXCLUSION | typeof p5.SCREEN | typeof p5.REPLACE | typeof p5.OVERLAY | typeof p5.HARD_LIGHT | typeof p5.SOFT_LIGHT | typeof p5.DODGE | typeof p5.BURN | typeof p5.ADD | typeof p5.REMOVE | typeof p5.SUBTRACT): void;
/**
* Displays text in the web browser's console.
*
* `print()` is helpful for printing values while debugging. Each call to
* `print()` creates a new line of text.
*
* Note: Call `print('\n')` to print a blank line. Calling `print()` without
* an argument opens the browser's dialog for printing documents.
* @param contents content to print to the console.
*/
print(contents: any): void;
print(data: string | number | any[]): void;
/**
* Changes the cursor's appearance.
*
* The first parameter, `type`, sets the type of cursor to display. The
* built-in options are `ARROW`, `CROSS`, `HAND`, `MOVE`, `TEXT`, and `WAIT`.
* `cursor()` also recognizes standard CSS cursor properties passed as
* strings: `'help'`, `'wait'`, `'crosshair'`, `'not-allowed'`, `'zoom-in'`,
* and `'grab'`. If the path to an image is passed, as in
* `cursor('assets/target.png')`, then the image will be used as the cursor.
* Images must be in .cur, .gif, .jpg, .jpeg, or .png format and should be at most 32 by 32 pixels large.
*
* The parameters `x` and `y` are optional. If an image is used for the
* cursor, `x` and `y` set the location pointed to within the image. They are
* both 0 by default, so the cursor points to the image's top-left corner. `x`
* and `y` must be less than the image's width and height, respectively.
* @param type Built-in: either ARROW, CROSS, HAND, MOVE, TEXT, or WAIT.
* Native CSS properties: 'grab', 'progress', and so on.
* Path to cursor image.
* @param x horizontal active spot of the cursor.
* @param y vertical active spot of the cursor.
*/
cursor(type: typeof p5.ARROW | typeof p5.CROSS | typeof p5.HAND | typeof p5.MOVE | typeof p5.TEXT | typeof p5.WAIT | string, x?: number, y?: number): void;
/**
* Sets the number of frames to draw per second.
*
* Calling `frameRate()` with one numeric argument, as in `frameRate(30)`,
* attempts to draw 30 frames per second (FPS). The target frame rate may not
* be achieved depending on the sketch's processing needs. Most computers
* default to a frame rate of 60 FPS. Frame rates of 24 FPS and above are
* fast enough for smooth animations.
*
* Calling `frameRate()` without an argument returns the current frame rate.
* The value returned is an approximation.
* @param fps number of frames to draw per second.
* @returns current frame rate.
*/
frameRate(fps: number): number;
frameRate(): number;
/**
* Returns the target frame rate.
*
* The value is either the system frame rate or the last value passed to
* frameRate().
* @returns _targetFrameRate
*/
getTargetFrameRate(): number;
/**
* Hides the cursor from view.
*/
noCursor(): void;
/**
* A function that's called when the browser window is resized.
*
* Code placed in the body of `windowResized()` will run when the
* browser window's size changes. It's a good place to call
* resizeCanvas() or make other
* adjustments to accommodate the new window size.
*
* The `event` parameter is optional. If added to the function declaration, it
* can be used for debugging or other purposes.
* @param event optional resize Event.
*/
windowResized(event?: Event): void;
/**
* Toggles full-screen mode or returns the current mode.
*
* Calling `fullscreen(true)` makes the sketch full-screen. Calling
* `fullscreen(false)` makes the sketch its original size.
*
* Calling `fullscreen()` without an argument returns `true` if the sketch
* is in full-screen mode and `false` if not.
*
* Note: Due to browser restrictions, `fullscreen()` can only be called with
* user input such as a mouse press.
* @param val whether the sketch should be in fullscreen mode.
* @returns current fullscreen state.
*/
fullscreen(val?: boolean): boolean;
/**
* Sets the pixel density or returns the current density.
*
* Computer displays are grids of little lights called pixels. A
* display's pixel density describes how many pixels it packs into an
* area. Displays with smaller pixels have a higher pixel density and create
* sharper images.
*
* `pixelDensity()` sets the pixel scaling for high pixel density displays.
* By default, the pixel density is set to match the display's density.
* Calling `pixelDensity(1)` turn this off.
*
* Calling `pixelDensity()` without an argument returns the current pixel
* density.
* @param val desired pixel density.
* @returns current pixel density of the sketch.
*/
pixelDensity(val?: number): number;
pixelDensity(): number;
/**
* Returns the display's current pixel density.
* @returns current pixel density of the display.
*/
displayDensity(): number;
/**
* Returns the sketch's current
* URL
* as a `String`.
* @returns url
*/
getURL(): string;
/**
* Returns the current
* URL
* path as an `Array` of `String`s.
*
* For example, consider a sketch hosted at the URL
* `https://example.com/sketchbook`. Calling `getURLPath()` returns
* `['sketchbook']`. For a sketch hosted at the URL
* `https://example.com/sketchbook/monday`, `getURLPath()` returns
* `['sketchbook', 'monday']`.
* @returns path components.
*/
getURLPath(): string[];
/**
* Returns the current
* URL parameters
* in an `Object`.
*
* For example, calling `getURLParams()` in a sketch hosted at the URL
* `https://p5js.org?year=2014&month=May&day=15` returns
* `{ year: 2014, month: 'May', day: 15 }`.
* @returns URL params
*/
getURLParams(): object;
/**
* Converts 3D world coordinates to 2D screen coordinates.
*
* This function takes a 3D vector and converts its coordinates
* from the world space to screen space. This can be useful for placing
* 2D elements in a 3D scene or for determining the screen position
* of 3D objects.
* @param x The x coordinate in world space. (Or a vector for all three coordinates.)
* @param y The y coordinate in world space.
* @param z The z coordinate in world space.
* @returns A vector containing the 2D screen coordinates.
*/
worldToScreen(x: number | p5.Vector, y: number, z?: number): p5.Vector;
/**
* Converts 2D screen coordinates to 3D world coordinates.
*
* This function takes a vector and converts its coordinates from coordinates
* on the screen to coordinates in the currently drawn object. This can be
* useful for determining the mouse position relative to a 2D or 3D object.
*
* If given, the Z component of the input coordinates is treated as "depth",
* or distance from the camera.
* @param x The x coordinate in screen space. (Or a vector for all three coordinates.)
* @param y The y coordinate in screen space.
* @param z The z coordinate in screen space.
* @returns A vector containing the 3D world space coordinates.
*/
screenToWorld(x: number | p5.Vector, y: number, z?: number): p5.Vector;
/**
* A function that's called once when the sketch begins running.
*
* Declaring the function `setup()` sets a code block to run once
* automatically when the sketch starts running. It's used to perform
* setup tasks such as creating the canvas and initializing variables:
*
* `function setup() {
* // Code to run once at the start of the sketch.
* }`Code placed in `setup()` will run once before code placed in
* draw() begins looping.
* If `setup()` is declared `async` (e.g. `async function setup()`),
* execution pauses at each `await` until its promise resolves.
* For example, `font = await loadFont(...)` waits for the font asset
* to load because `loadFont()` function returns a promise, and the await
* keyword means the program will wait for the promise to resolve.
* This ensures that all assets are fully loaded before the sketch continues.
*
* loading assets.
*
* Note: `setup()` doesn’t have to be declared, but it’s common practice to do so.
*/
setup(): void;
/**
* A function that's called repeatedly while the sketch runs.
*
* Declaring the function `draw()` sets a code block to run repeatedly
* once the sketch starts. It’s used to create animations and respond to
* user inputs:
*
* `function draw() {
* // Code to run repeatedly.
* }`This is often called the "draw loop" because p5.js calls the code in
* `draw()` in a loop behind the scenes. By default, `draw()` tries to run
* 60 times per second. The actual rate depends on many factors. The
* drawing rate, called the "frame rate", can be controlled by calling
* frameRate(). The number of times `draw()`
* has run is stored in the system variable
* frameCount().
*
* Code placed within `draw()` begins looping after
* setup() runs. `draw()` will run until the user
* closes the sketch. `draw()` can be stopped by calling the
* noLoop() function. `draw()` can be resumed by
* calling the loop() function.
*/
draw(): void;
/**
* Creates a canvas element on the web page.
*
* `createCanvas()` creates the main drawing canvas for a sketch. It should
* only be called once at the beginning of setup().
* Calling `createCanvas()` more than once causes unpredictable behavior.
*
* The first two parameters, `width` and `height`, are optional. They set the
* dimensions of the canvas and the values of the
* width and height system
* variables. For example, calling `createCanvas(900, 500)` creates a canvas
* that's 900×500 pixels. By default, `width` and `height` are both 100.
*
* The third parameter is also optional. If either of the constants `P2D` or
* `WEBGL` is passed, as in `createCanvas(900, 500, WEBGL)`, then it will set
* the sketch's rendering mode. If an existing
* HTMLCanvasElement
* is passed, as in `createCanvas(900, 500, myCanvas)`, then it will be used
* by the sketch.
*
* The fourth parameter is also optional. If an existing
* HTMLCanvasElement
* is passed, as in `createCanvas(900, 500, WEBGL, myCanvas)`, then it will be
* used by the sketch.
*
* Note: In WebGL mode, the canvas will use a WebGL2 context if it's supported
* by the browser. Check the webglVersion
* system variable to check what version is being used, or call
* `setAttributes({ version: 1 })` to create a WebGL1 context.
* @param width width of the canvas. Defaults to 100.
* @param height height of the canvas. Defaults to 100.
* @param renderer either P2D or WEBGL. Defaults to `P2D`.
* @param canvas existing canvas element that should be used for the sketch.
* @returns new `p5.Renderer` that holds the canvas.
*/
createCanvas(width?: number, height?: number, renderer?: typeof p5.P2D | typeof p5.WEBGL | typeof p5.P2DHDR, canvas?: HTMLCanvasElement): p5.Renderer;
createCanvas(width?: number, height?: number, canvas?: HTMLCanvasElement): p5.Renderer;
/**
* Resizes the canvas to a given width and height.
*
* `resizeCanvas()` immediately clears the canvas and calls
* redraw(). It's common to call `resizeCanvas()`
* within the body of windowResized() like
* so:
*
* `function windowResized() {
* resizeCanvas(windowWidth, windowHeight);
* }`The first two parameters, `width` and `height`, set the dimensions of the
* canvas. They also the values of the width and
* height system variables. For example, calling
* `resizeCanvas(300, 500)` resizes the canvas to 300×500 pixels, then sets
* width to 300 and
* height 500.
*
* The third parameter, `noRedraw`, is optional. If `true` is passed, as in
* `resizeCanvas(300, 500, true)`, then the canvas will be canvas to 300×500
* pixels but the redraw() function won't be called
* immediately. By default, redraw() is called
* immediately when `resizeCanvas()` finishes executing.
* @param width width of the canvas.
* @param height height of the canvas.
* @param noRedraw whether to delay calling
* redraw(). Defaults
* to `false`.
*/
resizeCanvas(width: number, height: number, noRedraw?: boolean): void;
/**
* Removes the default canvas.
*
* By default, a 100×100 pixels canvas is created without needing to call
* createCanvas(). `noCanvas()` removes the
* default canvas for sketches that don't need it.
*/
noCanvas(): void;
/**
* Creates a p5.Graphics object.
*
* `createGraphics()` creates an offscreen drawing canvas (graphics buffer)
* and returns it as a p5.Graphics object. Drawing
* to a separate graphics buffer can be helpful for performance and for
* organizing code.
*
* The first two parameters, `width` and `height`, are optional. They set the
* dimensions of the p5.Graphics object. For
* example, calling `createGraphics(900, 500)` creates a graphics buffer
* that's 900×500 pixels.
*
* The third parameter is also optional. If either of the constants `P2D` or
* `WEBGL` is passed, as in `createGraphics(900, 500, WEBGL)`, then it will set
* the p5.Graphics object's rendering mode. If an
* existing
* HTMLCanvasElement
* is passed, as in `createGraphics(900, 500, myCanvas)`, then it will be used
* by the graphics buffer.
*
* The fourth parameter is also optional. If an existing
* HTMLCanvasElement
* is passed, as in `createGraphics(900, 500, WEBGL, myCanvas)`, then it will be
* used by the graphics buffer.
*
* Note: In WebGL mode, the p5.Graphics object
* will use a WebGL2 context if it's supported by the browser. Check the
* webglVersion system variable to check what
* version is being used, or call `setAttributes({ version: 1 })` to create a
* WebGL1 context.
* @param width width of the graphics buffer.
* @param height height of the graphics buffer.
* @param renderer either P2D or WEBGL. Defaults to P2D.
* @param canvas existing canvas element that should be
* used for the graphics buffer..
* @returns new graphics buffer.
*/
createGraphics(width: number, height: number, renderer?: typeof p5.P2D | typeof p5.WEBGL, canvas?: HTMLCanvasElement): p5.Graphics;
createGraphics(width: number, height: number, canvas?: HTMLCanvasElement): p5.Graphics;
/**
* Creates and a new p5.Framebuffer object.
*
* p5.Framebuffer objects are separate drawing
* surfaces that can be used as textures in WebGL mode. They're similar to
* p5.Graphics objects and generally run much
* faster when used as textures.
*
* The parameter, `options`, is optional. An object can be passed to configure
* the p5.Framebuffer object. The available
* properties are:
*
* - `format`: data format of the texture, either `UNSIGNED_BYTE`, `FLOAT`, or `HALF_FLOAT`. Default is `UNSIGNED_BYTE`.
*
* - `channels`: whether to store `RGB` or `RGBA` color channels. Default is to match the main canvas which is `RGBA`.
*
* - `depth`: whether to include a depth buffer. Default is `true`.
*
* - `depthFormat`: data format of depth information, either `UNSIGNED_INT` or `FLOAT`. Default is `FLOAT`.
*
* - `stencil`: whether to include a stencil buffer for masking. `depth` must be `true` for this feature to work. Defaults to the value of `depth` which is `true`.
*
* - `antialias`: whether to perform anti-aliasing. If set to `true`, as in `{ antialias: true }`, 2 samples will be used by default. The number of samples can also be set, as in `{ antialias: 4 }`. Default is to match setAttributes() which is `false` (`true` in Safari).
*
* - `width`: width of the p5.Framebuffer object. Default is to always match the main canvas width.
*
* - `height`: height of the p5.Framebuffer object. Default is to always match the main canvas height.
*
* - `density`: pixel density of the p5.Framebuffer object. Default is to always match the main canvas pixel density.
*
* - `textureFiltering`: how to read values from the p5.Framebuffer object. Either `LINEAR` (nearby pixels will be interpolated) or `NEAREST` (no interpolation). Generally, use `LINEAR` when using the texture as an image and `NEAREST` if reading the texture as data. Default is `LINEAR`.
*
* If the `width`, `height`, or `density` attributes are set, they won't automatically match the main canvas and must be changed manually.
*
* Note: `createFramebuffer()` can only be used in WebGL mode.
* @param options configuration options.
* @returns new framebuffer.
*/
createFramebuffer(options?: { format?: typeof p5.UNSIGNED_BYTE | typeof p5.FLOAT | typeof p5.HALF_FLOAT; channels?: typeof p5.RGB | typeof p5.RGBA; depth?: boolean; depthFormat?: typeof p5.UNSIGNED_INT | typeof p5.FLOAT; stencil?: boolean; antialias?: boolean | number; width?: number; height?: number; density?: number; textureFiltering?: typeof p5.LINEAR | typeof p5.NEAREST }): p5.Framebuffer;
/**
* Clears the depth buffer in WebGL mode.
*
* `clearDepth()` clears information about how far objects are from the camera
* in 3D space. This information is stored in an object called the
* depth buffer. Clearing the depth buffer ensures new objects aren't drawn
* behind old ones. Doing so can be useful for feedback effects in which the
* previous frame serves as the background for the current frame.
*
* The parameter, `depth`, is optional. If a number is passed, as in
* `clearDepth(0.5)`, it determines the range of objects to clear from the
* depth buffer. 0 doesn't clear any depth information, 0.5 clears depth
* information halfway between the near and far clipping planes, and 1 clears
* depth information all the way to the far clipping plane. By default,
* `depth` is 1.
*
* Note: `clearDepth()` can only be used in WebGL mode.
* @param depth amount of the depth buffer to clear between 0
* (none) and 1 (far clipping plane). Defaults to 1.
*/
clearDepth(depth?: number): void;
/**
* Stops the code in draw() from running repeatedly.
*
* By default, draw() tries to run 60 times per
* second. Calling `noLoop()` stops draw() from
* repeating. The draw loop can be restarted by calling
* loop(). draw() can be run
* once by calling redraw().
*
* The isLooping() function can be used to check
* whether a sketch is looping, as in `isLooping() === true`.
*/
noLoop(): void;
/**
* Resumes the draw loop after noLoop() has been
* called.
*
* By default, draw() tries to run 60 times per
* second. Calling noLoop() stops
* draw() from repeating. The draw loop can be
* restarted by calling `loop()`.
*
* The isLooping() function can be used to check
* whether a sketch is looping, as in `isLooping() === true`.
*/
loop(): void;
/**
* Returns `true` if the draw loop is running and `false` if not.
*
* By default, draw() tries to run 60 times per
* second. Calling noLoop() stops
* draw() from repeating. The draw loop can be
* restarted by calling loop().
*
* The `isLooping()` function can be used to check whether a sketch is
* looping, as in `isLooping() === true`.
*/
isLooping(): boolean;
/**
* Runs the code in draw() once.
*
* By default, draw() tries to run 60 times per
* second. Calling noLoop() stops
* draw() from repeating. Calling `redraw()` will
* execute the code in the draw() function a set
* number of times. `await` the result of `redraw` to make sure it has finished.
*
* The parameter, `n`, is optional. If a number is passed, as in `redraw(5)`,
* then the draw loop will run the given number of times. By default, `n` is
* 1.
* @param n number of times to run draw(). Defaults to 1.
*/
redraw(n?: number): Promise;
/**
* Applies a transformation matrix to the coordinate system.
*
* Transformations such as
* translate(),
* rotate(), and
* scale()
* use matrix-vector multiplication behind the scenes. A table of numbers,
* called a matrix, encodes each transformation. The values in the matrix
* then multiply each point on the canvas, which is represented by a vector.
*
* `applyMatrix()` allows for many transformations to be applied at once. See
* Wikipedia
* and MDN
* for more details about transformations.
*
* There are two ways to call `applyMatrix()` in two and three dimensions.
*
* In 2D mode, the parameters `a`, `b`, `c`, `d`, `e`, and `f`, correspond to
* elements in the following transformation matrix:
*
*
*
* The numbers can be passed individually, as in
* `applyMatrix(2, 0, 0, 0, 2, 0)`. They can also be passed in an array, as in
* `applyMatrix([2, 0, 0, 0, 2, 0])`.
*
* In 3D mode, the parameters `a`, `b`, `c`, `d`, `e`, `f`, `g`, `h`, `i`,
* `j`, `k`, `l`, `m`, `n`, `o`, and `p` correspond to elements in the
* following transformation matrix:
*
*
*
* The numbers can be passed individually, as in
* `applyMatrix(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1)`. They can
* also be passed in an array, as in
* `applyMatrix([2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1])`.
*
* By default, transformations accumulate. The
* push() and pop() functions
* can be used to isolate transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `applyMatrix()` inside the draw() function won't
* cause shapes to transform continuously.
* @param arr an array containing the elements of the transformation matrix. Its length should be either 6 (2D) or 16 (3D).
*/
applyMatrix(arr: number[]): void;
applyMatrix(a: number, b: number, c: number, d: number, e: number, f: number): void;
applyMatrix(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number): void;
/**
* Clears all transformations applied to the coordinate system.
*/
resetMatrix(): void;
/**
* Rotates the coordinate system.
*
* By default, the positive x-axis points to the right and the positive y-axis
* points downward. The `rotate()` function changes this orientation by
* rotating the coordinate system about the origin. Everything drawn after
* `rotate()` is called will appear to be rotated.
*
* The first parameter, `angle`, is the amount to rotate. For example, calling
* `rotate(1)` rotates the coordinate system clockwise 1 radian which is
* nearly 57˚. `rotate()` interprets angle values using the current
* angleMode().
*
* The second parameter, `axis`, is optional. It's used to orient 3D rotations
* in WebGL mode. If a p5.Vector is passed, as in
* `rotate(QUARTER_PI, myVector)`, then the coordinate system will rotate
* `QUARTER_PI` radians about `myVector`. If an array of vector components is
* passed, as in `rotate(QUARTER_PI, [1, 0, 0])`, then the coordinate system
* will rotate `QUARTER_PI` radians about a vector with the components
* `[1, 0, 0]`.
*
* By default, transformations accumulate. For example, calling `rotate(1)`
* twice has the same effect as calling `rotate(2)` once. The
* push() and pop() functions
* can be used to isolate transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `rotate(1)` inside the draw() function won't cause
* shapes to spin.
* @param angle angle of rotation in the current angleMode().
* @param axis axis to rotate about in 3D.
*/
rotate(angle: number, axis?: p5.Vector | number[]): void;
/**
* Rotates the coordinate system about the x-axis in WebGL mode.
*
* The parameter, `angle`, is the amount to rotate. For example, calling
* `rotateX(1)` rotates the coordinate system about the x-axis by 1 radian.
* `rotateX()` interprets angle values using the current
* angleMode().
*
* By default, transformations accumulate. For example, calling `rotateX(1)`
* twice has the same effect as calling `rotateX(2)` once. The
* push() and pop() functions
* can be used to isolate transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `rotateX(1)` inside the draw() function won't cause
* shapes to spin.
* @param angle angle of rotation in the current angleMode().
*/
rotateX(angle: number): void;
/**
* Rotates the coordinate system about the y-axis in WebGL mode.
*
* The parameter, `angle`, is the amount to rotate. For example, calling
* `rotateY(1)` rotates the coordinate system about the y-axis by 1 radian.
* `rotateY()` interprets angle values using the current
* angleMode().
*
* By default, transformations accumulate. For example, calling `rotateY(1)`
* twice has the same effect as calling `rotateY(2)` once. The
* push() and pop() functions
* can be used to isolate transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `rotateY(1)` inside the draw() function won't cause
* shapes to spin.
* @param angle angle of rotation in the current angleMode().
*/
rotateY(angle: number): void;
/**
* Rotates the coordinate system about the z-axis in WebGL mode.
*
* The parameter, `angle`, is the amount to rotate. For example, calling
* `rotateZ(1)` rotates the coordinate system about the z-axis by 1 radian.
* `rotateZ()` interprets angle values using the current
* angleMode().
*
* By default, transformations accumulate. For example, calling `rotateZ(1)`
* twice has the same effect as calling `rotateZ(2)` once. The
* push() and pop() functions
* can be used to isolate transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `rotateZ(1)` inside the draw() function won't cause
* shapes to spin.
* @param angle angle of rotation in the current angleMode().
*/
rotateZ(angle: number): void;
/**
* Scales the coordinate system.
*
* By default, shapes are drawn at their original scale. A rectangle that's 50
* pixels wide appears to take up half the width of a 100 pixel-wide canvas.
* The `scale()` function can shrink or stretch the coordinate system so that
* shapes appear at different sizes. There are two ways to call `scale()` with
* parameters that set the scale factor(s).
*
* The first way to call `scale()` uses numbers to set the amount of scaling.
* The first parameter, `s`, sets the amount to scale each axis. For example,
* calling `scale(2)` stretches the x-, y-, and z-axes by a factor of 2. The
* next two parameters, `y` and `z`, are optional. They set the amount to
* scale the y- and z-axes. For example, calling `scale(2, 0.5, 1)` stretches
* the x-axis by a factor of 2, shrinks the y-axis by a factor of 0.5, and
* leaves the z-axis unchanged.
*
* The second way to call `scale()` uses a p5.Vector
* object to set the scale factors. For example, calling `scale(myVector)`
* uses the x-, y-, and z-components of `myVector` to set the amount of
* scaling along the x-, y-, and z-axes. Doing so is the same as calling
* `scale(myVector.x, myVector.y, myVector.z)`.
*
* By default, transformations accumulate. For example, calling `scale(1)`
* twice has the same effect as calling `scale(2)` once. The
* push() and pop() functions
* can be used to isolate transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `scale(2)` inside the draw() function won't cause
* shapes to grow continuously.
* @param s amount to scale along the positive x-axis.
* @param y amount to scale along the positive y-axis. Defaults to `s`.
* @param z amount to scale along the positive z-axis. Defaults to `y`.
*/
scale(s: number | p5.Vector | number[], y?: number, z?: number): void;
scale(scales: p5.Vector | number[]): void;
/**
* Shears the x-axis so that shapes appear skewed.
*
* By default, the x- and y-axes are perpendicular. The `shearX()` function
* transforms the coordinate system so that x-coordinates are translated while
* y-coordinates are fixed.
*
* The first parameter, `angle`, is the amount to shear. For example, calling
* `shearX(1)` transforms all x-coordinates using the formula
* `x = x + y * tan(angle)`. `shearX()` interprets angle values using the
* current angleMode().
*
* By default, transformations accumulate. For example, calling
* `shearX(1)` twice has the same effect as calling `shearX(2)` once. The
* push() and
* pop() functions can be used to isolate
* transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `shearX(1)` inside the draw() function won't
* cause shapes to shear continuously.
* @param angle angle to shear by in the current angleMode().
*/
shearX(angle: number): void;
/**
* Shears the y-axis so that shapes appear skewed.
*
* By default, the x- and y-axes are perpendicular. The `shearY()` function
* transforms the coordinate system so that y-coordinates are translated while
* x-coordinates are fixed.
*
* The first parameter, `angle`, is the amount to shear. For example, calling
* `shearY(1)` transforms all y-coordinates using the formula
* `y = y + x * tan(angle)`. `shearY()` interprets angle values using the
* current angleMode().
*
* By default, transformations accumulate. For example, calling
* `shearY(1)` twice has the same effect as calling `shearY(2)` once. The
* push() and
* pop() functions can be used to isolate
* transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `shearY(1)` inside the draw() function won't
* cause shapes to shear continuously.
* @param angle angle to shear by in the current angleMode().
*/
shearY(angle: number): void;
/**
* Translates the coordinate system.
*
* By default, the origin `(0, 0)` is at the sketch's top-left corner in 2D
* mode and center in WebGL mode. The `translate()` function shifts the origin
* to a different position. Everything drawn after `translate()` is called
* will appear to be shifted. There are two ways to call `translate()` with
* parameters that set the origin's position.
*
* The first way to call `translate()` uses numbers to set the amount of
* translation. The first two parameters, `x` and `y`, set the amount to
* translate along the positive x- and y-axes. For example, calling
* `translate(20, 30)` translates the origin 20 pixels along the x-axis and 30
* pixels along the y-axis. The third parameter, `z`, is optional. It sets the
* amount to translate along the positive z-axis. For example, calling
* `translate(20, 30, 40)` translates the origin 20 pixels along the x-axis,
* 30 pixels along the y-axis, and 40 pixels along the z-axis.
*
* The second way to call `translate()` uses a
* p5.Vector object to set the amount of
* translation. For example, calling `translate(myVector)` uses the x-, y-,
* and z-components of `myVector` to set the amount to translate along the x-,
* y-, and z-axes. Doing so is the same as calling
* `translate(myVector.x, myVector.y, myVector.z)`.
*
* By default, transformations accumulate. For example, calling
* `translate(10, 0)` twice has the same effect as calling
* `translate(20, 0)` once. The push() and
* pop() functions can be used to isolate
* transformations within distinct drawing groups.
*
* Note: Transformations are reset at the beginning of the draw loop. Calling
* `translate(10, 0)` inside the draw() function won't
* cause shapes to move continuously.
* @param x amount to translate along the positive x-axis.
* @param y amount to translate along the positive y-axis.
* @param z amount to translate along the positive z-axis.
*/
translate(x: number, y: number, z?: number): void;
translate(vector: p5.Vector): void;
/**
* Begins a drawing group that contains its own styles and transformations.
*
* By default, styles such as fill() and
* transformations such as rotate() are applied to
* all drawing that follows. The `push()` and pop()
* functions can limit the effect of styles and transformations to a specific
* group of shapes, images, and text. For example, a group of shapes could be
* translated to follow the mouse without affecting the rest of the sketch:
*
* `// Begin the drawing group.
* push();
*
* // Translate the origin to the mouse's position.
* translate(mouseX, mouseY);
*
* // Style the face.
* noStroke();
* fill('green');
*
* // Draw the face.
* circle(0, 0, 60);
*
* // Style the eyes.
* fill('white');
*
* // Draw the left eye.
* ellipse(-20, -20, 30, 20);
*
* // Draw the right eye.
* ellipse(20, -20, 30, 20);
*
* // End the drawing group.
* pop();
*
* // Draw a bug.
* let x = random(0, 100);
* let y = random(0, 100);
* text('🦟', x, y);`In the code snippet above, the bug's position isn't affected by
* `translate(mouseX, mouseY)` because that transformation is contained
* between `push()` and pop(). The bug moves around
* the entire canvas as expected.
*
* Note: `push()` and pop() are always called as a
* pair. Both functions are required to begin and end a drawing group.
*
* `push()` and pop() can also be nested to create
* subgroups. For example, the code snippet above could be changed to give
* more detail to the frog’s eyes:
*
* `// Begin the drawing group.
* push();
*
* // Translate the origin to the mouse's position.
* translate(mouseX, mouseY);
*
* // Style the face.
* noStroke();
* fill('green');
*
* // Draw a face.
* circle(0, 0, 60);
*
* // Style the eyes.
* fill('white');
*
* // Draw the left eye.
* push();
* translate(-20, -20);
* ellipse(0, 0, 30, 20);
* fill('black');
* circle(0, 0, 8);
* pop();
*
* // Draw the right eye.
* push();
* translate(20, -20);
* ellipse(0, 0, 30, 20);
* fill('black');
* circle(0, 0, 8);
* pop();
*
* // End the drawing group.
* pop();
*
* // Draw a bug.
* let x = random(0, 100);
* let y = random(0, 100);
* text('🦟', x, y);`In this version, the code to draw each eye is contained between its own
* `push()` and pop() functions. Doing so makes it
* easier to add details in the correct part of a drawing.
*
* `push()` and pop() contain the effects of the
* following functions:
*
* - fill()
*
* - noFill()
*
* - noStroke()
*
* - stroke()
*
* - tint()
*
* - noTint()
*
* - strokeWeight()
*
* - strokeCap()
*
* - strokeJoin()
*
* - imageMode()
*
* - rectMode()
*
* - ellipseMode()
*
* - colorMode()
*
* - textAlign()
*
* - textFont()
*
* - textSize()
*
* - textLeading()
*
* - applyMatrix()
*
* - resetMatrix()
*
* - rotate()
*
* - scale()
*
* - shearX()
*
* - shearY()
*
* - translate()
*
* In WebGL mode, `push()` and pop() contain the
* effects of a few additional styles:
*
* - setCamera()
*
* - ambientLight()
*
* - directionalLight()
*
* - pointLight()texture()
*
* - specularMaterial()
*
* - shininess()
*
* - normalMaterial()
*
* - shader()
*/
push(): void;
/**
* Ends a drawing group that contains its own styles and transformations.
*
* By default, styles such as fill() and
* transformations such as rotate() are applied to
* all drawing that follows. The push() and `pop()`
* functions can limit the effect of styles and transformations to a specific
* group of shapes, images, and text. For example, a group of shapes could be
* translated to follow the mouse without affecting the rest of the sketch:
*
* `// Begin the drawing group.
* push();
*
* // Translate the origin to the mouse's position.
* translate(mouseX, mouseY);
*
* // Style the face.
* noStroke();
* fill('green');
*
* // Draw the face.
* circle(0, 0, 60);
*
* // Style the eyes.
* fill('white');
*
* // Draw the left eye.
* ellipse(-20, -20, 30, 20);
*
* // Draw the right eye.
* ellipse(20, -20, 30, 20);
*
* // End the drawing group.
* pop();
*
* // Draw a bug.
* let x = random(0, 100);
* let y = random(0, 100);
* text('🦟', x, y);`In the code snippet above, the bug's position isn't affected by
* `translate(mouseX, mouseY)` because that transformation is contained
* between push() and `pop()`. The bug moves around
* the entire canvas as expected.
*
* Note: push() and `pop()` are always called as a
* pair. Both functions are required to begin and end a drawing group.
*
* push() and `pop()` can also be nested to create
* subgroups. For example, the code snippet above could be changed to give
* more detail to the frog’s eyes:
*
* `// Begin the drawing group.
* push();
*
* // Translate the origin to the mouse's position.
* translate(mouseX, mouseY);
*
* // Style the face.
* noStroke();
* fill('green');
*
* // Draw a face.
* circle(0, 0, 60);
*
* // Style the eyes.
* fill('white');
*
* // Draw the left eye.
* push();
* translate(-20, -20);
* ellipse(0, 0, 30, 20);
* fill('black');
* circle(0, 0, 8);
* pop();
*
* // Draw the right eye.
* push();
* translate(20, -20);
* ellipse(0, 0, 30, 20);
* fill('black');
* circle(0, 0, 8);
* pop();
*
* // End the drawing group.
* pop();
*
* // Draw a bug.
* let x = random(0, 100);
* let y = random(0, 100);
* text('🦟', x, y);`In this version, the code to draw each eye is contained between its own
* push() and `pop()` functions. Doing so makes it
* easier to add details in the correct part of a drawing.
*
* push() and `pop()` contain the effects of the
* following functions:
*
* - fill()
*
* - noFill()
*
* - noStroke()
*
* - stroke()
*
* - tint()
*
* - noTint()
*
* - strokeWeight()
*
* - strokeCap()
*
* - strokeJoin()
*
* - imageMode()
*
* - rectMode()
*
* - ellipseMode()
*
* - colorMode()
*
* - textAlign()
*
* - textFont()
*
* - textSize()
*
* - textLeading()
*
* - applyMatrix()
*
* - resetMatrix()
*
* - rotate()
*
* - scale()
*
* - shearX()
*
* - shearY()
*
* - translate()
*
* In WebGL mode, push() and `pop()` contain the
* effects of a few additional styles:
*
* - setCamera()
*
* - ambientLight()
*
* - directionalLight()
*
* - pointLight()texture()
*
* - specularMaterial()
*
* - shininess()
*
* - normalMaterial()
*
* - shader()
*/
pop(): void;
/**
* Stores a value in the web browser's local storage.
*
* Web browsers can save small amounts of data using the built-in
* localStorage object.
* Data stored in `localStorage` can be retrieved at any point, even after
* refreshing a page or restarting the browser. Data are stored as key-value
* pairs.
*
* `storeItem()` makes it easy to store values in `localStorage` and
* getItem() makes it easy to retrieve them.
*
* The first parameter, `key`, is the name of the value to be stored as a
* string.
*
* The second parameter, `value`, is the value to be stored. Values can have
* any type.
*
* Note: Sensitive data such as passwords or personal information shouldn't be
* stored in `localStorage`.
* @param key name of the value.
* @param value value to be stored.
*/
storeItem(key: string, value: string | number | boolean | object | any[]): void;
/**
* Returns a value in the web browser's local storage.
*
* Web browsers can save small amounts of data using the built-in
* localStorage object.
* Data stored in `localStorage` can be retrieved at any point, even after
* refreshing a page or restarting the browser. Data are stored as key-value
* pairs.
*
* storeItem() makes it easy to store values in
* `localStorage` and `getItem()` makes it easy to retrieve them.
*
* The first parameter, `key`, is the name of the value to be stored as a
* string.
*
* The second parameter, `value`, is the value to be retrieved a string. For
* example, calling `getItem('size')` retrieves the value with the key `size`.
*
* Note: Sensitive data such as passwords or personal information shouldn't be
* stored in `localStorage`.
* @param key name of the value.
* @returns stored item.
*/
getItem(key: string): string | number | boolean | object | any[];
/**
* Removes all items in the web browser's local storage.
*
* Web browsers can save small amounts of data using the built-in
* localStorage object.
* Data stored in `localStorage` can be retrieved at any point, even after
* refreshing a page or restarting the browser. Data are stored as key-value
* pairs. Calling `clearStorage()` removes all data from `localStorage`.
*
* Note: Sensitive data such as passwords or personal information shouldn't be
* stored in `localStorage`.
*/
clearStorage(): void;
/**
* Removes an item from the web browser's local storage.
*
* Web browsers can save small amounts of data using the built-in
* localStorage object.
* Data stored in `localStorage` can be retrieved at any point, even after
* refreshing a page or restarting the browser. Data are stored as key-value
* pairs.
*
* storeItem() makes it easy to store values in
* `localStorage` and `removeItem()` makes it easy to delete them.
*
* The parameter, `key`, is the name of the value to remove as a string. For
* example, calling `removeItem('size')` removes the item with the key `size`.
*
* Note: Sensitive data such as passwords or personal information shouldn't be
* stored in `localStorage`.
* @param key name of the value to remove.
*/
removeItem(key: string): void;
/**
* Searches the page for the first element that matches the given
* CSS selector string.
*
* The selector string can be an ID, class, tag name, or a combination.
* `select()` returns a p5.Element object if it
* finds a match and `null` if not.
*
* The second parameter, `container`, is optional. It specifies a container to
* search within. `container` can be CSS selector string, a
* p5.Element object, or an
* HTMLElement object.
* @param selectors CSS selector string of element to search for.
* @param container CSS selector string, p5.Element, or
* HTMLElement to search within.
* @returns p5.Element containing the element.
*/
select(selectors: string, container?: string | p5.Element | HTMLElement): p5.Element | null;
/**
* Searches the page for all elements that matches the given
* CSS selector string.
*
* The selector string can be an ID, class, tag name, or a combination.
* `selectAll()` returns an array of p5.Element
* objects if it finds any matches and an empty array if none are found.
*
* The second parameter, `container`, is optional. It specifies a container to
* search within. `container` can be CSS selector string, a
* p5.Element object, or an
* HTMLElement object.
* @param selectors CSS selector string of element to search for.
* @param container CSS selector string, p5.Element, or
* HTMLElement to search within.
* @returns array of p5.Elements containing any elements found.
*/
selectAll(selectors: string, container?: string | p5.Element | HTMLElement): p5.Element[];
/**
* Creates a new p5.Element object.
*
* The first parameter, `tag`, is a string an HTML tag such as `'h5'`.
*
* The second parameter, `content`, is optional. It's a string that sets the
* HTML content to insert into the new element. New elements have no content
* by default.
* @param tag tag for the new element.
* @param content HTML content to insert into the element.
* @returns new p5.Element object.
*/
createElement(tag: string, content?: string): p5.Element;
/**
* Removes all elements created by p5.js, including any event handlers.
*
* There are two exceptions:
* canvas elements created by createCanvas()
* and p5.Render objects created by
* createGraphics().
*/
removeElements(): void;
/**
* Helpers for create methods.
*/
addElement(): void;
addElement(): void;
/**
* Creates a `<div></div>` element.
*
* `<div></div>` elements are commonly used as containers for
* other elements.
*
* The parameter `html` is optional. It accepts a string that sets the
* inner HTML of the new `<div></div>`.
* @param html inner HTML for the new `<div></div>` element.
* @returns new p5.Element object.
*/
createDiv(html?: string): p5.Element;
/**
* Creates a paragraph element.
*
* `<p></p>` elements are commonly used for paragraph-length text.
*
* The parameter `html` is optional. It accepts a string that sets the
* inner HTML of the new `<p></p>`.
* @param html inner HTML for the new `<p></p>` element.
* @returns new p5.Element object.
*/
createP(html?: string): p5.Element;
/**
* Creates a `<span></span>` element.
*
* `<span></span>` elements are commonly used as containers
* for inline elements. For example, a `<span></span>`
* can hold part of a sentence that's a
* different style.
*
* The parameter `html` is optional. It accepts a string that sets the
* inner HTML of the new `<span></span>`.
* @param html inner HTML for the new `<span></span>` element.
* @returns new p5.Element object.
*/
createSpan(html?: string): p5.Element;
/**
* Creates an `<img>` element that can appear outside of the canvas.
*
* The first parameter, `src`, is a string with the path to the image file.
* `src` should be a relative path, as in `'assets/image.png'`, or a URL, as
* in `'https://example.com/image.png'`.
*
* The second parameter, `alt`, is a string with the
* alternate text
* for the image. An empty string `''` can be used for images that aren't displayed.
*
* The third parameter, `crossOrigin`, is optional. It's a string that sets the
* crossOrigin property
* of the image. Use `'anonymous'` or `'use-credentials'` to fetch the image
* with cross-origin access.
*
* The fourth parameter, `callback`, is also optional. It sets a function to
* call after the image loads. The new image is passed to the callback
* function as a p5.Element object.
* @param src relative path or URL for the image.
* @param alt alternate text for the image.
* @returns new p5.Element object.
*/
createImg(src: string, alt: string): p5.Element;
createImg(src: string, alt: string, crossOrigin?: string, successCallback?: Function): p5.Element;
/**
* Creates an `<a></a>` element that links to another web page.
*
* The first parmeter, `href`, is a string that sets the URL of the linked
* page.
*
* The second parameter, `html`, is a string that sets the inner HTML of the
* link. It's common to use text, images, or buttons as links.
*
* The third parameter, `target`, is optional. It's a string that tells the
* web browser where to open the link. By default, links open in the current
* browser tab. Passing `'_blank'` will cause the link to open in a new
* browser tab. MDN describes a few
* other options.
* @param href URL of linked page.
* @param html inner HTML of link element to display.
* @param target target where the new link should open,
* either `'_blank'`, `'_self'`, `'_parent'`, or `'_top'`.
* @returns new p5.Element object.
*/
createA(href: string, html: string, target?: string): p5.Element;
/**
* Creates a slider `<input></input>` element.
*
* Range sliders are useful for quickly selecting numbers from a given range.
*
* The first two parameters, `min` and `max`, are numbers that set the
* slider's minimum and maximum.
*
* The third parameter, `value`, is optional. It's a number that sets the
* slider's default value.
*
* The fourth parameter, `step`, is also optional. It's a number that sets the
* spacing between each value in the slider's range. Setting `step` to 0
* allows the slider to move smoothly from `min` to `max`.
* @param min minimum value of the slider.
* @param max maximum value of the slider.
* @param value default value of the slider.
* @param step size for each step in the slider's range.
* @returns new p5.Element object.
*/
createSlider(min: number, max: number, value?: number, step?: number): p5.Element;
/**
* Creates a `<button></button>` element.
*
* The first parameter, `label`, is a string that sets the label displayed on
* the button.
*
* The second parameter, `value`, is optional. It's a string that sets the
* button's value. See
* MDN
* for more details.
* @param label label displayed on the button.
* @param value value of the button.
* @returns new p5.Element object.
*/
createButton(label: string, value?: string): p5.Element;
/**
* Creates a checkbox `<input></input>` element.
*
* Checkboxes extend the p5.Element class with a
* `checked()` method. Calling `myBox.checked()` returns `true` if it the box
* is checked and `false` if not.
*
* The first parameter, `label`, is optional. It's a string that sets the label
* to display next to the checkbox.
*
* The second parameter, `value`, is also optional. It's a boolean that sets the
* checkbox's value.
* @param label label displayed after the checkbox.
* @param value value of the checkbox. Checked is `true` and unchecked is `false`.
* @returns new p5.Element object.
*/
createCheckbox(label?: string, value?: boolean): p5.Element;
/**
* Creates a dropdown menu `<select></select>` element.
*
* The parameter is optional. If `true` is passed, as in
* `let mySelect = createSelect(true)`, then the dropdown will support
* multiple selections. If an existing `<select></select>` element
* is passed, as in `let mySelect = createSelect(otherSelect)`, the existing
* element will be wrapped in a new p5.Element
* object.
*
* Dropdowns extend the p5.Element class with a few
* helpful methods for managing options:
*
* - `mySelect.option(name, [value])` adds an option to the menu. The first paremeter, `name`, is a string that sets the option's name and value. The second parameter, `value`, is optional. If provided, it sets the value that corresponds to the key `name`. If an option with `name` already exists, its value is changed to `value`.
*
* - `mySelect.value()` returns the currently-selected option's value.
*
* - `mySelect.selected()` returns the currently-selected option.
*
* - `mySelect.selected(option)` selects the given option by default.
*
* - `mySelect.disable()` marks the whole dropdown element as disabled.
*
* - `mySelect.disable(option)` marks a given option as disabled.
*
* - `mySelect.enable()` marks the whole dropdown element as enabled.
*
* - `mySelect.enable(option)` marks a given option as enabled.
* @param multiple support multiple selections.
* @returns new p5.Element object.
*/
createSelect(multiple?: boolean): p5.Element;
createSelect(existing: object): p5.Element;
/**
* Creates a radio button element.
*
* The parameter is optional. If a string is passed, as in
* `let myRadio = createSelect('food')`, then each radio option will
* have `"food"` as its `name` parameter: `<input name="food"></input>`.
* If an existing `<div></div>` or `<span></span>`
* element is passed, as in `let myRadio = createSelect(container)`, it will
* become the radio button's parent element.
*
* Radio buttons extend the p5.Element class with a few
* helpful methods for managing options:
*
* - `myRadio.option(value, [label])` adds an option to the menu. The first paremeter, `value`, is a string that sets the option's value and label. The second parameter, `label`, is optional. If provided, it sets the label displayed for the `value`. If an option with `value` already exists, its label is changed and its value is returned.
*
* - `myRadio.value()` returns the currently-selected option's value.
*
* - `myRadio.selected()` returns the currently-selected option.
*
* - `myRadio.selected(value)` selects the given option and returns it as an `HTMLInputElement`.
*
* - `myRadio.disable(shouldDisable)` enables the entire radio button if `true` is passed and disables it if `false` is passed.
* @param containerElement container HTML Element, either a `<div></div>`
* or `<span></span>`.
* @returns new p5.Element object.
*/
createRadio(containerElement?: object): p5.Element;
createRadio(name?: string): p5.Element;
createRadio(): p5.Element;
/**
* Creates a color picker element.
*
* The parameter, `value`, is optional. If a color string or
* p5.Color object is passed, it will set the default
* color.
*
* Color pickers extend the p5.Element class with a
* couple of helpful methods for managing colors:
*
* - `myPicker.value()` returns the current color as a hex string in the format `'#rrggbb'`.
*
* - `myPicker.color()` returns the current color as a p5.Color object.
* @param value default color as a CSS color string.
* @returns new p5.Element object.
*/
createColorPicker(value?: string | p5.Color): p5.Element;
/**
* Creates a text `<input></input>` element.
*
* Call `myInput.size()` to set the length of the text box.
*
* The first parameter, `value`, is optional. It's a string that sets the
* input's default value. The input is blank by default.
*
* The second parameter, `type`, is also optional. It's a string that
* specifies the type of text being input. See MDN for a full
* list of options.
* The default is `'text'`.
* @param value default value of the input box. Defaults to an empty string `''`.
* @param type type of input. Defaults to `'text'`.
* @returns new p5.Element object.
*/
createInput(value?: string, type?: string): p5.Element;
createInput(value?: string): p5.Element;
/**
* Creates an `<input></input>` element of type `'file'`.
*
* `createFileInput()` allows users to select local files for use in a sketch.
* It returns a p5.File object.
*
* The first parameter, `callback`, is a function that's called when the file
* loads. The callback function should have one parameter, `file`, that's a
* p5.File object.
*
* The second parameter, `multiple`, is optional. It's a boolean value that
* allows loading multiple files if set to `true`. If `true`, `callback`
* will be called once per file.
* @param callback function to call once the file loads.
* @param multiple allow multiple files to be selected.
* @returns The new input element.
*/
createFileInput(callback: (input: p5.File) => any, multiple?: boolean): p5.Element;
/**
* Creates a `<video>` element for simple audio/video playback.
*
* `createVideo()` returns a new
* p5.MediaElement object. Videos are shown by
* default. They can be hidden by calling `video.hide()` and drawn to the
* canvas using image().
*
* The first parameter, `src`, is the path the video. If a single string is
* passed, as in `'assets/topsecret.mp4'`, a single video is loaded. An array
* of strings can be used to load the same video in different formats. For
* example, `['assets/topsecret.mp4', 'assets/topsecret.ogv', 'assets/topsecret.webm']`.
* This is useful for ensuring that the video can play across different browsers with
* different capabilities. See
* MDN
* for more information about supported formats.
*
* The second parameter, `callback`, is optional. It's a function to call once
* the video is ready to play.
* @param src path to a video file, or an array of paths for
* supporting different browsers.
* @param callback function to call once the video is ready to play.
* @returns new p5.MediaElement object.
*/
createVideo(src?: string | string[], callback?: (video: p5.MediaElement) => any): p5.MediaElement;
/**
* Creates a hidden `<audio>` element for simple audio playback.
*
* `createAudio()` returns a new
* p5.MediaElement object.
*
* The first parameter, `src`, is the path the audio. If a single string is
* passed, as in `'assets/audio.mp3'`, a single audio is loaded. An array
* of strings can be used to load the same audio in different formats. For
* example, `['assets/audio.mp3', 'assets/video.wav']`.
* This is useful for ensuring that the audio can play across different
* browsers with different capabilities. See
* MDN
* for more information about supported formats.
*
* The second parameter, `callback`, is optional. It's a function to call once
* the audio is ready to play.
* @param src path to an audio file, or an array of paths
* for supporting different browsers.
* @param callback function to call once the audio is ready to play.
* @returns new p5.MediaElement object.
*/
createAudio(src?: string | string[], callback?: (video: p5.MediaElement) => any): p5.MediaElement;
/**
* Creates a `<video>` element that "captures" the audio/video stream from
* the webcam and microphone.
*
* `createCapture()` returns a new
* p5.MediaElement object. Videos are shown by
* default. They can be hidden by calling `capture.hide()` and drawn to the
* canvas using image().
*
* The first parameter, `type`, is optional. It sets the type of capture to
* use. By default, `createCapture()` captures both audio and video. If `VIDEO`
* is passed, as in `createCapture(VIDEO)`, only video will be captured.
* If `AUDIO` is passed, as in `createCapture(AUDIO)`, only audio will be
* captured. A constraints object can also be passed to customize the stream.
* See the
* W3C documentation for possible properties. Different browsers support different
* properties.
*
* The 'flipped' property is an optional property which can be set to `{flipped:true}`
* to mirror the video output.If it is true then it means that video will be mirrored
* or flipped and if nothing is mentioned then by default it will be `false`.
*
* The second parameter,`callback`, is optional. It's a function to call once
* the capture is ready for use. The callback function should have one
* parameter, `stream`, that's a
* MediaStream object.
*
* Note: `createCapture()` only works when running a sketch locally or using HTTPS. Learn more
* here
* and here.
* @param type type of capture, either AUDIO or VIDEO,
* or a constraints object. Both video and audio
* audio streams are captured by default.
* @param flipped flip the capturing video and mirror the output with `{flipped:true}`. By
* default it is false.
* @param callback function to call once the stream
* has loaded.
* @returns new p5.MediaElement object.
*/
createCapture(type?: typeof p5.AUDIO | typeof p5.VIDEO | object, flipped?: object, callback?: Function): p5.MediaElement;
/**
* The setMoveThreshold() function is used to set the movement threshold for
* the deviceMoved() function. The default threshold is set to 0.5.
* @param value The threshold value
*/
setMoveThreshold(value: number): void;
/**
* The setShakeThreshold() function is used to set the movement threshold for
* the deviceShaken() function. The default threshold is set to 30.
* @param value The threshold value
*/
setShakeThreshold(value: number): void;
/**
* The deviceMoved() function is called when the device is moved by more than
* the threshold value along X, Y or Z axis. The default threshold is set to 0.5.
* The threshold value can be changed using setMoveThreshold().
*/
deviceMoved(): void;
/**
* The deviceTurned() function is called when the device rotates by
* more than 90 degrees continuously.
*
* The axis that triggers the deviceTurned() method is stored in the turnAxis
* variable. The deviceTurned() method can be locked to trigger on any axis:
* X, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'.
*/
deviceTurned(): void;
/**
* The deviceShaken() function is called when the device total acceleration
* changes of accelerationX and accelerationY values is more than
* the threshold value. The default threshold is set to 30.
* The threshold value can be changed using setShakeThreshold().
*/
deviceShaken(): void;
/**
* A function that's called once when any key is pressed.
*
* Declaring the function `keyPressed()` sets a code block to run once
* automatically when the user presses any key:
*
* `function keyPressed() {
* // Code to run.
* }`The key and keyCode
* variables will be updated with the most recently typed value when
* `keyPressed()` is called by p5.js:
*
* `function keyPressed() {
* if (key === 'c') {
* // Code to run.
* }
*
* if (keyCode === 13) { // Enter key
* // Code to run.
* }
* }`The parameter, `event`, is optional. `keyPressed()` is always passed a
* KeyboardEvent
* object with properties that describe the key press event:
*
* `function keyPressed(event) {
* // Code to run that uses the event.
* console.log(event);
* }`Browsers may have default behaviors attached to various key events. For
* example, some browsers may jump to the bottom of a web page when the
* `SPACE` key is pressed. To prevent any default behavior for this event, add
* `return false;` to the end of the function.
* @param event optional `KeyboardEvent` callback argument.
*/
keyPressed(event?: KeyboardEvent): void;
/**
* A function that's called once when any key is released.
*
* Declaring the function `keyReleased()` sets a code block to run once
* automatically when the user releases any key:
*
* `function keyReleased() {
* // Code to run.
* }`The key and keyCode
* variables will be updated with the most recently released value when
* `keyReleased()` is called by p5.js:
*
* `function keyReleased() {
* if (key === 'c') {
* // Code to run.
* }
*
* if (keyCode === 13) { // Enter key
* // Code to run.
* }
* }`The parameter, `event`, is optional. `keyReleased()` is always passed a
* KeyboardEvent
* object with properties that describe the key press event:
*
* `function keyReleased(event) {
* // Code to run that uses the event.
* console.log(event);
* }`Browsers may have default behaviors attached to various key events. To
* prevent any default behavior for this event, add `return false;` to the end
* of the function.
* @param event optional `KeyboardEvent` callback argument.
*/
keyReleased(event?: KeyboardEvent): void;
/**
* A function that's called once when keys with printable characters are pressed.
*
* Declaring the function `keyTyped()` sets a code block to run once
* automatically when the user presses any key with a printable character such
* as `a` or 1. Modifier keys such as `SHIFT`, `CONTROL`, and the arrow keys
* will be ignored:
*
* `function keyTyped() {
* // Code to run.
* }`The key and keyCode
* variables will be updated with the most recently released value when
* `keyTyped()` is called by p5.js:
*
* `function keyTyped() {
* // Check for the "c" character using key.
* if (key === 'c') {
* // Code to run.
* }
*
* // Check for "c" using keyCode.
* if (keyCode === 67) { // 67 is the ASCII code for 'c'
* // Code to run.
* }
* }`The parameter, `event`, is optional. `keyTyped()` is always passed a
* KeyboardEvent
* object with properties that describe the key press event:
*
* `function keyReleased(event) {
* // Code to run that uses the event.
* console.log(event);
* }`Note: Use the keyPressed() function and
* keyCode system variable to respond to modifier
* keys such as `ALT`.
*
* Browsers may have default behaviors attached to various key events. To
* prevent any default behavior for this event, add `return false;` to the end
* of the function.
* @param event optional `KeyboardEvent` callback argument.
*/
keyTyped(event?: KeyboardEvent): void;
/**
* Returns `true` if the key it’s checking is pressed and `false` if not.
*
* `keyIsDown()` is helpful when checking for multiple different key presses.
* For example, `keyIsDown()` can be used to check if both `LEFT_ARROW` and
* `UP_ARROW` are pressed:
*
* `if (keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
* // Move diagonally.
* }``keyIsDown()` can check for key presses using strings based on
* KeyboardEvent.key
* or KeyboardEvent.code values,
* such as `keyIsDown('x')` or `keyIsDown('ArrowLeft')`.
*
* Note: In p5.js 2.0 and newer, numeric keycodes (such as 88 for 'X') are no longer supported.
* This is a breaking change from previous versions.
*
* You can still use the p5 constants like `LEFT_ARROW` which now map to string values
* internally rather than numeric codes.
* @param code key to check.
* @returns whether the key is down or not.
*/
keyIsDown(code: number | string): boolean;
/**
* A function that's called when the mouse moves.
*
* Declaring the function `mouseMoved()` sets a code block to run
* automatically when the user moves the mouse without clicking any mouse
* buttons:
*
* `function mouseMoved() {
* // Code to run.
* }`The mouse system variables, such as mouseX and
* mouseY, will be updated with their most recent
* value when `mouseMoved()` is called by p5.js:
*
* `function mouseMoved() {
* if (mouseX < 50) {
* // Code to run if the mouse is on the left.
* }
*
* if (mouseY > 50) {
* // Code to run if the mouse is near the bottom.
* }
* }`The parameter, `event`, is optional. `mouseMoved()` is always passed a
* MouseEvent
* object with properties that describe the mouse move event:
*
* `function mouseMoved(event) {
* // Code to run that uses the event.
* console.log(event);
* }`Browsers may have default behaviors attached to various mouse events. For
* example, some browsers highlight text when the user moves the mouse while
* pressing a mouse button. To prevent any default behavior for this event,
* add `return false;` to the end of the function.
* @param event optional `MouseEvent` argument.
*/
mouseMoved(event?: MouseEvent): void;
/**
* A function that's called when the mouse moves while a button is pressed.
*
* Declaring the function `mouseDragged()` sets a code block to run
* automatically when the user clicks and drags the mouse:
*
* `function mouseDragged() {
* // Code to run.
* }`The mouse system variables, such as mouseX and
* mouseY, will be updated with their most recent
* value when `mouseDragged()` is called by p5.js:
*
* `function mouseDragged() {
* if (mouseX < 50) {
* // Code to run if the mouse is on the left.
* }
*
* if (mouseY > 50) {
* // Code to run if the mouse is near the bottom.
* }
* }`The parameter, `event`, is optional. `mouseDragged()` is always passed a
* MouseEvent
* object with properties that describe the mouse drag event:
*
* `function mouseDragged(event) {
* // Code to run that uses the event.
* console.log(event);
* }`On touchscreen devices, `mouseDragged()` will run when a user moves a touch
* point.
*
* Browsers may have default behaviors attached to various mouse events. For
* example, some browsers highlight text when the user moves the mouse while
* pressing a mouse button. To prevent any default behavior for this event,
* add `return false;` to the end of the function.
* @param event optional `MouseEvent` argument.
*/
mouseDragged(event?: MouseEvent): void;
/**
* A function that's called once when a mouse button is pressed.
*
* Declaring the function `mousePressed()` sets a code block to run
* automatically when the user presses a mouse button:
*
* `function mousePressed() {
* // Code to run.
* }`The mouse system variables, such as mouseX and
* mouseY, will be updated with their most recent
* value when `mousePressed()` is called by p5.js:
*
* `function mousePressed() {
* if (mouseX < 50) {
* // Code to run if the mouse is on the left.
* }
*
* if (mouseY > 50) {
* // Code to run if the mouse is near the bottom.
* }
* }`The parameter, `event`, is optional. `mousePressed()` is always passed a
* MouseEvent
* object with properties that describe the mouse press event:
*
* `function mousePressed(event) {
* // Code to run that uses the event.
* console.log(event);
* }`On touchscreen devices, `mousePressed()` will run when a user’s touch
* begins.
*
* Browsers may have default behaviors attached to various mouse events. For
* example, some browsers highlight text when the user moves the mouse while
* pressing a mouse button. To prevent any default behavior for this event,
* add `return false;` to the end of the function.
*
* Note: `mousePressed()`, mouseReleased(),
* and mouseClicked() are all related.
* `mousePressed()` runs as soon as the user clicks the mouse.
* mouseReleased() runs as soon as the user
* releases the mouse click. mouseClicked()
* runs immediately after mouseReleased().
* @param event optional `MouseEvent` argument.
*/
mousePressed(event?: MouseEvent): void;
/**
* A function that's called once when a mouse button is released.
*
* Declaring the function `mouseReleased()` sets a code block to run
* automatically when the user releases a mouse button after having pressed
* it:
*
* `function mouseReleased() {
* // Code to run.
* }`The mouse system variables, such as mouseX and
* mouseY, will be updated with their most recent
* value when `mouseReleased()` is called by p5.js:
*
* `function mouseReleased() {
* if (mouseX < 50) {
* // Code to run if the mouse is on the left.
* }
*
* if (mouseY > 50) {
* // Code to run if the mouse is near the bottom.
* }
* }`The parameter, `event`, is optional. `mouseReleased()` is always passed a
* MouseEvent
* object with properties that describe the mouse release event:
*
* `function mouseReleased(event) {
* // Code to run that uses the event.
* console.log(event);
* }`On touchscreen devices, `mouseReleased()` will run when a user’s touch
* ends.
*
* Browsers may have default behaviors attached to various mouse events. For
* example, some browsers highlight text when the user moves the mouse while
* pressing a mouse button. To prevent any default behavior for this event,
* add `return false;` to the end of the function.
*
* Note: mousePressed(), `mouseReleased()`,
* and mouseClicked() are all related.
* mousePressed() runs as soon as the user
* clicks the mouse. `mouseReleased()` runs as soon as the user releases the
* mouse click. mouseClicked() runs
* immediately after `mouseReleased()`.
* @param event optional `MouseEvent` argument.
*/
mouseReleased(event?: MouseEvent): void;
/**
* A function that's called once after a mouse button is pressed and released.
*
* Declaring the function `mouseClicked()` sets a code block to run
* automatically when the user releases a mouse button after having pressed
* it:
*
* `function mouseClicked() {
* // Code to run.
* }`The mouse system variables, such as mouseX and
* mouseY, will be updated with their most recent
* value when `mouseClicked()` is called by p5.js:
*
* `function mouseClicked() {
* if (mouseX < 50) {
* // Code to run if the mouse is on the left.
* }
*
* if (mouseY > 50) {
* // Code to run if the mouse is near the bottom.
* }
* }`The parameter, `event`, is optional. `mouseClicked()` is always passed a
* MouseEvent
* object with properties that describe the mouse click event:
*
* `function mouseClicked(event) {
* // Code to run that uses the event.
* console.log(event);
* }`On touchscreen devices, `mouseClicked()` will run when a user’s touch
* ends.
*
* Browsers may have default behaviors attached to various mouse events. For
* example, some browsers highlight text when the user moves the mouse while
* pressing a mouse button. To prevent any default behavior for this event,
* add `return false;` to the end of the function.
*
* Note: mousePressed(),
* mouseReleased(),
* and `mouseClicked()` are all related.
* mousePressed() runs as soon as the user
* clicks the mouse. mouseReleased() runs as
* soon as the user releases the mouse click. `mouseClicked()` runs
* immediately after mouseReleased().
* @param event optional `MouseEvent` argument.
*/
mouseClicked(event?: MouseEvent): void;
/**
* A function that's called once when a mouse button is clicked twice quickly.
*
* Declaring the function `doubleClicked()` sets a code block to run
* automatically when the user presses and releases the mouse button twice
* quickly:
*
* `function doubleClicked() {
* // Code to run.
* }`The mouse system variables, such as mouseX and
* mouseY, will be updated with their most recent
* value when `doubleClicked()` is called by p5.js:
*
* `function doubleClicked() {
* if (mouseX < 50) {
* // Code to run if the mouse is on the left.
* }
*
* if (mouseY > 50) {
* // Code to run if the mouse is near the bottom.
* }
* }`The parameter, `event`, is optional. `doubleClicked()` is always passed a
* MouseEvent
* object with properties that describe the double-click event:
*
* `function doubleClicked(event) {
* // Code to run that uses the event.
* console.log(event);
* }`On touchscreen devices, code placed in `doubleClicked()` will run after two
* touches that occur within a short time.
*
* Browsers may have default behaviors attached to various mouse events. For
* example, some browsers highlight text when the user moves the mouse while
* pressing a mouse button. To prevent any default behavior for this event,
* add `return false;` to the end of the function.
* @param event optional `MouseEvent` argument.
*/
doubleClicked(event?: MouseEvent): void;
/**
* A function that's called once when the mouse wheel moves.
*
* Declaring the function `mouseWheel()` sets a code block to run
* automatically when the user scrolls with the mouse wheel:
*
* `function mouseWheel() {
* // Code to run.
* }`The mouse system variables, such as mouseX and
* mouseY, will be updated with their most recent
* value when `mouseWheel()` is called by p5.js:
*
* `function mouseWheel() {
* if (mouseX < 50) {
* // Code to run if the mouse is on the left.
* }
*
* if (mouseY > 50) {
* // Code to run if the mouse is near the bottom.
* }
* }`The parameter, `event`, is optional. `mouseWheel()` is always passed a
* MouseEvent
* object with properties that describe the mouse scroll event:
*
* `function mouseWheel(event) {
* // Code to run that uses the event.
* console.log(event);
* }`The `event` object has many properties including `delta`, a `Number`
* containing the distance that the user scrolled. For example, `event.delta`
* might have the value 5 when the user scrolls up. `event.delta` is positive
* if the user scrolls up and negative if they scroll down. The signs are
* opposite on macOS with "natural" scrolling enabled.
*
* Browsers may have default behaviors attached to various mouse events. For
* example, some browsers highlight text when the user moves the mouse while
* pressing a mouse button. To prevent any default behavior for this event,
* add `return false;` to the end of the function.
*
* Note: On Safari, `mouseWheel()` may only work as expected if
* `return false;` is added at the end of the function.
* @param event optional `WheelEvent` argument.
*/
mouseWheel(event?: WheelEvent): void;
/**
* Locks the mouse pointer to its current position and makes it invisible.
*
* `requestPointerLock()` allows the mouse to move forever without leaving the
* screen. Calling `requestPointerLock()` locks the values of
* mouseX, mouseY,
* pmouseX, and pmouseY.
* movedX and movedY
* continue updating and can be used to get the distance the mouse moved since
* the last frame was drawn. Calling
* exitPointerLock() resumes updating the
* mouse system variables.
*
* Note: Most browsers require an input, such as a click, before calling
* `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
* an event function such as doubleClicked().
*/
requestPointerLock(): void;
/**
* Exits a pointer lock started with
* requestPointerLock.
*
* Calling `requestPointerLock()` locks the values of
* mouseX, mouseY,
* pmouseX, and pmouseY.
* Calling `exitPointerLock()` resumes updating the mouse system variables.
*
* Note: Most browsers require an input, such as a click, before calling
* `requestPointerLock()`. It’s recommended to call `requestPointerLock()` in
* an event function such as doubleClicked().
*/
exitPointerLock(): void;
/**
* Creates a new p5.Image object.
*
* `createImage()` uses the `width` and `height` parameters to set the new
* p5.Image object's dimensions in pixels. The new
* p5.Image can be modified by updating its
* pixels array or by calling its
* get() and
* set() methods. The
* loadPixels() method must be called
* before reading or modifying pixel values. The
* updatePixels() method must be called
* for updates to take effect.
*
* Note: The new p5.Image object is transparent by
* default.
* @param width width in pixels.
* @param height height in pixels.
* @returns new p5.Image object.
*/
createImage(width: number, height: number): p5.Image;
/**
* Saves the current canvas as an image.
*
* By default, `saveCanvas()` saves the canvas as a PNG image called
* `untitled.png`.
*
* The first parameter, `filename`, is optional. It's a string that sets the
* file's name. If a file extension is included, as in
* `saveCanvas('drawing.png')`, then the image will be saved using that
* format.
*
* The second parameter, `extension`, is also optional. It sets the files format.
* Either `'png'`, `'webp'`, or `'jpg'` can be used. For example, `saveCanvas('drawing', 'jpg')`
* saves the canvas to a file called `drawing.jpg`.
*
* Note: The browser will either save the file immediately or prompt the user
* with a dialogue window.
* @param selectedCanvas reference to a
* specific HTML5 canvas element.
* @param filename file name. Defaults to 'untitled'.
* @param extension file extension, either 'png', 'webp', or 'jpg'. Defaults to 'png'.
*/
saveCanvas(selectedCanvas: p5.Framebuffer | p5.Element | HTMLCanvasElement, filename?: string, extension?: string): void;
saveCanvas(filename?: string, extension?: string): void;
/**
* Captures a sequence of frames from the canvas that can be saved as images.
*
* `saveFrames()` creates an array of frame objects. Each frame is stored as
* an object with its file type, file name, and image data as a string. For
* example, the first saved frame might have the following properties:
*
* `{ ext: 'png', filenmame: 'frame0', imageData: 'data:image/octet-stream;base64, abc123' }`.
*
* The first parameter, `filename`, sets the prefix for the file names. For
* example, setting the prefix to `'frame'` would generate the image files
* `frame0.png`, `frame1.png`, and so on.
*
* The second parameter, `extension`, sets the file type to either `'png'` or
* `'jpg'`.
*
* The third parameter, `duration`, sets the duration to record in seconds.
* The maximum duration is 15 seconds.
*
* The fourth parameter, `framerate`, sets the number of frames to record per
* second. The maximum frame rate value is 22. Limits are placed on `duration`
* and `framerate` to avoid using too much memory. Recording large canvases
* can easily crash sketches or even web browsers.
*
* The fifth parameter, `callback`, is optional. If a function is passed,
* image files won't be saved by default. The callback function can be used
* to process an array containing the data for each captured frame. The array
* of image data contains a sequence of objects with three properties for each
* frame: `imageData`, `filename`, and `extension`.
*
* Note: Frames are downloaded as individual image files by default.
* @param filename prefix of file name.
* @param extension file extension, either 'jpg' or 'png'.
* @param duration duration in seconds to record. This parameter will be constrained to be less or equal to 15.
* @param framerate number of frames to save per second. This parameter will be constrained to be less or equal to 22.
* @param callback callback function that will be executed
* to handle the image data. This function
* should accept an array as argument. The
* array will contain the specified number of
* frames of objects. Each object has three
* properties: `imageData`, `filename`, and `extension`.
*/
saveFrames(filename: string, extension: string, duration: number, framerate: number, callback?: (arg0: any[]) => void): void;
/**
* Loads an image to create a p5.Image object.
*
* `loadImage()` interprets the first parameter one of three ways. If the path
* to an image file is provided, `loadImage()` will load it. Paths to local
* files should be relative, such as `'assets/thundercat.jpg'`. URLs such as
* `'https://example.com/thundercat.jpg'` may be blocked due to browser
* security. Raw image data can also be passed as a base64 encoded image in
* the form `'data:image/png;base64,arandomsequenceofcharacters'`. The `path`
* parameter can also be defined as a `Request`
* object for more advanced usage.
*
* The second parameter is optional. If a function is passed, it will be
* called once the image has loaded. The callback function can optionally use
* the new p5.Image object. The return value of the
* function will be used as the final return value of `loadImage()`.
*
* The third parameter is also optional. If a function is passed, it will be
* called if the image fails to load. The callback function can optionally use
* the event error. The return value of the function will be used as the final
* return value of `loadImage()`.
*
* This function returns a `Promise` and should be used in an `async` setup with
* `await`. See the examples for the usage syntax.
* @param path path of the image to be loaded or base64 encoded image.
* @param successCallback function called with
* p5.Image once it
* loads.
* @param failureCallback function called with event
* error if the image fails to load.
* @returns the p5.Image object.
*/
loadImage(path: string | Request, successCallback?: (arg0: p5.Image) => void, failureCallback?: (arg0: Event) => void): Promise;
/**
* Generates a gif from a sketch and saves it to a file.
*
* `saveGif()` may be called in setup() or at any
* point while a sketch is running.
*
* The first parameter, `fileName`, sets the gif's file name.
*
* The second parameter, `duration`, sets the gif's duration in seconds.
*
* The third parameter, `options`, is optional. If an object is passed,
* `saveGif()` will use its properties to customize the gif. `saveGif()`
* recognizes the properties `delay`, `units`, `silent`,
* `notificationDuration`, and `notificationID`.
* @param filename file name of gif.
* @param duration duration in seconds to capture from the sketch.
* @param options an object that can contain five more properties:
*/
saveGif(filename: string, duration: number, options?: { delay?: number; units?: 'seconds' | 'frames'; silent?: boolean; notificationDuration?: number; notificationID?: string }): void;
/**
* Draws an image to the canvas.
*
* The first parameter, `img`, is the source image to be drawn. `img` can be
* any of the following objects:
*
* - p5.Image
*
* - p5.Element
*
* - p5.Texture
*
* - p5.Framebuffer
*
* - p5.FramebufferTexture
*
* The second and third parameters, `dx` and `dy`, set the coordinates of the
* destination image's top left corner. See
* imageMode() for other ways to position images.
*
* `let img;
*
* async function setup() {
* // Load the image.
* img = await loadImage('assets/laDefense.jpg');
*
* createCanvas(100, 100);
*
* background(50);
*
* // Draw the image.
* image(img, 0, 0);
*
* describe('An image of the underside of a white umbrella with a gridded ceiling above.');
* }`Here's a diagram that explains how optional parameters work in `image()`:
*
*
*
* The fourth and fifth parameters, `dw` and `dh`, are optional. They set the
* the width and height to draw the destination image. By default, `image()`
* draws the full source image at its original size.
*
* The sixth and seventh parameters, `sx` and `sy`, are also optional.
* These coordinates define the top left corner of a subsection to draw from
* the source image.
*
* The eighth and ninth parameters, `sw` and `sh`, are also optional.
* They define the width and height of a subsection to draw from the source
* image. By default, `image()` draws the full subsection that begins at
* `(sx, sy)` and extends to the edges of the source image.
*
* The ninth parameter, `fit`, is also optional. It enables a subsection of
* the source image to be drawn without affecting its aspect ratio. If
* `CONTAIN` is passed, the full subsection will appear within the destination
* rectangle. If `COVER` is passed, the subsection will completely cover the
* destination rectangle. This may have the effect of zooming into the
* subsection.
*
* The tenth and eleventh paremeters, `xAlign` and `yAlign`, are also
* optional. They determine how to align the fitted subsection. `xAlign` can
* be set to either `LEFT`, `RIGHT`, or `CENTER`. `yAlign` can be set to
* either `TOP`, `BOTTOM`, or `CENTER`. By default, both `xAlign` and `yAlign`
* are set to `CENTER`.
* @param img image to display.
* @param x x-coordinate of the top-left corner of the image.
* @param y y-coordinate of the top-left corner of the image.
* @param width width to draw the image.
* @param height height to draw the image.
*/
image(img: p5.Image | p5.Element | p5.Texture | p5.Framebuffer | p5.FramebufferTexture | p5.Renderer | p5.Graphics, x: number, y: number, width?: number, height?: number): void;
image(img: p5.Image | p5.Element | p5.Texture | p5.Framebuffer | p5.FramebufferTexture, dx: number, dy: number, dWidth: number, dHeight: number, sx: number, sy: number, sWidth?: number, sHeight?: number, fit?: typeof p5.CONTAIN | typeof p5.COVER, xAlign?: typeof p5.LEFT | typeof p5.RIGHT | typeof p5.CENTER, yAlign?: typeof p5.TOP | typeof p5.BOTTOM | typeof p5.CENTER): void;
/**
* Tints images using a color.
*
* The version of `tint()` with one parameter interprets it one of four ways.
* If the parameter is a number, it's interpreted as a grayscale value. If the
* parameter is a string, it's interpreted as a CSS color string. An array of
* `[R, G, B, A]` values or a p5.Color object can
* also be used to set the tint color.
*
* The version of `tint()` with two parameters uses the first one as a
* grayscale value and the second as an alpha value. For example, calling
* `tint(255, 128)` will make an image 50% transparent.
*
* The version of `tint()` with three parameters interprets them as RGB or
* HSB values, depending on the current
* colorMode(). The optional fourth parameter
* sets the alpha value. For example, `tint(255, 0, 0, 100)` will give images
* a red tint and make them transparent.
* @param v1 red or hue value.
* @param v2 green or saturation value.
* @param v3 blue or brightness.
*/
tint(v1: number, v2: number, v3: number, alpha?: number): void;
tint(value: string): void;
tint(gray: number, alpha?: number): void;
tint(values: number[]): void;
tint(color: p5.Color): void;
/**
* Removes the current tint set by tint().
*
* `noTint()` restores images to their original colors.
*/
noTint(): void;
/**
* Changes the location from which images are drawn when
* image() is called.
*
* By default, the first
* two parameters of image() are the x- and
* y-coordinates of the image's upper-left corner. The next parameters are
* its width and height. This is the same as calling `imageMode(CORNER)`.
*
* `imageMode(CORNERS)` also uses the first two parameters of
* image() as the x- and y-coordinates of the image's
* top-left corner. The third and fourth parameters are the coordinates of its
* bottom-right corner.
*
* `imageMode(CENTER)` uses the first two parameters of
* image() as the x- and y-coordinates of the image's
* center. The next parameters are its width and height.
* @param mode either CORNER, CORNERS, or CENTER.
*/
imageMode(mode: typeof p5.CORNER | typeof p5.CORNERS | typeof p5.CENTER): void;
/**
* Copies a region of pixels from one image to another.
*
* The first parameter, `srcImage`, is the
* p5.Image object to blend.
*
* The next four parameters, `sx`, `sy`, `sw`, and `sh` determine the region
* to blend from the source image. `(sx, sy)` is the top-left corner of the
* region. `sw` and `sh` are the regions width and height.
*
* The next four parameters, `dx`, `dy`, `dw`, and `dh` determine the region
* of the canvas to blend into. `(dx, dy)` is the top-left corner of the
* region. `dw` and `dh` are the regions width and height.
*
* The tenth parameter, `blendMode`, sets the effect used to blend the images'
* colors. The options are `BLEND`, `DARKEST`, `LIGHTEST`, `DIFFERENCE`,
* `MULTIPLY`, `EXCLUSION`, `SCREEN`, `REPLACE`, `OVERLAY`, `HARD_LIGHT`,
* `SOFT_LIGHT`, `DODGE`, `BURN`, `ADD`, or `NORMAL`
* @param srcImage source image.
* @param sx x-coordinate of the source's upper-left corner.
* @param sy y-coordinate of the source's upper-left corner.
* @param sw source image width.
* @param sh source image height.
* @param dx x-coordinate of the destination's upper-left corner.
* @param dy y-coordinate of the destination's upper-left corner.
* @param dw destination image width.
* @param dh destination image height.
* @param blendMode the blend mode. either
* BLEND, DARKEST, LIGHTEST, DIFFERENCE,
* MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,
* SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.
*/
blend(srcImage: p5.Image, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number, blendMode: typeof p5.BLEND | typeof p5.DARKEST | typeof p5.LIGHTEST | typeof p5.DIFFERENCE | typeof p5.MULTIPLY | typeof p5.EXCLUSION | typeof p5.SCREEN | typeof p5.REPLACE | typeof p5.OVERLAY | typeof p5.HARD_LIGHT | typeof p5.SOFT_LIGHT | typeof p5.DODGE | typeof p5.BURN | typeof p5.ADD | typeof p5.NORMAL): void;
blend(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number, blendMode: typeof p5.BLEND | typeof p5.DARKEST | typeof p5.LIGHTEST | typeof p5.DIFFERENCE | typeof p5.MULTIPLY | typeof p5.EXCLUSION | typeof p5.SCREEN | typeof p5.REPLACE | typeof p5.OVERLAY | typeof p5.HARD_LIGHT | typeof p5.SOFT_LIGHT | typeof p5.DODGE | typeof p5.BURN | typeof p5.ADD | typeof p5.NORMAL): void;
/**
* Copies pixels from a source image to a region of the canvas.
*
* The first parameter, `srcImage`, is the
* p5.Image object to blend. The source image can be
* the canvas itself or a
* p5.Image object. `copy()` will scale pixels from
* the source region if it isn't the same size as the destination region.
*
* The next four parameters, `sx`, `sy`, `sw`, and `sh` determine the region
* to copy from the source image. `(sx, sy)` is the top-left corner of the
* region. `sw` and `sh` are the region's width and height.
*
* The next four parameters, `dx`, `dy`, `dw`, and `dh` determine the region
* of the canvas to copy into. `(dx, dy)` is the top-left corner of the
* region. `dw` and `dh` are the region's width and height.
* @param srcImage source image.
* @param sx x-coordinate of the source's upper-left corner.
* @param sy y-coordinate of the source's upper-left corner.
* @param sw source image width.
* @param sh source image height.
* @param dx x-coordinate of the destination's upper-left corner.
* @param dy y-coordinate of the destination's upper-left corner.
* @param dw destination image width.
* @param dh destination image height.
*/
copy(srcImage: p5.Image | p5.Element, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
copy(sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
/**
* Applies an image filter to the canvas.
*
* The preset options are:
*
* `INVERT`
* Inverts the colors in the image. No parameter is used.
*
* `GRAY`
* Converts the image to grayscale. No parameter is used.
*
* `THRESHOLD`
* Converts the image to black and white. Pixels with a grayscale value
* above a given threshold are converted to white. The rest are converted to
* black. The threshold must be between 0.0 (black) and 1.0 (white). If no
* value is specified, 0.5 is used.
*
* `OPAQUE`
* Sets the alpha channel to entirely opaque. No parameter is used.
*
* `POSTERIZE`
* Limits the number of colors in the image. Each color channel is limited to
* the number of colors specified. Values between 2 and 255 are valid, but
* results are most noticeable with lower values. The default value is 4.
*
* `BLUR`
* Blurs the image. The level of blurring is specified by a blur radius. Larger
* values increase the blur. The default value is 4. A gaussian blur is used
* in `P2D` mode. A box blur is used in `WEBGL` mode.
*
* `ERODE`
* Reduces the light areas. No parameter is used.
*
* `DILATE`
* Increases the light areas. No parameter is used.
*
* `filter()` uses WebGL in the background by default because it's faster.
* This can be disabled in `P2D` mode by adding a `false` argument, as in
* `filter(BLUR, false)`. This may be useful to keep computation off the GPU
* or to work around a lack of WebGL support.
*
* In WebgL mode, `filter()` can also use custom shaders. See
* createFilterShader() for more
* information.
* @param filterType either THRESHOLD, GRAY, OPAQUE, INVERT,
* POSTERIZE, BLUR, ERODE, DILATE or BLUR.
* @param filterParam parameter unique to each filter.
* @param useWebGL flag to control whether to use fast
* WebGL filters (GPU) or original image
* filters (CPU); defaults to `true`.
*/
filter(filterType: typeof p5.THRESHOLD | typeof p5.GRAY | typeof p5.OPAQUE | typeof p5.INVERT | typeof p5.POSTERIZE | typeof p5.BLUR | typeof p5.ERODE | typeof p5.DILATE | typeof p5.BLUR, filterParam?: number, useWebGL?: boolean): void;
filter(filterType: typeof p5.THRESHOLD | typeof p5.GRAY | typeof p5.OPAQUE | typeof p5.INVERT | typeof p5.POSTERIZE | typeof p5.BLUR | typeof p5.ERODE | typeof p5.DILATE | typeof p5.BLUR, filterParam?: number, useWebGL?: boolean): void;
filter(shaderFilter: p5.Shader): void;
/**
* Gets a pixel or a region of pixels from the canvas.
*
* `get()` is easy to use but it's not as fast as
* pixels. Use pixels
* to read many pixel values.
*
* The version of `get()` with no parameters returns the entire canvas.
*
* The version of `get()` with two parameters interprets them as
* coordinates. It returns an array with the `[R, G, B, A]` values of the
* pixel at the given point.
*
* The version of `get()` with four parameters interprets them as coordinates
* and dimensions. It returns a subsection of the canvas as a
* p5.Image object. The first two parameters are the
* coordinates for the upper-left corner of the subsection. The last two
* parameters are the width and height of the subsection.
*
* Use p5.Image.get() to work directly with
* p5.Image objects.
* @param x x-coordinate of the pixel.
* @param y y-coordinate of the pixel.
* @param w width of the subsection to be returned.
* @param h height of the subsection to be returned.
* @returns subsection as a p5.Image object.
*/
get(x: number, y: number, w: number, h: number): p5.Image;
get(): p5.Image;
get(x: number, y: number): number[];
/**
* Loads the current value of each pixel on the canvas into the
* pixels array.
*
* `loadPixels()` must be called before reading from or writing to
* pixels.
*/
loadPixels(): void;
/**
* Sets the color of a pixel or draws an image to the canvas.
*
* `set()` is easy to use but it's not as fast as
* pixels. Use pixels
* to set many pixel values.
*
* `set()` interprets the first two parameters as x- and y-coordinates. It
* interprets the last parameter as a grayscale value, a `[R, G, B, A]` pixel
* array, a p5.Color object, or a
* p5.Image object. If an image is passed, the first
* two parameters set the coordinates for the image's upper-left corner,
* regardless of the current imageMode().
*
* updatePixels() must be called after using
* `set()` for changes to appear.
* @param x x-coordinate of the pixel.
* @param y y-coordinate of the pixel.
* @param c grayscale value | pixel array |
* p5.Color object | p5.Image to copy.
*/
set(x: number, y: number, c: number | number[] | object): void;
/**
* Updates the canvas with the RGBA values in the
* pixels array.
*
* `updatePixels()` only needs to be called after changing values in the
* pixels array. Such changes can be made directly
* after calling loadPixels() or by calling
* set().
* @param x x-coordinate of the upper-left corner of region
* to update.
* @param y y-coordinate of the upper-left corner of region
* to update.
* @param w width of region to update.
* @param h height of region to update.
*/
updatePixels(x?: number, y?: number, w?: number, h?: number): void;
updatePixels(): void;
/**
* Loads a JSON file to create an `Object`.
*
* JavaScript Object Notation
* (JSON)
* is a standard format for sending data between applications. The format is
* based on JavaScript objects which have keys and values. JSON files store
* data in an object with strings as keys. Values can be strings, numbers,
* Booleans, arrays, `null`, or other objects.
*
* The first parameter, `path`, is a string with the path to the file.
* Paths to local files should be relative, as in
* `loadJSON('assets/data.json')`. URLs such as
* `'https://example.com/data.json'` may be blocked due to browser security.
* The `path` parameter can also be defined as a `Request`
* object for more advanced usage.
*
* The second parameter, `successCallback`, is optional. If a function is
* passed, as in `loadJSON('assets/data.json', handleData)`, then the
* `handleData()` function will be called once the data loads. The object
* created from the JSON data will be passed to `handleData()` as its only argument.
* The return value of the `handleData()` function will be used as the final return
* value of `loadJSON('assets/data.json', handleData)`.
*
* The third parameter, `failureCallback`, is also optional. If a function is
* passed, as in `loadJSON('assets/data.json', handleData, handleFailure)`,
* then the `handleFailure()` function will be called if an error occurs while
* loading. The `Error` object will be passed to `handleFailure()` as its only
* argument. The return value of the `handleFailure()` function will be used as the
* final return value of `loadJSON('assets/data.json', handleData, handleFailure)`.
*
* This function returns a `Promise` and should be used in an `async` setup with
* `await`. See the examples for the usage syntax.
* @param path path of the JSON file to be loaded.
* @param successCallback function to call once the data is loaded. Will be passed the object.
* @param errorCallback function to call if the data fails to load. Will be passed an `Error` event object.
* @returns object containing the loaded data.
*/
loadJSON(path: string | Request, successCallback?: Function, errorCallback?: Function): Promise