MCPcopy
hub / github.com/processing/p5.js / rendering

Function rendering

src/core/rendering.js:11–676  ·  view source on GitHub ↗
(p5, fn)

Source from the content-addressed store, hash-verified

9
10let renderers;
11function rendering(p5, fn){
12 // Extend additional renderers object to p5 class, new renderer can be similarly attached
13 if (!p5.renderers) {
14 p5.renderers = {};
15 }
16 renderers = p5.renderers;
17
18 /**
19 * Creates a canvas element on the web page.
20 *
21 * `createCanvas()` creates the main drawing canvas for a sketch. It should
22 * only be called once at the beginning of <a href="#/p5/setup">setup()</a>.
23 * Calling `createCanvas()` more than once causes unpredictable behavior.
24 *
25 * The first two parameters, `width` and `height`, are optional. They set the
26 * dimensions of the canvas and the values of the
27 * <a href="#/p5/width">width</a> and <a href="#/p5/height">height</a> system
28 * variables. For example, calling `createCanvas(900, 500)` creates a canvas
29 * that's 900×500 pixels. By default, `width` and `height` are both 100.
30 *
31 * The third parameter is also optional. If either of the constants `P2D` or
32 * `WEBGL` is passed, as in `createCanvas(900, 500, WEBGL)`, then it will set
33 * the sketch's rendering mode. If an existing
34 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement" target="_blank">HTMLCanvasElement</a>
35 * is passed, as in `createCanvas(900, 500, myCanvas)`, then it will be used
36 * by the sketch. To use `WEBGPU` mode, make sure you have the WebGPU mode addon included.
37 *
38 * The fourth parameter is also optional. If an existing
39 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement" target="_blank">HTMLCanvasElement</a>
40 * is passed, as in `createCanvas(900, 500, WEBGL, myCanvas)`, then it will be
41 * used by the sketch.
42 *
43 * Note: In WebGL mode, the canvas will use a WebGL2 context if it's supported
44 * by the browser. Check the <a href="#/p5/webglVersion">webglVersion</a>
45 * system variable to check what version is being used, or call
46 * `setAttributes({ version: 1 })` to create a WebGL1 context.
47 *
48 * Note: In WebGPU mode, you must `await` this function.
49 *
50 * @method createCanvas
51 * @param {Number} [width] width of the canvas. Defaults to 100.
52 * @param {Number} [height] height of the canvas. Defaults to 100.
53 * @param {(P2D|WEBGL|P2DHDR)} [renderer] either P2D or WEBGL. Defaults to `P2D`.
54 * @param {HTMLCanvasElement} [canvas] existing canvas element that should be used for the sketch.
55 * @return {p5.Renderer} new `p5.Renderer` that holds the canvas.
56 *
57 * @example
58 * function setup() {
59 * createCanvas(100, 100);
60 *
61 * background(200);
62 *
63 * // Draw a diagonal line.
64 * line(0, 0, width, height);
65 *
66 * describe('A diagonal line drawn from top-left to bottom-right on a gray background.');
67 * }
68 *

Callers 1

rendering.jsFile · 0.85

Calls 8

removeChildMethod · 0.80
_assert3dMethod · 0.80
_friendlyErrorMethod · 0.45
removeMethod · 0.45
pushMethod · 0.45
_applyDefaultsMethod · 0.45
resizeMethod · 0.45
clearDepthMethod · 0.45

Tested by

no test coverage detected