# Random Movement

Educator notes

## Educator Notes

### Length of the chapter: 1,5 - 3h

• Adjust the length of the chapter according to the time you have at hand.
• There are more detailed lesson plans on the next page.

### Learning objectives:

Students learn…

• … to use random-command to locate shapes in specific areas.
• … to pick ranges of colors to create a certain atmosphere.
• … to use random-command creatively to illustrate movement in the world around us.
• … to experiment open-mindedly while programming - it’s not always necessary to know the exact result beforehand!
• … to use integer-variables to create continuous movement.
• … to create objects that reappear on the canvas after crossing the edges.
• … to create objects that bounce from the edges of the canvas.
• … to use different kinds of moving objects in the Space Exploration -exercise in the end of this chapter.

You can use the slides below to introduce the second chapter to the students. See also the lesson plans below the slides!

### Plan 1 - Structured Lessons (110-150 min)

Time to completeActivity
10 minSCRUM routine: Students explain to others: 1) what was the last thing they did on the previous lesson and 2) if they had any challenges they need help with. If students are shy to speak when others are listening, you can go and talk with them individually later on.

It doesn't matter if some students are still doing the tasks of the first chapter. You can help those students after introducing the second chapter to everyone.
15 minIntroduce the second chapter with the slides above.
25-45 minStudents start the second chapter alone or in pairs and go through the topics Random Movement and Fast and Furious objects. Ask students to speak out if they have any challenges.

Go around in the classroom while the students are working and discuss briefly with each student. Talk especially with those who have had challenges or seem to lack motivation. Make sure that every student has some kind of meaningful goal for this lesson.
10 minAsk the students if they have had any challenges so far.

If needed, draw a coordinate system on a whiteboard and explain, what happens if you locate a shape with a random-command or by using a variable that increases.

Discussion: Ask students to give examples of what to express with randomized locations? What about continuous movement?
20-40 minStudents continue with the material and go through the topic What if? Ask students to speak out if they have challenges.
15 minReflection discussion: What has been most interesting? Do you have ideas of what to express with the new programming tools?

Introduction to the Space Exploration -exercise
- Show an example result from Open Processing or show something you have coded yourself
- Give a time-limit: 30 minutes!
30 min

Students develop their own Space Exploration and submit the code.

5 min

You can end the lesson (or start the next lesson) by going through a couple of Space Explorations the students have made, if they are willing to show them.

### Plan 2 - Freely flowing lessons (110-150 min)

Time to completeActivity
10 min

SCRUM routine: Students explain to others: 1) what was the last thing they did on the previous lesson and 2) if they had any challenges they need help with. If students are shy to speak when others are listening, you can go and talk with them individually later on.It doesn't matter if some students are still completing the tasks of the first chapter. You can help those students after introducing the second chapter to everyone.

5 min

Set a goal for the second (and third) lesson: complete the second chapter. Show the Space Exploration -exercise of the chapter to the students with a projector.

Ask the students to start from the topic Random Movement and then continue forward. Ask the students to speak out if they have a any questions.

50-90 min

Go around in the classroom while the students are working and discuss briefly with each student. Talk especially with those who have had challenges or seem to lack motivation. Make sure that every student has some kind of meaningful goal for this lesson.

If you feel that students have trouble understanding variables or if-statements, explain them to everyone together. Check the Educator Notes for more teaching tips related to these topics.

10 min

Reflection discussion: What has been most interesting? Do you have ideas of what to express with the new programming tools?

Introduce the Space Exploration -exercise. If some students have started or completed it already, it doesn't matter.
- Show an example result from Open Processing or show something you have coded yourself.
- Give a time-limit: 30 minutes!

30 min

Students develop their own Space Exploration and submit the code.

5 min

You can end the lesson (or start the next lesson) by going through a couple of Space Explorations the students have made, if they are willing to show them.

## Repetition is the Key

Do this

Write the example below to Processing IDE and test it.

Which of the following statements is true?
If I want to change the location of a shape as the program proceeds, I have to do this...
What does the command random(0, 500) do?

Educator notes

It’s important to understand that the computer executes the draw-method on loop, repeating it over and over again. When the computer has executed the last command of the draw-method, it returns back to the starting point. You can demonstrate this to everyone together by showing the draw-method and going through the commands written one by one.

If your students have done programming before, they might be used to writing the actual program inside a loop-method. You can tell them that draw-method has the same function as the loop in other programming languages.

Some students may want to know how fast the computer can execute the draw-method. While the default value is 60 frames per second, the speed can be changed with the frameRate-command which we will introduce later. This can be used to create different effects: if shapes appear on the canvas slower, it will create a totally different atmosphere. The maximum framerate depends on the hardware and the complexity of the program, but should be somewhere between 100 and 1000 frames per second (fps). Note, that your monitor can only draw frames as fast as its refresh rate!

## Random, Random Everywhere

Do this

Copy the program developed in the video from below and test it.

``````void setup(){
size(500, 500);
}

void draw(){
// Make width and height of the rectangles random too.
rect(random(0, 500), random(0, 500), 100, 100);
}
``````

Make an addition so that the width and height of the rectangle are random values as well. That means there should be four random-commands inside the rect-command.

The result should look like the animation below. If you have difficulties, ask your teacher for help!

Educator notes

Remind the students that you locate an ellipse by using the coordinate-point of the center and a rectangle by using the coordinate-point of the top-left corner.

## Autumn Vibes

Do this

Copy the code in the video from below and run it.

Change the colors in the fill-command and the size of the rectangles.

Think of some theme other than the autumn! For example waves of the sea, snowflakes, flowers, rainstorm, colony of ants, busy people in a city...

Give your creation a name and save it to your computer  (File > Save as).

``````// Autumn Vibes
void setup(){
size(500, 500);
}

void draw(){
// Change the color-ranges. The Color Selector helps! (Tools > Color Selector).
// Change the transparency of the color (fourth parameter) too.
fill(random(200, 255), random(100, 200), random(100), 125);
// Change the size of the rectangles or replace them with another shape.
rect(random(500), random(500), 100, 100);
}
``````

Where you can find the Color Selector in Processing IDE?
What is the amount of red in this fill-command? fill(random(200, 255), 50, 150, 100);

Educator notes

Encourage the learners to experiment with the autumn vibes-project in the video and make it their own. You can totally change the theme and mood of the project just by changing colors and the size of the shapes. Students can also use other shapes instead of rectangles: for example, ellipses, rectangles and lines will create very different atmospheres. Triangles are a bit more tricky to use because every corner is located separately. But students will find their way by experimenting!

If you determine a filling color or color of the stroke with four parameters, the fourth one will determine the opacity of the color. 0 creates a totally transparent color (0 % opacity) and 255 a color with 100 % opacity.

Activity: If you’re familiar with different color theories, this can be a good point in the course to explain and experiment with them in different combinations. What color-ranges look good on the canvas together and why?

## Speed of Light

Do this

Copy the code below and run it in Processing IDE.

``````// Speed of Light

void setup(){
size(500, 500);
}

void draw(){
line(250, 250, 0, random(500));
line(250, 250, random(500), 0);
// Add a third line-command here
// Add a fourth line-command here
}
``````

Replace the two commented lines with two new line-commands and try to produce the result below on the right. If you have difficulties, ask your teacher for help!

On the left, you can see the example completed in the video.

Educator notes

Lines are perfect for a variety of simplistic but impressive illustrations. Remember that you can change the weight of the lines with the strokeWeight-command. You can use a random-value inside that command too.

Activity: Ask students to give examples of phenomena that can be illustrated with regular shapes and a random-command. Think together of how to draw them in Processing.