You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/tutorials/en/typography-2.0.mdx
+24-14Lines changed: 24 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -876,7 +876,7 @@ function draw() {
876
876
877
877
We've got a nice looking postcard already! But since this isn't going to be a physical postcard--we're going to put it on a website--we want viewers who use screen readers to be able to tell what's on the canvas.
878
878
879
-
To do so, we can use `describe()` in setup, and write a short, descriptive string about what we've drawn.
879
+
To do so, we can use `describe()` in setup, and write a short, descriptive string about what we've drawn.[Check out our `describe` tutorial](https://p5js.org/tutorials/writing-accessible-canvas-descriptions/) for more info!
880
880
881
881
```js
882
882
describe(`An old postcard that says, "Greetings from ${greeting}"`);
@@ -1404,6 +1404,28 @@ function draw() {
1404
1404
}
1405
1405
`} />
1406
1406
1407
+
## High-res exports
1408
+
1409
+
We have a small canvas here, what would you do if you wanted to get a high-res image saved?
1410
+
1411
+
Well, first, I'll add `setAttributes({ antialias: true })` after the `createCanvas` line to make sure our edges are nice and smooth.
1412
+
1413
+
Then, we can use `pixelDensity()` to make the sketch draw at higher resolution than what the screen needs. If the default size is 600x400, a pixel density of 2 will render 1200x800 pixels, even though the canvas looks the same size onscreen.
1414
+
1415
+
Often, to save an image, you'll wait for a key to be pressed (e.g. the s key), set the pixel density very high, redraw, save the canvas, then set it back. We'll use this technique by defining the keyPressed function, which p5.js will call whenever a key is pressed, and checking the value of key, a global variable set to the recent key. Here's a snippet you can add to a sketch to add that functionality:
1416
+
1417
+
```js
1418
+
asyncfunctionkeyPressed() {
1419
+
if (key ==='s') {
1420
+
constprevDensity=pixelDensity();
1421
+
pixelDensity(3); // Make the canvas high res
1422
+
awaitredraw(); // Redraw the canvas at high res
1423
+
save('sketch.png');
1424
+
pixelDensity(prevDensity); // Put the density back
1425
+
}
1426
+
}
1427
+
```
1428
+
1407
1429
## Mouse interactivity
1408
1430
1409
1431
Let's make it so that when you mouse over each letter, the animation for that letter restarts! To do this, rather than having a **fixed** start time for each letter, we'll make a variable start time that we can update dynamically. We'll make a **variable** at the top with the start time for each letter, and then refer to those times in `draw()` when calculating the progress.
@@ -1590,19 +1612,7 @@ function draw() {
1590
1612
);
1591
1613
pop();
1592
1614
}
1593
-
`} />
1594
-
1595
-
## High-res exports
1596
-
1597
-
We have a small canvas here, what would you do if you wanted to get a high-res image saved?
1598
1615
1599
-
Well, first, I'll add `setAttributes({ antialias: true })` after the `createCanvas` line to make sure our edges are nice and smooth.
1600
-
1601
-
Then, we can use `pixelDensity()` to make the sketch draw at higher resolution than what the screen needs. If the default size is 600x400, a pixel density of 2 will render 1200x800 pixels, even though the canvas looks the same size onscreen.
1602
-
1603
-
Often, to save an image, you'll wait for a key to be pressed (e.g. the s key), set the pixel density very high, redraw, save the canvas, then set it back. We'll use this technique by defining the keyPressed function, which p5.js will call whenever a key is pressed, and checking the value of key, a global variable set to the recent key. Here's a snippet you can add to a sketch to add that functionality:
1604
-
1605
-
```js
1606
1616
async function keyPressed() {
1607
1617
if (key === 's') {
1608
1618
const prevDensity = pixelDensity();
@@ -1612,7 +1622,7 @@ async function keyPressed() {
1612
1622
pixelDensity(prevDensity); // Put the density back
0 commit comments