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
+98-3Lines changed: 98 additions & 3 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, and it 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:
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,94 @@ 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
-
Short guide coming soon! For now, you can [find out more here](https://github.com/processing/p5.js/issues/6766)
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
+
166
+
167
+
```js
168
+
functionsetup() {
169
+
createCanvas(windowWidth, windowHeight);
170
+
background(100);
171
+
}
172
+
functiondraw() {
173
+
translate(width/2, height/2);
174
+
// Draw the curved star shape.
175
+
beginShape();
176
+
177
+
// Original anchor at top.
178
+
vertex(0, -100);
179
+
180
+
// Top-right curve.
181
+
bezierVertex(0, -50, 50, 0, 100, 0);
182
+
183
+
// Bottom-right curve.
184
+
bezierVertex(50, 0, 0, 50, 0, 100);
185
+
186
+
// Bottom-left curve.
187
+
bezierVertex( 0, 50, -50, 0, -100, 0);
188
+
189
+
// Top-left curve.
190
+
bezierVertex(-50, 0, 0,-50, 0,-100);
191
+
endShape();
192
+
}
193
+
```
194
+
195
+
</td><td>
196
+
197
+
198
+
```js
199
+
functionsetup() {
200
+
createCanvas(windowWidth, windowHeight);
201
+
background(100);
202
+
}
203
+
functiondraw() {
204
+
translate(width/2, height/2);
205
+
206
+
// Draw the curved star shape.
207
+
beginShape();
208
+
209
+
// Because the order is three, the curves should be
210
+
// defined in sets of three after the original anchor
211
+
bezierOrder(3);
212
+
213
+
// Original anchor at top.
214
+
bezierVertex(0, -100);
215
+
216
+
// Top-right curve.
217
+
bezierVertex(0, -50);
218
+
bezierVertex(50, 0);
219
+
bezierVertex(100, 0);
220
+
221
+
// Bottom-right curve.
222
+
bezierVertex(50, 0);
223
+
bezierVertex(0, 50);
224
+
bezierVertex(0, 100);
225
+
226
+
// Bottom-left curve.
227
+
bezierVertex( 0, 50);
228
+
bezierVertex(-50, 0);
229
+
bezierVertex(-100, 0);
230
+
231
+
// Top-left curve.
232
+
bezierVertex(-50, 0);
233
+
bezierVertex(0, -50);
234
+
bezierVertex(0,-100);
235
+
236
+
endShape();
237
+
}
238
+
```
239
+
240
+
</td></tr>
241
+
</table>
242
+
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.
149
244
150
245
## …using non-JavaScript data structures and functions
0 commit comments