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: README.md
+24-5Lines changed: 24 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,12 @@ If you’re interested in the history of async [read on here](https://dev.to/lim
48
48
49
49
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.
50
50
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>
52
57
53
58
```js
54
59
let img;
@@ -71,7 +76,7 @@ function setup() {
71
76
}
72
77
```
73
78
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>
75
80
76
81
```js
77
82
let img;
@@ -91,6 +96,9 @@ async function setup() {
91
96
}
92
97
```
93
98
99
+
</td></tr>
100
+
</table>
101
+
94
102
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.
95
103
96
104
@@ -145,7 +153,16 @@ And that's it! You can check this example of making an add-on library backwards-
145
153
146
154
## …making shapes
147
155
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
+
149
166
150
167
```js
151
168
functionsetup() {
@@ -175,7 +192,7 @@ function draw() {
175
192
}
176
193
```
177
194
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>
179
196
180
197
181
198
```js
@@ -220,8 +237,10 @@ function draw() {
220
237
}
221
238
```
222
239
240
+
</td></tr>
241
+
</table>
223
242
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.
225
244
226
245
## …using non-JavaScript data structures and functions
0 commit comments