Skip to content

Commit b0001a7

Browse files
committed
Shape and color pages init
1 parent 08a1ba8 commit b0001a7

9 files changed

Lines changed: 190 additions & 152 deletions

File tree

_curriculum/01-01_Lessons.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ published: true
77
gallery: # Below is for including an image gallery
88
---
99

10-
# Getting Started
11-
12-
## 1. Setting Up Your Environment
10+
## Setting Up Your Environment
1311

1412
To begin writing code using [p5.js](https://p5js.org/), you need to set up the coding environment to write and save your programs. [Processing Foundation](https://processingfoundation.org/) provides the [p5.js Editor](https://editor.p5js.org/), a website where programmers can write, test, share, and remix p5.js programs without needing to download or install a code editor on a computer.
1513

1614
<iframe width="560" height="315" src="https://www.youtube.com/embed/MXs1cOlidWs?si=h8uilatDVzeLCl_a" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
1715

18-
### What you will need
16+
#### What you will need
1917

2018
- Access to the internet and the latest version of a desktop browser such as:
2119
- Chrome (recommended)
@@ -24,14 +22,14 @@ To begin writing code using [p5.js](https://p5js.org/), you need to set up the c
2422
- Edge
2523
- A desktop computer, laptop, or Chromebook
2624

27-
### 1A. Opening the p5.js Editor
25+
#### A. Opening the p5.js Editor
2826

2927
1. Open the latest version of Chrome or Firefox browser on your computer and visit the [p5.js Editor](https://editor.p5js.org/) website.
3028
1. Click the “Sign up” link on the top right of the web page.
3129

3230
![p5.js Editor sign-up link]({{ "https://github.com/processing/p5.js-website/blob/main/src/content/tutorials/images/introduction/p5_editor_sign_up.png?raw=true" | relative_url}})
3331

34-
### 1B. Creating an Account
32+
#### B. Creating an Account
3533

3634
Create an account on the [p5.js Editor](https://editor.p5js.org/) using one of the following options:
3735

@@ -53,7 +51,7 @@ Create an account on the [p5.js Editor](https://editor.p5js.org/) using one of t
5351
- Follow the prompts to enter your username and password for GitHub.
5452
- Authorize the [p5.js Editor](https://editor.p5js.org/) to access your GitHub details by clicking the “Authorize processing” button.
5553

56-
### 1C. Exploring the p5.js Editor and running your first “sketch”
54+
#### C. Exploring the p5.js Editor and running your first “sketch”
5755

5856
![p5.js Editor interface breakdown]({{ "https://github.com/processing/p5.js-website/blob/main/src/content/tutorials/images/introduction/p5_editor_interface_breakdown.png?raw=true" | relative_url }})
5957

@@ -67,15 +65,15 @@ Create an account on the [p5.js Editor](https://editor.p5js.org/) using one of t
6765
![p5.js Editor version switcher]({{ "/assets/images/ui/version_switcher_2.png" | relative_url }})
6866
![p5.js Editor version switcher]({{ "/assets/images/ui/version_switcher_3.png" | relative_url }})
6967

70-
### 1D. Renaming, saving, and sharing sketches
68+
#### D. Renaming, saving, and sharing sketches
7169

7270
1. By default, the [p5.js Editor](https://editor.p5js.org/) will generate a playful name for your first sketch. You can rename your sketch by clicking on the pencil icon above the text editor and typing in a name for your project. ![Renaming a sketch]({{ "https://github.com/processing/p5.js-website/blob/main/src/content/tutorials/images/introduction/p5_editor_naming_a_sketch.png?raw=true" | relative_url }})
7371
1. Save projects by clicking on File in the top toolbar and selecting Save. Alternatively, you can use the shortcut keys Control+S (PC) or Command+S (Mac). ![Saving a sketch]({{ "https://github.com/processing/p5.js-website/blob/main/src/content/tutorials/images/introduction/p5_editor_saving_a_sketch.png?raw=true" | relative_url }}) ![Saved notification]({{ "https://github.com/processing/p5.js-website/blob/main/src/content/tutorials/images/introduction/p5_editor_saved_sketch_notification.png?raw=true" | relative_url }})
7472

7573
**Tip:** Make sure you are logged in to your account, or you will not be able to save the sketch. Saving projects frequently helps ensure that code isn’t lost if something happens to your computer, browser, or internet connection while you're coding.
7674
{: .notice--success}
7775

78-
### 1E. Sharing, downloading, and deleting your sketches
76+
#### E. Sharing, downloading, and deleting your sketches
7977

8078
1. Once your project is saved, you can share it! Click on File in the navigation menu, select Share, and copy one of the links provided to share your project in Embed, Fullscreen, and Edit modes.
8179
1. If you share your project link with a teacher or classmate, you are giving them the permission to view all of your sketches stored on the [p5.js Editor](https://editor.p5js.org/). This is because all sketches stored in the [p5.js Editor](https://editor.p5js.org/) are publicly viewable. Additionally, it’s also possible for your sketches to show up in search engine results.
File renamed without changes.
Lines changed: 6 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# This is the frontmatter
33
title: "Lost and Found" # Title and Heading 1
4-
permalink: /lostAndFound-lessons/ # Give your page a permalink
4+
permalink: /lostAndFound-lessons/1 # Give your page a permalink
55
published: true
66

77
gallery: # Below is for including an image gallery
@@ -22,12 +22,11 @@ gallery: # Below is for including an image gallery
2222
alt: "cursor creating a drawing of vertical blue lines and stamping red ellipses"
2323
title: "Digital Drawing Tool Step 4"
2424
---
25-
# Lesson Plans & Technical Steps
2625

27-
## 1. Shape
26+
## Shape
2827
<iframe width="560" height="315" src="https://www.youtube.com/embed/hISICBkFa4Q?si=U-LWuegXM9xtLfXg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
2928

30-
#### 1A. p5.js canvas coordinates
29+
#### A. p5.js canvas coordinates
3130
By default, every new p5.js sketch you create on the p5.js Editor will contain the following code:
3231

3332
```jsx
@@ -62,7 +61,7 @@ function setup(){
6261
Additionally, it’s not possible to animate canvas size while a sketch is playing.
6362
{: .notice--success}
6463

65-
#### 1B. p5.js coordinate system
64+
#### B. p5.js coordinate system
6665
We’re on our way to placing shapes on the canvas. Do you recall the Cartesian coordinate system taught in math classes? Don’t worry, we believe this to be much simpler! The p5.js canvas features an invisible coordinate system that originates from an X position of 0 and a Y location of 0 in the top-left corner.
6766

6867
![p5.js coordinate system]({{ "https://github.com/processing/p5.js-website/blob/main/src/content/tutorials/images/introduction/coordinates.png?raw=true" | relative_url }})
@@ -72,7 +71,7 @@ As a shape on the canvas moves to the right of this point, its [X-coordinate val
7271
**Code Snippet:** Explore the p5.js coordinate system with this [pixel ruler tool](https://editor.p5js.org/xinemata/sketches/gjWtrowcK) created by Alp Tugǎn, a p5.js Contributor.
7372
{: .notice--info}
7473

75-
#### 1C. Drawing simple shapes
74+
#### C. Drawing simple shapes
7675
Now that we’ve covered the basics of the coordinate system, let’s draw a rectangle on the canvas by using the [rect()](https://p5js.org/reference/p5/rect/) feature!
7776

7877
```jsx
@@ -192,135 +191,4 @@ function draw() {
192191
**Code Snippet:** [ellipse() + rect()](https://editor.p5js.org/xinemata/sketches/29C52nZDz).
193192
{: .notice--info}
194193

195-
The ellipse should now be sitting on top of your rectangle. What this tells us is that the order in which you code your shapes matters. [p5.js](https://p5js.org) is built on JavaScript, and JavaScript renders code on the fly from top to bottom. Coding the rectangle first means that the rectangle is drawn first, and then it gets covered by the ellipse, which comes later.
196-
197-
### 2. Color
198-
<iframe width="560" height="315" src="https://www.youtube.com/embed/fTEvHLLwSBE?si=O-3UMF0ZjaUhQb6M" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
199-
200-
#### Grade 6~8
201-
##### 2A. Story Behind the Screen
202-
Look at the screen in front of you right now. Every color you see—bright pinks, glowing greens, stormy blues—is made from just three colors of light: red, green, and blue—also known as RGB.
203-
204-
You can’t always see it, but it’s true. If you looked at your phone or computer screen under a microscope (cool science class moment!), you’d see tiny red, green, and blue lights—called pixels—turning on and off in different combinations. That’s how screens make color: by mixing light.
205-
206-
![RGB screen]({{ "https://upload.wikimedia.org/wikipedia/commons/9/9d/TFT_Bildschirm_RGB_Pixel.JPG" | relative_url }})
207-
208-
This kind of color mixing is called additive color. It’s different from mixing paint, where adding more makes things darker. With light, adding more actually make things brighter.
209-
210-
![RGB mixing]({{ "https://upload.wikimedia.org/wikipedia/commons/5/59/RGB_combination_on_wall.png" | relative_url }})
211-
212-
213-
In this topic, we'll learn to cast some color spells together using code. You’ll learn how to control the RGB colors in p5.js, a creative coding environment made for artists, designers, and anyone curious about how code can be expressive.
214-
215-
##### 2B. Meet RGB
216-
217-
Let’s start by updating the [background()](https://p5js.org/reference/p5/background/) in the [p5.js editor](https://editor.p5js.org/):
218-
219-
```js
220-
function setup() {
221-
createCanvas(400, 400);
222-
}
223-
224-
function draw() {
225-
background(255, 0, 0); // r, g, b
226-
}
227-
```
228-
229-
If you click the Play button, the background of the canvas should be filled in bright red. Let's break this down to better understand what's going on:
230-
231-
- RGB ranges from a minimum value of 0, to a maximum value of 255. These numbers control the brightness levels of the red, green, and blue lights.
232-
- In this case, the sketch is coloring the background in the brightest possible red in RGB. `background(255, 0, 0);` means: full red light, no green light, and no blue light.
233-
234-
**Mini-Challenge:** Can you update background() to fill the canvas with the brightest blue possible?
235-
{: .notice--warning}
236-
237-
**Tip**: In the RGB world, `background(255, 255, 0);` creates yellow, `background(255, 0, 255);` creates magenta, and `background(0, 255, 255);` creates cyan.
238-
{: .notice--success}
239-
240-
Play around! What happens with:
241-
- `background(255, 255, 255)`?
242-
- `background(0, 0, 0)`?
243-
244-
**Tip**: If you only type one number like `background(150)`, it fills the background with a shade of gray. That’s a shortcut for `background(150, 150, 150)`.
245-
{: .notice--success}
246-
247-
---
248-
249-
##### 2C. Filling Shapes with Color
250-
251-
Let’s add an ellipse and give it color using the [fill()](https://p5js.org/reference/p5/fill/) feature:
252-
253-
```js
254-
function setup() {
255-
createCanvas(400, 400); // w, h
256-
rectMode(CENTER);
257-
}
258-
259-
function draw() {
260-
background(220);
261-
fill(255, 255, 0); // r, g, b
262-
rect(200, 200, 40, 40); // x, y, w, h
263-
ellipse(200, 200, 40, 40); // x, y, w, h
264-
}
265-
```
266-
267-
By default, [fill()](https://p5js.org/reference/p5/fill/) recognizes RGB values and sets the color of the shapes you draw. But what if you want to fill the ellipse with a different color? You will need to place another [fill()](https://p5js.org/reference/p5/fill/) right before the ellipse.
268-
269-
```js
270-
function setup() {
271-
createCanvas(400, 400); // w, h
272-
rectMode(CENTER);
273-
}
274-
275-
function draw() {
276-
background(220);
277-
fill(255,255,0); // r, g, b
278-
rect(200, 200, 40, 40); // x, y, w, h
279-
fill(255,0,255); // r, g, b
280-
ellipse(200, 200, 40, 40); // x, y, w, h
281-
}
282-
```
283-
**Code Snippet:** [fill()](https://editor.p5js.org/xinemata/sketches/sU7-2LedO).
284-
{: .notice--info}
285-
286-
Once you feel comfortable with using RGB colors, you have the option of going further by adding a fourth number to [fill()](https://editor.p5js.org/xinemata/sketches/sU7-2LedO) to make something see-through!
287-
288-
```js
289-
fill(255, 0, 0, 100); // r, g, b, alpha
290-
```
291-
292-
The last number is called the alpha value. It also ranges from 0 (fully transparent) to 255 (fully opaque).
293-
294-
**Mini-Challenge:** Try overlapping shapes with different alpha values. What kinds of layering effects can you make?
295-
{: .notice--warning}
296-
297-
##### 2D. Draw your favorite snack
298-
Let’s use everything you’ve learned so far to draw a snack you love. Think about ways you could represent your snack using 2D primitives like ellipses and rectangles. And instead of guessing the RGB values of a color you want to use, play around with this [color picker](https://g.co/kgs/6fssxMC) to choose specific colors. Below is an example of a lollipop:
299-
300-
![lollipop made in p5.js]({{ "/assets/images/curriculum/Unit-1_Sample-10.png" | relative_url }})
301-
302-
**Code Snippet:** [lollipop example](https://editor.p5js.org/xinemata/sketches/reojWdPOp).
303-
{: .notice--info}
304-
305-
**Tip:** Adding [noStroke()](https://p5js.org/reference/p5/noStroke/) removes the black outline around shapes. [stroke()](https://p5js.org/reference/p5/stroke/) sets the outline to a different color. [strokeWeight()](https://p5js.org/reference/p5/strokeWeight/) alters the thickness of the outline.
306-
{: .notice--success}
307-
308-
#### Grade 9~12
309-
##### 3. Blend Modes
310-
311-
Want your colors to mix in cool ways—like in Photoshop or Instagram filters? Try this:
312-
313-
```js
314-
function setup() {
315-
createCanvas(400, 400);
316-
blendMode(LIGHTEST); // Try other modes: DARKEST, MULTIPLY, DIFFERENCE
317-
318-
fill(255, 0, 0);
319-
ellipse(150, 200, 200, 200);
320-
321-
fill(0, 0, 255);
322-
ellipse(250, 200, 200, 200);
323-
}
324-
```
325-
326-
Blend modes change how colors mix when they overlap. Each one creates different visual effects.
194+
The ellipse should now be sitting on top of your rectangle. What this tells us is that the order in which you code your shapes matters. [p5.js](https://p5js.org) is built on JavaScript, and JavaScript renders code on the fly from top to bottom. Coding the rectangle first means that the rectangle is drawn first, and then it gets covered by the ellipse, which comes later.

0 commit comments

Comments
 (0)