Students place circles on a ring with sin and cos, make the ring turn with frameCount, colour it with map, add trails and a spiral, and make a moving pattern 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 15 min
Optional enrichment after the challenge. Students need no trigonometry beyond "sin and cos give the x and y of a point going round a circle"; angles here are in radians (frameCount * 0.02), apart from the Predict, which converts degrees with radians(). Skip the explanation of radians unless asked. map is the most useful new tool: it turns any range into any other.
Seeing why a loop with i makes different circles. Print i or draw just one circle first.
| What you will see | A question to ask | The fix |
|---|---|---|
| The circles all sit in one place. | Does the angle depend on i? | Add i * 0.5 to the angle. |
| Everything is in the top left corner. | Is the middle added (150 + ...)? | Add 150 to x and to y. |
| The trails are too strong or do not show. | What is the fourth number in background? | Lower it for longer trails, raise it for shorter. |
One possible solution for each task. Other correct programs are fine.
function setup() {
createCanvas(300, 300);
noStroke();
}
function draw() {
background(20, 30, 60, 30);
for (let i = 0; i < 12; i++) {
let angle = frameCount * 0.02 + i * 0.5;
let x = 150 + cos(angle) * 100;
let y = 150 + sin(angle) * 100;
fill(map(i, 0, 11, 255, 120), map(i, 0, 11, 120, 220), 200);
circle(x, y, 20);
}
}
function setup() {
createCanvas(300, 300);
noStroke();
}
function draw() {
background(20, 30, 60);
for (let i = 0; i < 24; i++) {
let angle = frameCount * 0.02 + i * 0.5;
let radius = 10 + i * 5;
let x = 150 + cos(angle) * radius;
let y = 150 + sin(angle) * radius;
fill(map(i, 0, 23, 255, 120), map(i, 0, 23, 120, 220), 200);
circle(x, y, 12);
}
}
function setup() {
createCanvas(300, 300);
noStroke();
}
function draw() {
background(20, 30, 60);
for (let i = 0; i < 20; i++) {
let x = map(i, 0, 19, 20, 280);
let y = 150 + sin(frameCount * 0.05 + i * 0.5) * 80;
fill(255, map(i, 0, 19, 100, 220), map(i, 0, 19, 200, 100));
circle(x, y, 14 + sin(frameCount * 0.1 + i) * 6);
}
}
Stretch: Make the circles change size with sin, or draw two rings turning opposite ways.
Support: Give the Run sketch and ask for one change, such as colours or speed.
What does map(i, 0, 11, 255, 120) do?
It turns i from the range 0 to 11 into a number from 255 down to 120.
From here, students can start their own sketches or explore p5.js's reference.