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
+82Lines changed: 82 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,6 +202,8 @@ endShape();
202
202
```js
203
203
// Draw the curved star shape.
204
204
beginShape();
205
+
206
+
// The default value is 3,
205
207
bezierOrder(3);
206
208
207
209
// Original anchor at top.
@@ -230,11 +232,91 @@ bezierVertex(0,-100);
230
232
endShape();
231
233
```
232
234
235
+
</td></tr>
236
+
<tr><td>
237
+
238
+
```js
239
+
// https://p5js.org/reference/p5/quadraticVertex/
240
+
functionsetup() {
241
+
createCanvas(100, 100);
242
+
243
+
background(200);
244
+
245
+
// Start drawing the shape.
246
+
beginShape();
247
+
248
+
// Add the curved segments.
249
+
vertex(20, 20);
250
+
quadraticVertex(80, 20, 50, 50);
251
+
quadraticVertex(20, 80, 80, 80);
252
+
253
+
// Add the straight segments.
254
+
vertex(80, 10);
255
+
vertex(20, 10);
256
+
vertex(20, 20);
257
+
258
+
// Stop drawing the shape.
259
+
endShape();
260
+
261
+
describe('White puzzle piece on a gray background.');
262
+
}
263
+
```
264
+
</td><td>
265
+
266
+
267
+
```js
268
+
// Achieve the same curve with bezierOrder(2)
269
+
functionsetup() {
270
+
createCanvas(100, 100);
271
+
272
+
background(200);
273
+
274
+
// Start drawing the shape.
275
+
beginShape();
276
+
277
+
bezierOrder(2);
278
+
279
+
// Add the curved segments.
280
+
bezierVertex(20, 20);
281
+
bezierVertex(80, 20);
282
+
bezierVertex(50, 50);
283
+
bezierVertex(20, 80);
284
+
bezierVertex(80, 80);
285
+
286
+
// Add the straight segments.
287
+
vertex(80, 10);
288
+
vertex(20, 10);
289
+
vertex(20, 20);
290
+
291
+
// Stop drawing the shape.
292
+
endShape();
293
+
294
+
describe('White puzzle piece on a gray background.');
295
+
}
296
+
```
297
+
233
298
</td></tr>
234
299
</table>
235
300
236
301
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.
237
302
303
+
Additional shanges to shapes in p5.js 1.x, compared to p5.js 2.0, are as follows:
304
+
305
+
* Name changes - functionality stays the same, but the functiona is more consistently named:
306
+
*`curveVertex()` renamed to `splineVertex()`
307
+
*`curvePoint()` renamed to `splinePoint()`
308
+
*`curveTangent()` renamed to `splineTangent()`
309
+
*`curve()` renamed to `spline()`
310
+
*`curveTightness(t)` renamed to `splineProperty('tightness', t)`
311
+
* Geometry cleanup
312
+
* p5.js 1.x has functionality in `beginGeometry()`, `endGeometry()` that is covered in `buildGeometry()`
313
+
* p5.js 2.0 only keeps `buildGeometry()`
314
+
* Sampling detail cleanup
315
+
* p5.js 1.x has separate `curveDetail()` and `bezierDetail()`
316
+
* p5.js 2.0 uses `curveDetail()` to cover both, as the more general function
317
+
318
+
All of the above usages in p5.js 1.x remain available with the shapes.js compatibility add-on library.
319
+
238
320
## …using data structures and functions that have improved alternatives
239
321
240
322
One bit change relates to data structures in JavaScript. The following funcitons have been removed in p5.js 2.0. These were originally in p5.js 1.x because, historically, they were also in Processing. However, p5.js is a JavaScript library, and JavaScript objects and key-value maps can be used instead of these functions:
0 commit comments