Skip to content

Commit 902e532

Browse files
committed
grade 9~12 tutorials
1 parent 4143d08 commit 902e532

6 files changed

Lines changed: 141 additions & 4 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

_curriculum/02-03_Lessons.md

Lines changed: 141 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ While the leaves are symmetrical on the X-axis, they are asymmetrical on the Y-a
112112

113113
<iframe width="560" height="315" src="https://www.youtube.com/embed/maTfm84mLbo?si=Orx71C5hl7owLq78" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipbo a ard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
114114

115-
#### B. Translate
115+
#### B. Grouped Drawing
116116

117117
As your p5.js journey unfold, you might find yourself wanting to move or resize a group of shapes all at the same time. This is achievable through features listed under the [Transform](https://p5js.org/reference/#transform) category.
118118

119-
To begin, let's draw a cloud using the [translate()](https://p5js.org/reference/p5/translate/) feature.
119+
To begin, let's draw a cloud using the [translate()](https://p5js.org/reference/p5/translate/) feature:
120120

121121
![Symmetrical cloud sketch]({{ "/assets/images/curriculum/Unit-1_Sample-11.png" | relative_url }})
122122

@@ -167,7 +167,144 @@ function draw() {
167167

168168
![Symmetrical cloud sketch]({{ "/assets/images/curriculum/Unit-1_Sample-19.png" | relative_url }})
169169

170-
Great work! Before moving on to draw another shape, make sure that you finish grouping your cloud drawing by sandwitching the code we've written so far in between [push()](https://p5js.org/reference/p5/push/) and [pop()](https://p5js.org/reference/p5/pop/). Doing this will make sure that any new shapes you draw won't get affected by the cloud's custom [translate()](https://p5js.org/reference/p5/translate/) values.
170+
Great work! Before moving on to draw another shape, make sure that you sort your cloud drawing into a group using [push()](https://p5js.org/reference/p5/push/) and [pop()](https://p5js.org/reference/p5/pop/).
171171

172172
**Code Snippet:** [cloud example](https://editor.p5js.org/xinemata/sketches/deDhLjr2Q).
173-
{: .notice--info}
173+
{: .notice--info}
174+
175+
From this point on, you can draw a new shape, or copy and paste the cloud drawing into a new position on the canvas by manipulating the [translate()](https://p5js.org/reference/p5/translate/) values:
176+
177+
```js
178+
function setup() {
179+
createCanvas(400, 400);
180+
rectMode(CENTER);
181+
noStroke();
182+
}
183+
184+
function draw() {
185+
background(122, 122, 190);
186+
fill(255);
187+
188+
// Cloud 1
189+
190+
// Begin tranformation
191+
push();
192+
193+
// Shifts canvas origin to a new location
194+
translate(60, 60); // x, y
195+
196+
// The rectangle refers to the new canvas origin to determine X, Y positions
197+
rect(0, 0, 100, 50);
198+
199+
ellipse(-80, 0, 70, 70); // offset ellipse 80 pixel to the left
200+
ellipse(80, 0, 70, 70); // offset ellipse 80 pixel to the right
201+
202+
ellipse(-40, -40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the top
203+
ellipse(40, 40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the bottom
204+
ellipse(-40, 40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the bottom
205+
ellipse(40, -40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the top
206+
207+
ellipse(0, -50, 70, 70); // offset ellipse 50 pixel to the top
208+
ellipse(0, 50, 70, 70); // offset ellipse 50 pixel to the bottom
209+
210+
// End transformation
211+
pop();
212+
213+
// Cloud 2
214+
215+
// Begin tranformation
216+
push();
217+
218+
// Shifts canvas origin to a new location
219+
translate(200, 200); // x, y
220+
221+
// The rectangle refers to the new canvas origin to determine X, Y positions
222+
rect(0, 0, 100, 50);
223+
224+
ellipse(-80, 0, 70, 70); // offset ellipse 80 pixel to the left
225+
ellipse(80, 0, 70, 70); // offset ellipse 80 pixel to the right
226+
227+
ellipse(-40, -40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the top
228+
ellipse(40, 40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the bottom
229+
ellipse(-40, 40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the bottom
230+
ellipse(40, -40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the top
231+
232+
ellipse(0, -50, 70, 70); // offset ellipse 50 pixel to the top
233+
ellipse(0, 50, 70, 70); // offset ellipse 50 pixel to the bottom
234+
235+
// End transformation
236+
pop();
237+
238+
// Cloud 3
239+
240+
// Begin tranformation
241+
push();
242+
243+
// Shifts canvas origin to a new location
244+
translate(350, 350); // x, y
245+
246+
// The rectangle refers to the new canvas origin to determine X, Y positions
247+
rect(0, 0, 100, 50);
248+
249+
ellipse(-80, 0, 70, 70); // offset ellipse 80 pixel to the left
250+
ellipse(80, 0, 70, 70); // offset ellipse 80 pixel to the right
251+
252+
ellipse(-40, -40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the top
253+
ellipse(40, 40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the bottom
254+
ellipse(-40, 40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the bottom
255+
ellipse(40, -40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the top
256+
257+
ellipse(0, -50, 70, 70); // offset ellipse 50 pixel to the top
258+
ellipse(0, 50, 70, 70); // offset ellipse 50 pixel to the bottom
259+
260+
// End transformation
261+
pop();
262+
}
263+
```
264+
265+
![Symmetrical cloud sketch]({{ "/assets/images/curriculum/Unit-1_Sample-21.png" | relative_url }})
266+
267+
#### C. Illusion of Depth
268+
269+
[scale()](https://p5js.org/reference/p5/scale/) is a p5.js feature that makes it possible to resize the things we drew:
270+
271+
```js
272+
// Begin tranformation
273+
push();
274+
275+
// Shifts canvas origin to the center of the canvas
276+
translate(400 / 2, 400 / 2); // x, y
277+
278+
scale(0.5); // Shrink the drawing to 50% of its original size
279+
280+
// The rectangle refers to the new canvas origin to determine X, Y positions
281+
rect(0, 0, 100, 50);
282+
283+
ellipse(-80, 0, 70, 70); // offset ellipse 80 pixel to the left
284+
ellipse(80, 0, 70, 70); // offset ellipse 80 pixel to the right
285+
286+
ellipse(-40, -40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the top
287+
ellipse(40, 40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the bottom
288+
ellipse(-40, 40, 70, 70); // offset ellipse 40 pixel to the left, and 40 pixel to the bottom
289+
ellipse(40, -40, 70, 70); // offset ellipse 40 pixel to the right, and 40 pixel to the top
290+
291+
ellipse(0, -50, 70, 70); // offset ellipse 50 pixel to the top
292+
ellipse(0, 50, 70, 70); // offset ellipse 50 pixel to the bottom
293+
294+
// End transformation
295+
pop();
296+
```
297+
298+
![Symmetrical cloud sketch]({{ "/assets/images/curriculum/Unit-1_Sample-22.png" | relative_url }})
299+
300+
**Code Snippet:** [shrunk cloud example](https://editor.p5js.org/xinemata/sketches/9C6-u82S6).
301+
{: .notice--info}
302+
303+
Combining [translate()](https://p5js.org/reference/p5/translate/), [scale()](https://p5js.org/reference/p5/scale/), [push()](https://p5js.org/reference/p5/push/) and [pop()](https://p5js.org/reference/p5/pop/) opens up enormous potentials for creating illusion of depth.
304+
305+
Play around with the [multiple clouds example](https://editor.p5js.org/xinemata/sketches/Uox1dH1Mc) by resizing each cloud. Are you able to use [scale()](https://p5js.org/reference/p5/scale/) to make a cloud appear closer or further away?
306+
307+
![Symmetrical cloud sketch]({{ "/assets/images/curriculum/Unit-1_Sample-23.png" | relative_url }})
308+
309+
**Code Snippet:** [multiple clouds with depth example]( https://editor.p5js.org/xinemata/sketches/VMZ2Qc8NW).
310+
{: .notice--info}

assets/images/.DS_Store

0 Bytes
Binary file not shown.
21.1 KB
Loading
14.9 KB
Loading
19.5 KB
Loading

0 commit comments

Comments
 (0)