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
+78-2Lines changed: 78 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ function setup() {
71
71
}
72
72
```
73
73
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:
75
75
76
76
```js
77
77
let img;
@@ -145,7 +145,83 @@ And that's it! You can check this example of making an add-on library backwards-
145
145
146
146
## …making shapes
147
147
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
+
functionsetup() {
152
+
createCanvas(windowWidth, windowHeight);
153
+
background(100);
154
+
}
155
+
functiondraw() {
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
+
bezierVertex( 0, 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
+
functionsetup() {
183
+
createCanvas(windowWidth, windowHeight);
184
+
background(100);
185
+
}
186
+
functiondraw() {
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
+
bezierVertex( 0, 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)
149
225
150
226
## …using non-JavaScript data structures and functions
0 commit comments