2. Introduce the idea of output. To fully understand this concept, we must also understand the idea of input. Input is
something given to the program by the user, while output is something given to the user by the program. A simple
analogy is that of a vending machine, with the input being the money that is put in and the output being the food
item that the vending machine releases. In this lesson, the input will be the sound of the user’s voice and the output
will be the on screen visualization
Discussion: Can students think of other real-life examples of input and output?
3. For this project, students also need to understand the concept of variables, which are values in our code that store
data or information. They can change (or vary) depending on what information is moved into and out of them.
There are two main variables in our code. The position variable will hold the x coordinate where our dot is
positioned. The loudness variable is one already built into Scratch. It holds information on how loud a sound is,
based on what the microphone picks up.
Creating Our Project:
This sample code demonstrates how the project might work. For your reference, Scratch determines where to display
sprites and controls movement using a Cartesian coordinate system, with (0,0) being the center of the screen and it may
be helpful to pre-teach this concept, if it is one with which students are unfamiliar. This particular project makes use of
the microphone so in order for it to work, students will need to use a device with a functioning microphone. They will
also need to approve the microphone settings and make sure that the microphone source is correct.
Part 1: Project Setup
1. Delete the automatically added sprite. Use the option to create your own sprite with the paint editor. Your sprite
should just be a small dot (i.e., use the paintbrush set to size 10 to draw a single small dot, approximately in the
middle of the paint area).
2. Use the Add Extension button in the bottom, left-hand corner of the screen to add the Pen Extension in order to
use its features.
Part 2: Starting Position & Variables
3. Add in the When Green Flag Clicked block from the yellow Events menu and add the Erase All block from the Pen
extension menu. This will ensure that each time you restart the code all previous lines drawn on screen are erased.
Use the Go To X () Y () block to set your position to the very left of the screen, using the coordinates of (-240, 0).
4. In the orange Variables menu, press “Make A Variable” and set the name to something like “current”; then, use the
Set (variablename) to () block to set the variable you just created to 0. A variable is used to store data that can vary
throughout your code and be referred to in other code blocks in order to control the outcome of your code. In this
sound visualizer project, this variable will be used to track our position along the x axis to allow the sound
visualization to progress across the screen.
5. Add the Pen Down block from the Pen extension menu. This will allow the sound visualization to actually be drawn
using the pen feature. Pen down to start drawing.
Part 3: Drawing the Sound Visualizer
6. Use the Repeat () block and set it to repeat 480 times. The number 480 has been chosen to represent the entire
width of the screen from edge to edge (240 to the left of the y axis, 240 to the right of the y axis). This will allow our
sound visualizer to use up the entire screen. All blocks in future steps will be put inside of this repeat block.
7. Add the Set Pen Color To (#) block from the Pen extension menu. In the blue Sensing menu, drag out the Loudness
block. Use this block to replace the numerical value currently stored in the Set Pen Color To () block. This will mean
that you end up with a block that reads Set Pen Color To (Loudness). The Loudness block allows Scratch to use the
microphone to detect sounds and use the value assigned to the loudness in other areas of the code. In this case,
we will use the Loudness value to change the colour of the sound visualizer depending on how quiet/loud the sound
is (i.e., with red representing quietest, purple representing loudest).