Skip to content

Commit ae85039

Browse files
authored
Update README.md with more extensive documentation of shapes 2.0 transition
1 parent a3b6b0c commit ae85039

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ endShape();
202202
```js
203203
// Draw the curved star shape.
204204
beginShape();
205+
206+
// The default value is 3,
205207
bezierOrder(3);
206208

207209
// Original anchor at top.
@@ -230,11 +232,91 @@ bezierVertex(0,-100);
230232
endShape();
231233
```
232234

235+
</td></tr>
236+
<tr><td>
237+
238+
```js
239+
// https://p5js.org/reference/p5/quadraticVertex/
240+
function setup() {
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+
function setup() {
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+
233298
</td></tr>
234299
</table>
235300

236301
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.
237302

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+
238320
## …using data structures and functions that have improved alternatives
239321

240322
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

Comments
 (0)