Skip to content

Commit 4df5bc3

Browse files
committed
Convert use of preload to async/await in reference examples
1 parent efe0fd1 commit 4df5bc3

File tree

15 files changed

+454
-749
lines changed

15 files changed

+454
-749
lines changed

src/core/environment.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,10 @@ function environment(p5, fn){
538538
* <code>
539539
* let font;
540540
*
541-
* function preload() {
541+
* async function setup() {
542542
* // Load a font to use.
543-
* font = loadFont('assets/inconsolata.otf');
544-
* }
543+
* font = await loadFont('assets/inconsolata.otf');
545544
*
546-
* function setup() {
547545
* // Create a canvas using WEBGL mode.
548546
* createCanvas(100, 50, WEBGL);
549547
* background(200);
@@ -562,12 +560,10 @@ function environment(p5, fn){
562560
* <code>
563561
* let font;
564562
*
565-
* function preload() {
563+
* async function setup() {
566564
* // Load a font to use.
567-
* font = loadFont('assets/inconsolata.otf');
568-
* }
565+
* font = await loadFont('assets/inconsolata.otf');
569566
*
570-
* function setup() {
571567
* // Create a canvas using WEBGL mode.
572568
* createCanvas(100, 50, WEBGL);
573569
*

src/core/main.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,9 @@ for (const k in constants) {
499499
* <code>
500500
* let img;
501501
*
502-
* function preload() {
503-
* img = loadImage('assets/bricks.jpg');
504-
* }
502+
* async function setup() {
503+
* img = await loadImage('assets/bricks.jpg');
505504
*
506-
* function setup() {
507505
* createCanvas(100, 100);
508506
*
509507
* // Draw the image.

src/events/pointer.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,10 @@ function pointer(p5, fn){
187187
* <code>
188188
* let font;
189189
*
190-
* // Load a font for WebGL mode.
191-
* function preload() {
192-
* font = loadFont('assets/inconsolata.otf');
193-
* }
190+
* async function setup() {
191+
* // Load a font for WebGL mode.
192+
* font = await loadFont('assets/inconsolata.otf');
194193
*
195-
* function setup() {
196194
* createCanvas(100, 100, WEBGL);
197195
*
198196
* describe(
@@ -298,12 +296,10 @@ function pointer(p5, fn){
298296
* <code>
299297
* let font;
300298
*
301-
* // Load a font for WebGL mode.
302-
* function preload() {
303-
* font = loadFont('assets/inconsolata.otf');
304-
* }
299+
* async function setup() {
300+
* // Load a font for WebGL mode.
301+
* font = await loadFont('assets/inconsolata.otf');
305302
*
306-
* function setup() {
307303
* createCanvas(100, 100, WEBGL);
308304
*
309305
* describe(

src/image/loading_displaying.js

Lines changed: 43 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -857,12 +857,10 @@ function loadingDisplaying(p5, fn){
857857
* ```js example
858858
* let img;
859859
*
860-
* // Load the image.
861-
* function preload() {
862-
* img = loadImage('assets/laDefense.jpg');
863-
* }
860+
* async function setup() {
861+
* // Load the image.
862+
* img = await loadImage('assets/laDefense.jpg');
864863
*
865-
* function setup() {
866864
* createCanvas(100, 100);
867865
*
868866
* background(50);
@@ -916,12 +914,10 @@ function loadingDisplaying(p5, fn){
916914
* <code>
917915
* let img;
918916
*
919-
* // Load the image.
920-
* function preload() {
921-
* img = loadImage('assets/laDefense.jpg');
922-
* }
917+
* async function setup() {
918+
* // Load the image.
919+
* img = await loadImage('assets/laDefense.jpg');
923920
*
924-
* function setup() {
925921
* createCanvas(100, 100);
926922
*
927923
* background(50);
@@ -938,12 +934,10 @@ function loadingDisplaying(p5, fn){
938934
* <code>
939935
* let img;
940936
*
941-
* // Load the image.
942-
* function preload() {
943-
* img = loadImage('assets/laDefense.jpg');
944-
* }
937+
* async function setup() {
938+
* // Load the image.
939+
* img = await loadImage('assets/laDefense.jpg');
945940
*
946-
* function setup() {
947941
* createCanvas(100, 100);
948942
*
949943
* background(50);
@@ -960,12 +954,10 @@ function loadingDisplaying(p5, fn){
960954
* <code>
961955
* let img;
962956
*
963-
* // Load the image.
964-
* function preload() {
965-
* img = loadImage('assets/laDefense.jpg');
966-
* }
957+
* async function setup() {
958+
* // Load the image.
959+
* img = await loadImage('assets/laDefense.jpg');
967960
*
968-
* function setup() {
969961
* createCanvas(100, 100);
970962
*
971963
* background(50);
@@ -982,12 +974,9 @@ function loadingDisplaying(p5, fn){
982974
* <code>
983975
* let img;
984976
*
985-
* // Load the image.
986-
* function preload() {
987-
* img = loadImage('assets/moonwalk.jpg');
988-
* }
989-
*
990-
* function setup() {
977+
* async function setup() {
978+
* // Load the image.
979+
* img = await loadImage('assets/moonwalk.jpg');
991980
* createCanvas(100, 100);
992981
*
993982
* background(50);
@@ -1004,13 +993,10 @@ function loadingDisplaying(p5, fn){
1004993
* <code>
1005994
* let img;
1006995
*
1007-
* // Load the image.
1008-
* function preload() {
1009-
* // Image is 50 x 50 pixels.
1010-
* img = loadImage('assets/laDefense50.png');
1011-
* }
996+
* async function setup() {
997+
* // Load the image.
998+
* img = await loadImage('assets/laDefense50.jpg');
1012999
*
1013-
* function setup() {
10141000
* createCanvas(100, 100);
10151001
*
10161002
* background(50);
@@ -1171,12 +1157,10 @@ function loadingDisplaying(p5, fn){
11711157
* <code>
11721158
* let img;
11731159
*
1174-
* // Load the image.
1175-
* function preload() {
1176-
* img = loadImage('assets/laDefense.jpg');
1177-
* }
1160+
* async function setup() {
1161+
* // Load the image.
1162+
* img = await loadImage('assets/laDefense.jpg');
11781163
*
1179-
* function setup() {
11801164
* createCanvas(100, 100);
11811165
*
11821166
* // Left image.
@@ -1196,12 +1180,10 @@ function loadingDisplaying(p5, fn){
11961180
* <code>
11971181
* let img;
11981182
*
1199-
* // Load the image.
1200-
* function preload() {
1201-
* img = loadImage('assets/laDefense.jpg');
1202-
* }
1183+
* async function setup() {
1184+
* // Load the image.
1185+
* img = await loadImage('assets/laDefense.jpg');
12031186
*
1204-
* function setup() {
12051187
* createCanvas(100, 100);
12061188
*
12071189
* // Left image.
@@ -1220,13 +1202,11 @@ function loadingDisplaying(p5, fn){
12201202
* <div>
12211203
* <code>
12221204
* let img;
1205+
**
1206+
* async function setup() {
1207+
* // Load the image.
1208+
* img = await loadImage('assets/laDefense.jpg');
12231209
*
1224-
* // Load the image.
1225-
* function preload() {
1226-
* img = loadImage('assets/laDefense.jpg');
1227-
* }
1228-
*
1229-
* function setup() {
12301210
* createCanvas(100, 100);
12311211
*
12321212
* // Left.
@@ -1246,12 +1226,10 @@ function loadingDisplaying(p5, fn){
12461226
* <code>
12471227
* let img;
12481228
*
1249-
* // Load the image.
1250-
* function preload() {
1251-
* img = loadImage('assets/laDefense.jpg');
1252-
* }
1229+
* async function setup() {
1230+
* // Load the image.
1231+
* img = await loadImage('assets/laDefense.jpg');
12531232
*
1254-
* function setup() {
12551233
* createCanvas(100, 100);
12561234
*
12571235
* // Left.
@@ -1306,12 +1284,10 @@ function loadingDisplaying(p5, fn){
13061284
* <code>
13071285
* let img;
13081286
*
1309-
* // Load the image.
1310-
* function preload() {
1311-
* img = loadImage('assets/laDefense.jpg');
1312-
* }
1287+
* async function setup() {
1288+
* // Load the image.
1289+
* img = await loadImage('assets/laDefense.jpg');
13131290
*
1314-
* function setup() {
13151291
* createCanvas(100, 100);
13161292
*
13171293
* // Left.
@@ -1371,12 +1347,10 @@ function loadingDisplaying(p5, fn){
13711347
* <code>
13721348
* let img;
13731349
*
1374-
* // Load the image.
1375-
* function preload() {
1376-
* img = loadImage('assets/bricks.jpg');
1377-
* }
1350+
* async function setup() {
1351+
* // Load the image.
1352+
* img = await loadImage('assets/bricks.jpg');
13781353
*
1379-
* function setup() {
13801354
* createCanvas(100, 100);
13811355
*
13821356
* background(200);
@@ -1396,12 +1370,10 @@ function loadingDisplaying(p5, fn){
13961370
* <code>
13971371
* let img;
13981372
*
1399-
* // Load the image.
1400-
* function preload() {
1401-
* img = loadImage('assets/bricks.jpg');
1402-
* }
1373+
* async function setup() {
1374+
* // Load the image.
1375+
* img = await loadImage('assets/bricks.jpg');
14031376
*
1404-
* function setup() {
14051377
* createCanvas(100, 100);
14061378
*
14071379
* background(200);
@@ -1421,12 +1393,10 @@ function loadingDisplaying(p5, fn){
14211393
* <code>
14221394
* let img;
14231395
*
1424-
* // Load the image.
1425-
* function preload() {
1426-
* img = loadImage('assets/bricks.jpg');
1427-
* }
1396+
* async function setup() {
1397+
* // Load the image.
1398+
* img = await loadImage('assets/bricks.jpg');
14281399
*
1429-
* function setup() {
14301400
* createCanvas(100, 100);
14311401
*
14321402
* background(200);

0 commit comments

Comments
 (0)