diff --git a/src/accessibility/describe.js b/src/accessibility/describe.js index 79cebe605e..984682ee34 100644 --- a/src/accessibility/describe.js +++ b/src/accessibility/describe.js @@ -75,6 +75,11 @@ function describe(p5, fn){ * *
* + * + * function setup(){ + * createCanvas(100, 100); + * }; + * * function draw() { * background(200); * @@ -96,6 +101,11 @@ function describe(p5, fn){ * *
* + * + * function setup(){ + * createCanvas(100, 100); + * } + * * function draw() { * background(200); * diff --git a/src/accessibility/outputs.js b/src/accessibility/outputs.js index a8b445bc28..6fa60e6243 100644 --- a/src/accessibility/outputs.js +++ b/src/accessibility/outputs.js @@ -81,6 +81,11 @@ function outputs(p5, fn){ * *
* + * + * function setup(){ + * createCanvas(100, 100); + * } + * * function draw() { * // Add the text description. * textOutput(); @@ -101,6 +106,11 @@ function outputs(p5, fn){ * *
* + * + * function setup(){ + * createCanvas(100, 100); + * } + * * function draw() { * // Add the text description and * // display it for debugging. @@ -215,6 +225,11 @@ function outputs(p5, fn){ * *
* + * + * function setup() { + * createCanvas(100, 100); + * } + * * function draw() { * // Add the grid description. * gridOutput(); @@ -235,6 +250,11 @@ function outputs(p5, fn){ * *
* + * + * function setup(){ + * createCanvas(100, 100); + * } + * * function draw() { * // Add the grid description and * // display it for debugging. @@ -255,6 +275,7 @@ function outputs(p5, fn){ *
*/ + fn.gridOutput = function(display) { // p5._validateParameters('gridOutput', arguments); //if gridOutput is already true diff --git a/src/color/p5.Color.js b/src/color/p5.Color.js index 886caa6e83..bddd312688 100644 --- a/src/color/p5.Color.js +++ b/src/color/p5.Color.js @@ -381,7 +381,7 @@ class Color { * } * *
- **/ + */ setGreen(new_green, max=[0, 1]) { if(!Array.isArray(max)){ max = [0, max]; @@ -492,7 +492,7 @@ class Color { * } * *
- **/ + */ setAlpha(new_alpha, max=[0, 1]) { if(!Array.isArray(max)){ max = [0, max]; diff --git a/src/core/environment.js b/src/core/environment.js index 6936d04f52..0d7d6b949c 100644 --- a/src/core/environment.js +++ b/src/core/environment.js @@ -31,8 +31,8 @@ function environment(p5, fn){ * @method print * @param {Any} contents content to print to the console. * @example - *
- * + *
+ * * function setup() { * // Prints "hello, world" to the console. * print('hello, world'); @@ -40,8 +40,8 @@ function environment(p5, fn){ * *
* - *
- * + *
+ * * function setup() { * let name = 'ada'; * // Prints "hello, ada" to the console. diff --git a/src/core/main.js b/src/core/main.js index 75d10c7398..a5c9a6c93d 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -464,10 +464,14 @@ for (const k in constants) { * ``` * * Code placed in `setup()` will run once before code placed in - * draw() begins looping. If the - * preload() is declared, then `setup()` will - * run immediately after preload() finishes - * + * 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. * @@ -539,7 +543,6 @@ for (const k in constants) { * *
*/ - /** * A function that's called repeatedly while the sketch runs. * diff --git a/src/dom/dom.js b/src/dom/dom.js index 0cf3edee0b..7501130cbf 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -352,7 +352,7 @@ function dom(p5, fn){ * let slider; * * function setup() { - * createCanvas(100, 100); + * createCanvas(200, 200); * * // Create a paragraph element and place * // it at the top of the canvas. @@ -593,10 +593,10 @@ function dom(p5, fn){ * background(200); * * let img = createImg( - * 'https://p5js.org/assets/img/asterisk-01.png', - * 'The p5.js magenta asterisk.' + * '/assets/cat.jpg', + * 'image of a cat' * ); - * img.position(0, -10); + * img.position(0, 10); * * describe('A gray square with a magenta asterisk in its center.'); * } @@ -945,7 +945,7 @@ function dom(p5, fn){ * * // Create a checkbox and place it beneath the canvas. * checkbox = createCheckbox(); - * checkbox.position(0, 100); + * checkbox.position(0, 70); * * describe('A black square with a checkbox beneath it. The square turns white when the box is checked.'); * } @@ -971,7 +971,7 @@ function dom(p5, fn){ * // Create a checkbox and place it beneath the canvas. * // Label the checkbox "white". * checkbox = createCheckbox(' white'); - * checkbox.position(0, 100); + * checkbox.position(0, 70); * * describe('A black square with a checkbox labeled "white" beneath it. The square turns white when the box is checked.'); * } @@ -997,7 +997,7 @@ function dom(p5, fn){ * // Create a checkbox and place it beneath the canvas. * // Label the checkbox "white" and set its value to true. * checkbox = createCheckbox(' white', true); - * checkbox.position(0, 100); + * checkbox.position(0, 70); * * describe('A white square with a checkbox labeled "white" beneath it. The square turns black when the box is unchecked.'); * } @@ -1876,7 +1876,7 @@ function dom(p5, fn){ * let img; * * function setup() { - * createCanvas(100, 100); + * createCanvas(200, 200); * * // Create a file input and place it beneath * // the canvas. diff --git a/src/events/acceleration.js b/src/events/acceleration.js index 36ab8a047e..3b0d5d8dc7 100644 --- a/src/events/acceleration.js +++ b/src/events/acceleration.js @@ -142,18 +142,18 @@ function acceleration(p5, fn){ * @example *
* + * let rotationX = 0; // Angle in degrees + * * function setup() { - * createCanvas(100, 100, WEBGL); + * createCanvas(200, 200, WEBGL); // Create 3D canvas * } * * function draw() { - * background(200); - * //rotateZ(radians(rotationZ)); - * rotateX(radians(rotationX)); - * //rotateY(radians(rotationY)); - * box(200, 200, 200); - * describe(`red horizontal line right, green vertical line bottom. - * black background.`); + * background(220); // Set light gray background + * rotateX(radians(rotationX)); // Rotate around X-axis + * normalMaterial(); // Apply simple shaded material + * box(60); // Draw 3D cube (60 units wide) + * rotationX = (rotationX + 2) % 360; // Increment rotation (2° per frame) * } * *
@@ -175,18 +175,18 @@ function acceleration(p5, fn){ * @example *
* + * let rotationY = 0; // Angle in degrees + * * function setup() { - * createCanvas(100, 100, WEBGL); + * createCanvas(200, 200, WEBGL); // Create 3D canvas * } * * function draw() { - * background(200); - * //rotateZ(radians(rotationZ)); - * //rotateX(radians(rotationX)); - * rotateY(radians(rotationY)); - * box(200, 200, 200); - * describe(`red horizontal line right, green vertical line bottom. - * black background.`); + * background(220); // Set light gray background + * rotateY(radians(rotationY)); // Rotate around Y-axis (vertical) + * normalMaterial(); // Apply simple shaded material + * box(60); // Draw 3D cube (60 units wide) + * rotationY = (rotationY + 2) % 360; // Increment rotation (2° per frame) * } * *
@@ -209,18 +209,18 @@ function acceleration(p5, fn){ * @example *
* + * let rotationZ = 0; // Angle in degrees + * * function setup() { - * createCanvas(100, 100, WEBGL); + * createCanvas(200, 200, WEBGL); // Create 3D canvas * } * * function draw() { - * background(200); - * rotateZ(radians(rotationZ)); - * //rotateX(radians(rotationX)); - * //rotateY(radians(rotationY)); - * box(200, 200, 200); - * describe(`red horizontal line right, green vertical line bottom. - * black background.`); + * background(220); + * rotateZ(radians(rotationZ)); // Rotate around Z-axis + * normalMaterial(); // Apply simple shaded material + * box(60); // Draw 3D cube + * rotationZ = (rotationZ + 2) % 360; // Increment rotation angle * } * *
diff --git a/src/image/p5.Image.js b/src/image/p5.Image.js index 4b1002012e..0fad23a429 100644 --- a/src/image/p5.Image.js +++ b/src/image/p5.Image.js @@ -1637,7 +1637,7 @@ class Image { * * async function setup() { * // Load the image. - * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif'); + * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif'); * * createCanvas(100, 100); * @@ -1677,7 +1677,7 @@ class Image { * * async function setup() { * // Load the image. - * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif'); + * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif'); * * createCanvas(100, 100); * @@ -1733,7 +1733,7 @@ class Image { * * async function setup() { * // Load the image. - * gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif'); + * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif'); * * createCanvas(100, 100); * diff --git a/src/image/pixels.js b/src/image/pixels.js index e1d1edd614..ebea101273 100644 --- a/src/image/pixels.js +++ b/src/image/pixels.js @@ -41,6 +41,7 @@ function pixels(p5, fn){ * * function setup() { * createCanvas(100, 100); + * background(128); * * // Load the pixels array. * loadPixels(); diff --git a/src/io/files.js b/src/io/files.js index b98bf009f6..2a23bb71db 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -950,7 +950,7 @@ function files(p5, fn){ * } * * function mousePressed() { - * httpPost(url, 'json', postData, function(result) { + * httpPost(url, postData, 'json', function(result) { * strokeWeight(2); * text(result.body, mouseX, mouseY); * }); @@ -970,8 +970,8 @@ function files(p5, fn){ * function mousePressed() { * httpPost( * url, - * 'json', * postData, + * 'json', * function(result) { * // ... won't be called * }, @@ -1089,20 +1089,29 @@ function files(p5, fn){ * let eqFeatureIndex = 0; * * function setup() { + * createCanvas(100,100); + * * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson'; + * + * const req = new Request(url, { + * method: 'GET', + * headers: {authorization: 'Bearer secretKey'} + * }); + * // httpDo(path, method, datatype, success, error) + * * httpDo( - * url, - * { - * method: 'GET', - * // Other Request options, like special headers for apis - * headers: { authorization: 'Bearer secretKey' } + * req, + * 'GET', + * 'json', + * res => { + * earthquakes = res; * }, - * function(res) { - * earthquakes = res; - * } - * ); + * err => { + * console.error('Error loading data:', err); + * } + * ); * } - * + * * function draw() { * // wait until the data is loaded * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) { diff --git a/src/io/p5.TableRow.js b/src/io/p5.TableRow.js index ae5f04652c..c5f1dfd4ea 100644 --- a/src/io/p5.TableRow.js +++ b/src/io/p5.TableRow.js @@ -255,8 +255,8 @@ class TableRow { * let table; * * async function setup() { - * // Create a 200x100 canvas and set a white background - * createCanvas(200, 100); + * // Create a 300x100 canvas and set a white background + * createCanvas(300, 100); * background(255); * * // Load the CSV file with a header row diff --git a/src/type/textCore.js b/src/type/textCore.js index e4a5a1107f..11c863d650 100644 --- a/src/type/textCore.js +++ b/src/type/textCore.js @@ -1240,7 +1240,7 @@ function textCore(p5, fn) { * createCanvas(300, 300); * background(220); * - * textSize(48); + * textSize(35); * textAlign(LEFT, BASELINE); * textFont('Georgia'); * diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index c6f30660c0..bca2efb2a2 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -71,7 +71,7 @@ class Camera { * fill(0); * * // Display the value of eyeX, rounded to the nearest integer. - * text(`eyeX: ${round(cam.eyeX)}`, 0, 55); + * text(`eyeX: ${round(cam.eyeX)}`, 0, 45); * } * *
@@ -89,9 +89,6 @@ class Camera { * // Create a p5.Camera object. * cam = createCamera(); * - * // Set the camera - * setCamera(cam); - * * // Place the camera at the top-center. * cam.setPosition(0, -400, 800); * @@ -125,7 +122,7 @@ class Camera { * cam.setPosition(x, -400, 800); * * // Display the value of eyeX, rounded to the nearest integer. - * text(`eyeX: ${round(cam.eyeX)}`, 0, 55); + * text(`eyeX: ${round(cam.eyeX)}`, 0, 45); * } * *
@@ -183,7 +180,7 @@ class Camera { * fill(0); * * // Display the value of eyeY, rounded to the nearest integer. - * text(`eyeY: ${round(cam.eyeY)}`, 0, 55); + * text(`eyeY: ${round(cam.eyeY)}`, 0, 45); * } * *
@@ -237,7 +234,7 @@ class Camera { * cam.setPosition(0, y, 800); * * // Display the value of eyeY, rounded to the nearest integer. - * text(`eyeY: ${round(cam.eyeY)}`, 0, 55); + * text(`eyeY: ${round(cam.eyeY)}`, 0, 45); * } * *
@@ -295,7 +292,7 @@ class Camera { * fill(0); * * // Display the value of eyeZ, rounded to the nearest integer. - * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 55); + * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 45); * } *
*
@@ -349,7 +346,7 @@ class Camera { * cam.setPosition(0, -400, z); * * // Display the value of eyeZ, rounded to the nearest integer. - * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 55); + * text(`eyeZ: ${round(cam.eyeZ)}`, 0, 45); * } * * @@ -408,7 +405,7 @@ class Camera { * fill(0); * * // Display the value of centerX, rounded to the nearest integer. - * text(`centerX: ${round(cam.centerX)}`, 0, 55); + * text(`centerX: ${round(cam.centerX)}`, 0, 45); * } * * @@ -462,7 +459,7 @@ class Camera { * cam.lookAt(x, 20, -30); * * // Display the value of centerX, rounded to the nearest integer. - * text(`centerX: ${round(cam.centerX)}`, 0, 55); + * text(`centerX: ${round(cam.centerX)}`, 0, 45); * } * * @@ -521,7 +518,7 @@ class Camera { * fill(0); * * // Display the value of centerY, rounded to the nearest integer. - * text(`centerY: ${round(cam.centerY)}`, 0, 55); + * text(`centerY: ${round(cam.centerY)}`, 0, 45); * } * * @@ -575,7 +572,7 @@ class Camera { * cam.lookAt(10, y, -30); * * // Display the value of centerY, rounded to the nearest integer. - * text(`centerY: ${round(cam.centerY)}`, 0, 55); + * text(`centerY: ${round(cam.centerY)}`, 0, 45); * } * * @@ -634,7 +631,7 @@ class Camera { * fill(0); * * // Display the value of centerZ, rounded to the nearest integer. - * text(`centerZ: ${round(cam.centerZ)}`, 0, 55); + * text(`centerZ: ${round(cam.centerZ)}`, 0, 45); * } * * @@ -652,9 +649,6 @@ class Camera { * // Create a p5.Camera object. * cam = createCamera(); * - * // Set the camera - * setCamera(cam); - * * // Place the camera at the top-right. * cam.setPosition(100, -400, 800); * @@ -688,7 +682,7 @@ class Camera { * cam.lookAt(10, 20, z); * * // Display the value of centerZ, rounded to the nearest integer. - * text(`centerZ: ${round(cam.centerZ)}`, 0, 55); + * text(`centerZ: ${round(cam.centerZ)}`, 0, 45); * } * * @@ -746,7 +740,7 @@ class Camera { * fill(0); * * // Display the value of upX, rounded to the nearest tenth. - * text(`upX: ${round(cam.upX, 1)}`, 0, 55); + * text(`upX: ${round(cam.upX, 1)}`, 0, 45); * } * * @@ -799,7 +793,7 @@ class Camera { * cam.camera(100, -400, 800, 0, 0, 0, x, 1, 0); * * // Display the value of upX, rounded to the nearest tenth. - * text(`upX: ${round(cam.upX, 1)}`, 0, 55); + * text(`upX: ${round(cam.upX, 1)}`, 0, 45); * } * * @@ -857,7 +851,7 @@ class Camera { * fill(0); * * // Display the value of upY, rounded to the nearest tenth. - * text(`upY: ${round(cam.upY, 1)}`, 0, 55); + * text(`upY: ${round(cam.upY, 1)}`, 0, 45); * } * * @@ -910,7 +904,7 @@ class Camera { * cam.camera(100, -400, 800, 0, 0, 0, 0, y, 0); * * // Display the value of upY, rounded to the nearest tenth. - * text(`upY: ${round(cam.upY, 1)}`, 0, 55); + * text(`upY: ${round(cam.upY, 1)}`, 0, 45); * } * * @@ -968,7 +962,7 @@ class Camera { * fill(0); * * // Display the value of upZ, rounded to the nearest tenth. - * text(`upZ: ${round(cam.upZ, 1)}`, 0, 55); + * text(`upZ: ${round(cam.upZ, 1)}`, 0, 45); * } * * @@ -1021,7 +1015,7 @@ class Camera { * cam.camera(100, -400, 800, 0, 0, 0, 0, 1, z); * * // Display the value of upZ, rounded to the nearest tenth. - * text(`upZ: ${round(cam.upZ, 1)}`, 0, 55); + * text(`upZ: ${round(cam.upZ, 1)}`, 0, 45); * } * * diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index f7b1079213..5e46d2d106 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -2614,11 +2614,10 @@ function rendererGL(p5, fn) { * } * * - *
- * Now with the antialias attribute set to true. - *
+ * *
* + * // Now with the antialias attribute set to true. * function setup() { * setAttributes('antialias', true); * createCanvas(100, 100, WEBGL);