Skip to content

Updating all the broken refrence examples. #7739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: dev-2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/accessibility/describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ function describe(p5, fn){
*
* <div>
* <code>
*
* function setup(){
* createCanvas(100, 100);
* };
*
* function draw() {
* background(200);
*
Expand All @@ -96,6 +101,11 @@ function describe(p5, fn){
*
* <div>
* <code>
*
* function setup(){
* createCanvas(100, 100);
* }
*
* function draw() {
* background(200);
*
Expand Down
21 changes: 21 additions & 0 deletions src/accessibility/outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ function outputs(p5, fn){
*
* <div>
* <code>
*
* function setup(){
* createCanvas(100, 100);
* }
*
* function draw() {
* // Add the text description.
* textOutput();
Expand All @@ -101,6 +106,11 @@ function outputs(p5, fn){
*
* <div>
* <code>
*
* function setup(){
* createCanvas(100, 100);
* }
*
* function draw() {
* // Add the text description and
* // display it for debugging.
Expand Down Expand Up @@ -215,6 +225,11 @@ function outputs(p5, fn){
*
* <div>
* <code>
*
* function setup() {
* createCanvas(100, 100);
* }
*
* function draw() {
* // Add the grid description.
* gridOutput();
Expand All @@ -235,6 +250,11 @@ function outputs(p5, fn){
*
* <div>
* <code>
*
* function setup(){
* createCanvas(100, 100);
* }
*
* function draw() {
* // Add the grid description and
* // display it for debugging.
Expand All @@ -255,6 +275,7 @@ function outputs(p5, fn){
* </div>
*/


fn.gridOutput = function(display) {
// p5._validateParameters('gridOutput', arguments);
//if gridOutput is already true
Expand Down
4 changes: 2 additions & 2 deletions src/color/p5.Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class Color {
* }
* </code>
* </div>
**/
*/
setGreen(new_green, max=[0, 1]) {
if(!Array.isArray(max)){
max = [0, max];
Expand Down Expand Up @@ -492,7 +492,7 @@ class Color {
* }
* </code>
* </div>
**/
*/
setAlpha(new_alpha, max=[0, 1]) {
if(!Array.isArray(max)){
max = [0, max];
Expand Down
8 changes: 4 additions & 4 deletions src/core/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ function environment(p5, fn){
* @method print
* @param {Any} contents content to print to the console.
* @example
* <div>
* <code class="norender">
* <div class="norender">
* <code>
* function setup() {
* // Prints "hello, world" to the console.
* print('hello, world');
* }
* </code>
* </div>
*
* <div>
* <code class="norender">
* <div class="norender">
* <code>
* function setup() {
* let name = 'ada';
* // Prints "hello, ada" to the console.
Expand Down
8 changes: 4 additions & 4 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,10 @@ for (const k in constants) {
* ```
*
* Code placed in `setup()` will run once before code placed in
* <a href="#/p5/draw">draw()</a> begins looping. If the
* <a href="#/p5/preload">preload()</a> is declared, then `setup()` will
* run immediately after <a href="#/p5/preload">preload()</a> finishes
* <a href="#/p5/draw">draw()</a> begins looping. When `setup()` is declared async,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a slightly more precise description:

"When setup() uses the async keyword (like this: async function setup() instead of function setup())...."

* execution pauses at each `await` until the promise resolves, ensuring all assets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, providing a bit of explanation on promise:

"execution pauses at each await: for example, font = await loadFont(...) will wait for the font asset to load. This is because the loadFont(..) function returns a promise, and the await keyword means the program will wait for the promise to resolve."

Feel free to rephrase of course.

* are loaded before the sketch continues.
*
* loading assets.
*
* Note: `setup()` doesn’t have to be declared, but it’s common practice to do so.
Expand Down Expand Up @@ -535,7 +536,6 @@ for (const k in constants) {
* </code>
* </div>
*/

/**
* A function that's called repeatedly while the sketch runs.
*
Expand Down
12 changes: 6 additions & 6 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -596,7 +596,7 @@ function dom(p5, fn){
* 'https://p5js.org/assets/img/asterisk-01.png',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken URL; maybe grab an image from another part of the reference that works? eg from https://beta.p5js.org/reference/p5/image/?

* 'The p5.js magenta asterisk.'
* );
* img.position(0, -10);
* img.position(0, 10);
*
* describe('A gray square with a magenta asterisk in its center.');
* }
Expand Down Expand Up @@ -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.');
* }
Expand All @@ -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.');
* }
Expand All @@ -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.');
* }
Expand Down Expand Up @@ -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.
Expand Down
48 changes: 24 additions & 24 deletions src/events/acceleration.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ function acceleration(p5, fn){
* @example
* <div>
* <code>
* 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)
* }
* </code>
* </div>
Expand All @@ -175,18 +175,18 @@ function acceleration(p5, fn){
* @example
* <div>
* <code>
* 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)
* }
* </code>
* </div>
Expand All @@ -209,18 +209,18 @@ function acceleration(p5, fn){
* @example
* <div>
* <code>
* 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you for the expanded example 👍

* rotateZ(radians(rotationZ)); // Rotate around Z-axis
* normalMaterial(); // Apply simple shaded material
* box(60); // Draw 3D cube
* rotationZ = (rotationZ + 2) % 360; // Increment rotation angle
* }
* </code>
* </div>
Expand Down
6 changes: 3 additions & 3 deletions src/image/p5.Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
*
Expand Down Expand Up @@ -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);
*
Expand Down Expand Up @@ -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);
*
Expand Down
1 change: 1 addition & 0 deletions src/image/pixels.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function pixels(p5, fn){
* <code>
* function setup() {
* createCanvas(100, 100);
* background(128);
*
* // Load the pixels array.
* loadPixels();
Expand Down
33 changes: 21 additions & 12 deletions src/io/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
* });
Expand All @@ -970,8 +970,8 @@ function files(p5, fn){
* function mousePressed() {
* httpPost(
* url,
* 'json',
* postData,
* 'json',
* function(result) {
* // ... won't be called
* },
Expand Down Expand Up @@ -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]) {
Expand Down
4 changes: 2 additions & 2 deletions src/io/p5.TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/type/textCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ function textCore(p5, fn) {
* createCanvas(300, 300);
* background(220);
*
* textSize(48);
* textSize(35);
* textAlign(LEFT, BASELINE);
* textFont('Georgia');
*
Expand Down
Loading