Skip to content

Commit 22e83a8

Browse files
authored
Update README.md
1 parent 96cf2c2 commit 22e83a8

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

README.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function setup() {
7171
}
7272
```
7373

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:
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:
7575

7676
```js
7777
let img;
@@ -145,7 +145,83 @@ And that's it! You can check this example of making an add-on library backwards-
145145

146146
## …making shapes
147147

148-
Short guide coming soon! For now, you can [find out more here](https://github.com/processing/p5.js/issues/6766)
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):
149+
150+
```js
151+
function setup() {
152+
createCanvas(windowWidth, windowHeight);
153+
background(100);
154+
}
155+
function draw() {
156+
translate(width/2, height/2);
157+
// Draw the curved star shape.
158+
beginShape();
159+
160+
// Original anchor at top.
161+
vertex(0, -100);
162+
163+
// Top-right curve.
164+
bezierVertex(0, -50, 50, 0, 100, 0);
165+
166+
// Bottom-right curve.
167+
bezierVertex(50, 0, 0, 50, 0, 100);
168+
169+
// Bottom-left curve.
170+
bezierVertex0, 50, -50, 0, -100, 0);
171+
172+
// Top-left curve.
173+
bezierVertex(-50, 0, 0,-50, 0,-100);
174+
endShape();
175+
}
176+
```
177+
178+
Using p5.js 2.0, the use is more consistent, and allows greater customization. The above code is rewritten as follows:
179+
180+
181+
```js
182+
function setup() {
183+
createCanvas(windowWidth, windowHeight);
184+
background(100);
185+
}
186+
function draw() {
187+
translate(width/2, height/2);
188+
189+
// Draw the curved star shape.
190+
beginShape();
191+
192+
// Because the order is three, the curves should be
193+
// defined in sets of three after the original anchor
194+
bezierOrder(3);
195+
196+
// Original anchor at top.
197+
bezierVertex(0, -100);
198+
199+
// Top-right curve.
200+
bezierVertex(0, -50);
201+
bezierVertex(50, 0);
202+
bezierVertex(100, 0);
203+
204+
// Bottom-right curve.
205+
bezierVertex(50, 0);
206+
bezierVertex(0, 50);
207+
bezierVertex(0, 100);
208+
209+
// Bottom-left curve.
210+
bezierVertex0, 50);
211+
bezierVertex(-50, 0);
212+
bezierVertex(-100, 0);
213+
214+
// Top-left curve.
215+
bezierVertex(-50, 0);
216+
bezierVertex(0, -50);
217+
bezierVertex(0,-100);
218+
219+
endShape();
220+
}
221+
```
222+
223+
224+
For more information about this, you can [find out more here](https://github.com/processing/p5.js/issues/6766)
149225

150226
## …using non-JavaScript data structures and functions
151227

0 commit comments

Comments
 (0)