Skip to content

Commit 42dc95a

Browse files
authored
Merge branch '2.0' into fix-against-2.0
2 parents e0dbf23 + 0448521 commit 42dc95a

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// PromiseAllExample.js
2+
3+
// Declare variables to hold the images we'll load
4+
let img1, img2, img3;
5+
6+
async function setup() {
7+
// Add screen reader-friendly text description
8+
textOutput();
9+
10+
// Create a canvas where the images will be drawn
11+
createCanvas(600, 400);
12+
13+
// Set background color to gray
14+
background(220);
15+
16+
// Configure text appearance
17+
textAlign(CENTER, CENTER);
18+
textSize(18);
19+
20+
// Use async/await with Promise.all to load all three images at once
21+
// This waits until ALL images are loaded before continuing
22+
[img1, img2, img3] = await Promise.all([
23+
loadImage('https://picsum.photos/100/100?random=1'), // Replace the image links with user wanted images.
24+
loadImage('https://picsum.photos/100/100?random=2'),
25+
loadImage('https://picsum.photos/100/100?random=3')
26+
]);
27+
28+
// Once all images are ready, draw them on the canvas
29+
image(img1, 100, 150); // Draw first image at x=100
30+
image(img2, 250, 150); // Second image at x=250
31+
image(img3, 400, 150); // Third image at x=400
32+
33+
// Display a message showing that everything is loaded
34+
fill(0); // Set text color to black
35+
text("All images loaded!", width / 2, 50);
36+
}
37+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
featuredImage: "../../../images/featured/16_Async_Await_PromiseAll-thumbnail.png"
3+
featuredImageAlt: Three random images loaded and displayed on a canvas after using async/await and Promise.all.
4+
title: Async Await with Promise.all
5+
oneLineDescription: Load multiple resources asynchronously before drawing.
6+
---
7+
8+
This example demonstrates how to use
9+
<a href="https://beta.p5js.org/reference/p5/async_await/" target="_blank"> async/await </a>
10+
together with
11+
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all" target="_blank">Promise.all()</a>
12+
13+
Three random images are fetched asynchronously from the internet.
14+
After all images finish loading, they are drawn together on the canvas.
15+
Using
16+
<a href="https://beta.p5js.org/reference/p5/loadimage/" target="_blank">loadImage()</a>
17+
wrapped inside a promise allows better control over loading multiple resources efficiently.
Loading

src/content/libraries/en/p5.woff2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: p5.woff2
22
description: An addon to add support for WebGL rendering, textToPoints, and related text methods for woff2 fonts. Load a Google Fonts URL and you're good to go!
33
category: utils
4-
sourceUrl: https://github.com/davepagurek/p5.transparency
4+
sourceUrl: https://github.com/davepagurek/p5.woff2
55
featuredImage: ../images/p5.woff2.png
66
featuredImageAlt: The text "The quick brown fox jumps over the lazy dog" repeated in different weights
77
author:

src/scripts/parsers/reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const parsersOutPath = path.join(__dirname, "out");
2323
export const parseLibraryReference =
2424
async (): Promise<ParsedLibraryReference | null> => {
2525
let latestRelease:string = p5Version;
26-
if (/^\d+\.\d+\.\d+$/.exec(latestRelease)) {
26+
if (/^\d+\.\d+\.\d+(-[\w.]+)?$/.exec(latestRelease)) {
2727
latestRelease = `v${ latestRelease}`;
2828
}
2929

0 commit comments

Comments
 (0)