Students meet p5.js on its own playground, draw circles, rectangles, triangles and lines on a canvas, learn that (0, 0) is the top left and y counts down, fix a fill that comes after its shape, and draw a picture of their own.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 10 min · Investigate 10 min · Modify 10 min · Make 20 min
Read the unit primer first. The playground is our own p5.js editor (p5.js is served from this site, so it works with no network beyond the school's own). Run starts the sketch, Stop ends it, and errors show the line and a hint. Students do not need to understand function setup() { ... } yet: it is a recipe for this lesson and the next explains it as the place that runs once. The hard part is that y counts down from the top-left: turtle and maths graphs count up. Expect "where did my shape go?" until students get this. Curly brackets, brackets and semicolons are copied as written; the hint under a red error says which is missing.
y counts down from the top-left. Ask students to predict which way a shape moves before they change a number.
| What you will see | A question to ask | The fix |
|---|---|---|
| A red line saying a name is not defined. | Is the command spelled exactly as in the example, with the same capital letters? | circle, not Circle; rect, not Rect. |
| Nothing is drawn. | Is the shape inside function setup() { ... }, between the curly brackets? | Move the line inside the braces, before the closing }. |
| The shape is in the wrong corner. | Which way does y count, up or down? | y counts down from the top, so a bigger y is lower on the canvas. |
| The new shape is hidden. | Was a bigger shape drawn after it in the same place? | Draw it later in the code, so it lands on top. |
One possible solution for each task. Other correct programs are fine.
function setup() {
createCanvas(300, 200);
background(20, 30, 60);
noStroke();
fill(255, 210, 0);
circle(250, 160, 80);
fill(255, 120, 160);
rect(20, 20, 60, 40);
fill(120, 220, 255);
triangle(220, 160, 260, 90, 290, 160);
stroke(255);
line(0, 190, 300, 190);
}
function setup() {
createCanvas(300, 200);
background(20, 30, 60);
noStroke();
fill(255, 210, 0);
circle(150, 100, 80);
fill(255, 120, 160);
ellipse(60, 40, 90, 40);
fill(120, 220, 255);
triangle(220, 160, 260, 90, 290, 160);
stroke(255);
line(0, 190, 300, 190);
}
function setup() {
createCanvas(300, 200);
background(120, 200, 255);
noStroke();
fill(90, 170, 90);
rect(0, 150, 300, 50);
fill(240, 220, 180);
rect(90, 80, 120, 80);
fill(180, 70, 60);
triangle(80, 80, 150, 30, 220, 80);
fill(120, 80, 50);
rect(135, 110, 30, 50);
fill(255, 210, 0);
circle(260, 40, 50);
}
Stretch: Make the picture with only rect and circle commands that use arithmetic, such as circle(100 + 50, 100, 40), or draw a flag from a real country.
Support: Give students the finished picture's code and ask them to change colours and sizes first, then add one shape.
Which corner is (0, 0), and which way does y count?
The top left; y counts downward.
Next lesson: variables and draw(), so the picture changes while it runs.