16 While Loop

How can we use iteration to create abstract artwork?

Vocabulary: Loops, Iterations, While loop

Activity:


1.  Create the following on your canvas

ellipses in a row

2. Let's observe together the repetition of code and think about how we could reproduce this with one ellipse function. Here is the example from p5.js reference to help us get started.

// This example logs the lines below to the console
// 4
// 3
// 2
// 1
// 0
let num = 5;
while (num > 0) {
  num = num - 1;
  console.log(num);
}

While creates a loop that is useful for executing one section of code multiple times. With a 'while loop', the code inside of the loop body (between the curly braces) is run repeatedly until the test condition (inside of the parenthesis) evaluates to false.

3. Create the ellipses using the while loop together.

while sketch

4.  Create a custom shape. See two examples below. You can create your own.

while smileyswhile-circles

5. Use the while loop to repeat your shape horizontally, vertically, and diagonally. Submit this creation.

while-5