Skip to content

Commit 1bd1b31

Browse files
committed
Rearrange sections, link to describe tutorial
1 parent 76d3d3d commit 1bd1b31

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/content/tutorials/en/typography-2.0.mdx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ function draw() {
876876

877877
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.
878878

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!
880880

881881
```js
882882
describe(`An old postcard that says, "Greetings from ${greeting}"`);
@@ -1404,6 +1404,28 @@ function draw() {
14041404
}
14051405
`} />
14061406

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+
async function keyPressed() {
1419+
if (key === 's') {
1420+
const prevDensity = pixelDensity();
1421+
pixelDensity(3); // Make the canvas high res
1422+
await redraw(); // Redraw the canvas at high res
1423+
save('sketch.png');
1424+
pixelDensity(prevDensity); // Put the density back
1425+
}
1426+
}
1427+
```
1428+
14071429
## Mouse interactivity
14081430

14091431
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() {
15901612
);
15911613
pop();
15921614
}
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?
15981615
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
16061616
async function keyPressed() {
16071617
if (key === 's') {
16081618
const prevDensity = pixelDensity();
@@ -1612,7 +1622,7 @@ async function keyPressed() {
16121622
pixelDensity(prevDensity); // Put the density back
16131623
}
16141624
}
1615-
```
1625+
`} />
16161626

16171627
## Add your postcard to the collection!
16181628

0 commit comments

Comments
 (0)