Skip to content

Commit 302677d

Browse files
committed
Added side by side comparison
1 parent 22e83a8 commit 302677d

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ If you’re interested in the history of async [read on here](https://dev.to/lim
4848

4949
To play around, check out [the example from the p5.js 1.x `preload()` reference](https://p5js.org/reference/p5/preload/), but get a very big file instead of bricks.jpg.
5050

51-
This is the p5.js 1.x code, and it will result in a blank “Loading…” screen and then show the image:
51+
52+
53+
<table>
54+
<tr><th>p5.js 1.x</th><th>p5.js 2.x</th></tr>
55+
<tr><td>Blank “Loading…” screen, then image shown</td><td>Red background while image loads</td></tr>
56+
<tr><td>
5257

5358
```js
5459
let img;
@@ -71,7 +76,7 @@ function setup() {
7176
}
7277
```
7378

74-
Using p5.js 2.0 - this will result in the red background being shown before the image loads, so people viewing your sketch don’t have to look at a blank screen, but you're still guaranteed that the asset is loaded in the rest of the sketch:
79+
</td><td>
7580

7681
```js
7782
let img;
@@ -91,6 +96,9 @@ async function setup() {
9196
}
9297
```
9398

99+
</td></tr>
100+
</table>
101+
94102
If it takes a while to load the image, the sketch will be "paused" on the line `img = await loadImage('/assets/bricks.jpg');` - once the image is loaded, it will resume.
95103

96104

@@ -145,7 +153,16 @@ And that's it! You can check this example of making an add-on library backwards-
145153

146154
## …making shapes
147155

148-
If you use `vertex` and `bezierVertex` is the p5.js 1.x code, it looks like this (code based on the [custom shapes](https://p5js.org/tutorials/custom-shapes-and-smooth-curves/) tutoral):
156+
If you use `vertex` and `bezierVertex` is the p5.js 1.x code, here's how you can approach updating your code.
157+
158+
The below code is based on the [custom shapes](https://p5js.org/tutorials/custom-shapes-and-smooth-curves/) tutorial:
159+
160+
161+
<table>
162+
<tr><th>p5.js 1.x</th><th>p5.js 2.x</th></tr>
163+
<tr><td>Blank “Loading…” screen, then image shown</td><td>Red background while image loads</td></tr>
164+
<tr><td>
165+
149166

150167
```js
151168
function setup() {
@@ -175,7 +192,7 @@ function draw() {
175192
}
176193
```
177194

178-
Using p5.js 2.0, the use is more consistent, and allows greater customization. The above code is rewritten as follows:
195+
</td><td>
179196

180197

181198
```js
@@ -220,8 +237,10 @@ function draw() {
220237
}
221238
```
222239

240+
</td></tr>
241+
</table>
223242

224-
For more information about this, you can [find out more here](https://github.com/processing/p5.js/issues/6766)
243+
The [custom shapes tutorial](https://p5js.org/tutorials/custom-shapes-and-smooth-curves/) has a bit more detail on this, but Bézier curves need multiple points. In p5.js 1.x, they use three control points. In p5.js 2.0, that number is set by `bezierOrder`. Then, in p5.js 1.x each `bezierVertex(...)` was actually a set of three points describing a smooth curve. In p5.js 2.0, each `bezierVertext(x, y)` is just one point; you need the first point to anchor, and each curve after that needs 3 points.
225244

226245
## …using non-JavaScript data structures and functions
227246

0 commit comments

Comments
 (0)