Skip to content

Commit 4d6493b

Browse files
authored
Merge pull request #7739 from perminder-17/patch-9
Updating all the broken refrence examples.
2 parents 54652c1 + cefb10b commit 4d6493b

File tree

14 files changed

+125
-88
lines changed

14 files changed

+125
-88
lines changed

src/accessibility/describe.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ function describe(p5, fn){
7575
*
7676
* <div>
7777
* <code>
78+
*
79+
* function setup(){
80+
* createCanvas(100, 100);
81+
* };
82+
*
7883
* function draw() {
7984
* background(200);
8085
*
@@ -96,6 +101,11 @@ function describe(p5, fn){
96101
*
97102
* <div>
98103
* <code>
104+
*
105+
* function setup(){
106+
* createCanvas(100, 100);
107+
* }
108+
*
99109
* function draw() {
100110
* background(200);
101111
*

src/accessibility/outputs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ function outputs(p5, fn){
8181
*
8282
* <div>
8383
* <code>
84+
*
85+
* function setup(){
86+
* createCanvas(100, 100);
87+
* }
88+
*
8489
* function draw() {
8590
* // Add the text description.
8691
* textOutput();
@@ -101,6 +106,11 @@ function outputs(p5, fn){
101106
*
102107
* <div>
103108
* <code>
109+
*
110+
* function setup(){
111+
* createCanvas(100, 100);
112+
* }
113+
*
104114
* function draw() {
105115
* // Add the text description and
106116
* // display it for debugging.
@@ -215,6 +225,11 @@ function outputs(p5, fn){
215225
*
216226
* <div>
217227
* <code>
228+
*
229+
* function setup() {
230+
* createCanvas(100, 100);
231+
* }
232+
*
218233
* function draw() {
219234
* // Add the grid description.
220235
* gridOutput();
@@ -235,6 +250,11 @@ function outputs(p5, fn){
235250
*
236251
* <div>
237252
* <code>
253+
*
254+
* function setup(){
255+
* createCanvas(100, 100);
256+
* }
257+
*
238258
* function draw() {
239259
* // Add the grid description and
240260
* // display it for debugging.
@@ -255,6 +275,7 @@ function outputs(p5, fn){
255275
* </div>
256276
*/
257277

278+
258279
fn.gridOutput = function(display) {
259280
// p5._validateParameters('gridOutput', arguments);
260281
//if gridOutput is already true

src/color/p5.Color.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class Color {
381381
* }
382382
* </code>
383383
* </div>
384-
**/
384+
*/
385385
setGreen(new_green, max=[0, 1]) {
386386
if(!Array.isArray(max)){
387387
max = [0, max];
@@ -492,7 +492,7 @@ class Color {
492492
* }
493493
* </code>
494494
* </div>
495-
**/
495+
*/
496496
setAlpha(new_alpha, max=[0, 1]) {
497497
if(!Array.isArray(max)){
498498
max = [0, max];

src/core/environment.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ function environment(p5, fn){
3131
* @method print
3232
* @param {Any} contents content to print to the console.
3333
* @example
34-
* <div>
35-
* <code class="norender">
34+
* <div class="norender">
35+
* <code>
3636
* function setup() {
3737
* // Prints "hello, world" to the console.
3838
* print('hello, world');
3939
* }
4040
* </code>
4141
* </div>
4242
*
43-
* <div>
44-
* <code class="norender">
43+
* <div class="norender">
44+
* <code>
4545
* function setup() {
4646
* let name = 'ada';
4747
* // Prints "hello, ada" to the console.

src/core/main.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,14 @@ for (const k in constants) {
464464
* ```
465465
*
466466
* Code placed in `setup()` will run once before code placed in
467-
* <a href="#/p5/draw">draw()</a> begins looping. If the
468-
* <a href="#/p5/preload">preload()</a> is declared, then `setup()` will
469-
* run immediately after <a href="#/p5/preload">preload()</a> finishes
470-
*
467+
* <a href="#/p5/draw">draw()</a> begins looping.
468+
* If `setup()` is declared `async` (e.g. `async function setup()`),
469+
* execution pauses at each `await` until its promise resolves.
470+
* For example, `font = await loadFont(...)` waits for the font asset
471+
* to load because `loadFont()` function returns a promise, and the await
472+
* keyword means the program will wait for the promise to resolve.
473+
* This ensures that all assets are fully loaded before the sketch continues.
474+
471475
*
472476
* loading assets.
473477
*
@@ -539,7 +543,6 @@ for (const k in constants) {
539543
* </code>
540544
* </div>
541545
*/
542-
543546
/**
544547
* A function that's called repeatedly while the sketch runs.
545548
*

src/dom/dom.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function dom(p5, fn){
352352
* let slider;
353353
*
354354
* function setup() {
355-
* createCanvas(100, 100);
355+
* createCanvas(200, 200);
356356
*
357357
* // Create a paragraph element and place
358358
* // it at the top of the canvas.
@@ -593,10 +593,10 @@ function dom(p5, fn){
593593
* background(200);
594594
*
595595
* let img = createImg(
596-
* 'https://p5js.org/assets/img/asterisk-01.png',
597-
* 'The p5.js magenta asterisk.'
596+
* '/assets/cat.jpg',
597+
* 'image of a cat'
598598
* );
599-
* img.position(0, -10);
599+
* img.position(0, 10);
600600
*
601601
* describe('A gray square with a magenta asterisk in its center.');
602602
* }
@@ -945,7 +945,7 @@ function dom(p5, fn){
945945
*
946946
* // Create a checkbox and place it beneath the canvas.
947947
* checkbox = createCheckbox();
948-
* checkbox.position(0, 100);
948+
* checkbox.position(0, 70);
949949
*
950950
* describe('A black square with a checkbox beneath it. The square turns white when the box is checked.');
951951
* }
@@ -971,7 +971,7 @@ function dom(p5, fn){
971971
* // Create a checkbox and place it beneath the canvas.
972972
* // Label the checkbox "white".
973973
* checkbox = createCheckbox(' white');
974-
* checkbox.position(0, 100);
974+
* checkbox.position(0, 70);
975975
*
976976
* describe('A black square with a checkbox labeled "white" beneath it. The square turns white when the box is checked.');
977977
* }
@@ -997,7 +997,7 @@ function dom(p5, fn){
997997
* // Create a checkbox and place it beneath the canvas.
998998
* // Label the checkbox "white" and set its value to true.
999999
* checkbox = createCheckbox(' white', true);
1000-
* checkbox.position(0, 100);
1000+
* checkbox.position(0, 70);
10011001
*
10021002
* describe('A white square with a checkbox labeled "white" beneath it. The square turns black when the box is unchecked.');
10031003
* }
@@ -1876,7 +1876,7 @@ function dom(p5, fn){
18761876
* let img;
18771877
*
18781878
* function setup() {
1879-
* createCanvas(100, 100);
1879+
* createCanvas(200, 200);
18801880
*
18811881
* // Create a file input and place it beneath
18821882
* // the canvas.

src/events/acceleration.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ function acceleration(p5, fn){
142142
* @example
143143
* <div>
144144
* <code>
145+
* let rotationX = 0; // Angle in degrees
146+
*
145147
* function setup() {
146-
* createCanvas(100, 100, WEBGL);
148+
* createCanvas(200, 200, WEBGL); // Create 3D canvas
147149
* }
148150
*
149151
* function draw() {
150-
* background(200);
151-
* //rotateZ(radians(rotationZ));
152-
* rotateX(radians(rotationX));
153-
* //rotateY(radians(rotationY));
154-
* box(200, 200, 200);
155-
* describe(`red horizontal line right, green vertical line bottom.
156-
* black background.`);
152+
* background(220); // Set light gray background
153+
* rotateX(radians(rotationX)); // Rotate around X-axis
154+
* normalMaterial(); // Apply simple shaded material
155+
* box(60); // Draw 3D cube (60 units wide)
156+
* rotationX = (rotationX + 2) % 360; // Increment rotation (2° per frame)
157157
* }
158158
* </code>
159159
* </div>
@@ -175,18 +175,18 @@ function acceleration(p5, fn){
175175
* @example
176176
* <div>
177177
* <code>
178+
* let rotationY = 0; // Angle in degrees
179+
*
178180
* function setup() {
179-
* createCanvas(100, 100, WEBGL);
181+
* createCanvas(200, 200, WEBGL); // Create 3D canvas
180182
* }
181183
*
182184
* function draw() {
183-
* background(200);
184-
* //rotateZ(radians(rotationZ));
185-
* //rotateX(radians(rotationX));
186-
* rotateY(radians(rotationY));
187-
* box(200, 200, 200);
188-
* describe(`red horizontal line right, green vertical line bottom.
189-
* black background.`);
185+
* background(220); // Set light gray background
186+
* rotateY(radians(rotationY)); // Rotate around Y-axis (vertical)
187+
* normalMaterial(); // Apply simple shaded material
188+
* box(60); // Draw 3D cube (60 units wide)
189+
* rotationY = (rotationY + 2) % 360; // Increment rotation (2° per frame)
190190
* }
191191
* </code>
192192
* </div>
@@ -209,18 +209,18 @@ function acceleration(p5, fn){
209209
* @example
210210
* <div>
211211
* <code>
212+
* let rotationZ = 0; // Angle in degrees
213+
*
212214
* function setup() {
213-
* createCanvas(100, 100, WEBGL);
215+
* createCanvas(200, 200, WEBGL); // Create 3D canvas
214216
* }
215217
*
216218
* function draw() {
217-
* background(200);
218-
* rotateZ(radians(rotationZ));
219-
* //rotateX(radians(rotationX));
220-
* //rotateY(radians(rotationY));
221-
* box(200, 200, 200);
222-
* describe(`red horizontal line right, green vertical line bottom.
223-
* black background.`);
219+
* background(220);
220+
* rotateZ(radians(rotationZ)); // Rotate around Z-axis
221+
* normalMaterial(); // Apply simple shaded material
222+
* box(60); // Draw 3D cube
223+
* rotationZ = (rotationZ + 2) % 360; // Increment rotation angle
224224
* }
225225
* </code>
226226
* </div>

src/image/p5.Image.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ class Image {
16371637
*
16381638
* async function setup() {
16391639
* // Load the image.
1640-
* gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
1640+
* gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
16411641
*
16421642
* createCanvas(100, 100);
16431643
*
@@ -1677,7 +1677,7 @@ class Image {
16771677
*
16781678
* async function setup() {
16791679
* // Load the image.
1680-
* gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
1680+
* gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
16811681
*
16821682
* createCanvas(100, 100);
16831683
*
@@ -1733,7 +1733,7 @@ class Image {
17331733
*
17341734
* async function setup() {
17351735
* // Load the image.
1736-
* gif = await loadImage('assets/arnott-wallace-wink-loop-forever.gif');
1736+
* gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');
17371737
*
17381738
* createCanvas(100, 100);
17391739
*

src/image/pixels.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function pixels(p5, fn){
4141
* <code>
4242
* function setup() {
4343
* createCanvas(100, 100);
44+
* background(128);
4445
*
4546
* // Load the pixels array.
4647
* loadPixels();

src/io/files.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ function files(p5, fn){
950950
* }
951951
*
952952
* function mousePressed() {
953-
* httpPost(url, 'json', postData, function(result) {
953+
* httpPost(url, postData, 'json', function(result) {
954954
* strokeWeight(2);
955955
* text(result.body, mouseX, mouseY);
956956
* });
@@ -970,8 +970,8 @@ function files(p5, fn){
970970
* function mousePressed() {
971971
* httpPost(
972972
* url,
973-
* 'json',
974973
* postData,
974+
* 'json',
975975
* function(result) {
976976
* // ... won't be called
977977
* },
@@ -1089,20 +1089,29 @@ function files(p5, fn){
10891089
* let eqFeatureIndex = 0;
10901090
*
10911091
* function setup() {
1092+
* createCanvas(100,100);
1093+
*
10921094
* let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
1095+
*
1096+
* const req = new Request(url, {
1097+
* method: 'GET',
1098+
* headers: {authorization: 'Bearer secretKey'}
1099+
* });
1100+
* // httpDo(path, method, datatype, success, error)
1101+
*
10931102
* httpDo(
1094-
* url,
1095-
* {
1096-
* method: 'GET',
1097-
* // Other Request options, like special headers for apis
1098-
* headers: { authorization: 'Bearer secretKey' }
1103+
* req,
1104+
* 'GET',
1105+
* 'json',
1106+
* res => {
1107+
* earthquakes = res;
10991108
* },
1100-
* function(res) {
1101-
* earthquakes = res;
1102-
* }
1103-
* );
1109+
* err => {
1110+
* console.error('Error loading data:', err);
1111+
* }
1112+
* );
11041113
* }
1105-
*
1114+
*
11061115
* function draw() {
11071116
* // wait until the data is loaded
11081117
* if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {

0 commit comments

Comments
 (0)