Do Now
Do Now: Real-World Connections
Today, we’re going to start by hearing from Kinsley on the importance of diversity in tech.
Do Now: Real-World Connections
Where does Kinsley work? What is his job there?
Why does Kinsley say it is important to work with diverse people?
What does Kinsley say is the best way to get started?
Mini Lesson
Procedures in Animation
Procedures are used a lot in world of animation to help computer-based animators. A manual form of them were even used for hand-drawn animation, as seen here!
How might having reusable code scripts, like procedures, help computer animators create their scenes?
Procedures in Animation
For example, an animator might come up with a code sequence that generates a character's facial expression to show a specific reaction. The animator could just copy and paste the code into each spot they use the reaction.
But, what if they need to tweak the expression a little bit? They would then have to find every place they used that reaction and update it. That takes a lot of time!
Procedures in Animation
If the animator uses a procedure, however, they only have to tweak the code in the definition of the procedure and it will run with the updated code every time!
These kinds of procedures that are used to help create repeatable groups of code for animations are called animation cycles. This is what we'll be making in Scratch today!
These are 2 different animation cycles for the same character.
Introducing Parameters
Today, we're also going to look at a way to expand how we use procedures through using something called parameters.
Let's learn about parameters by looking at the procedure block we made a couple of lessons ago — my dance — and what else we can do with it.
Introducing
Parameters
One of the examples we saw of how the block could be used is shown here. What if we wanted to simplify my dance even further by editing our custom procedure block to allow us to specify the amount of times it should run without having to add a repeat block?
How can we get the "2" to display in a spot right next to my dance? By adding a parameter!
Introducing
Parameters
These are all types of parameters, which are also called inputs in Scratch. We've been using them all this time and didn't know it!
Adding parameters let us get more specific in a simpler way with our procedures since we don't have to rely on other blocks (like repeat) to make something happen.
Numerical
Dropdown
Text (string)
Boolean
Color
Introducing
Parameters
Now we know what to call these empty spots we've been using. But, what do we call the values we enter into these spots? Those are called arguments in programming. Scratch also calls them inputs.
Today, we'll learn how to add parameters to the custom procedures blocks we create, which are the types shown in pink here.
Numerical
Dropdown
Text (string)
Boolean
Color
Vocabulary
procedure (n): a group of code that has been given a name; also called a function.
parameter (n): the name of a piece of data or information in code that helps make it more specific and requires input, or an argument.
argument (n): the value of a parameter that is input; also called input in Scratch.
Introducing
Parameters
Last, what about the words that come after the parameter in some blocks to help us know more about what the parameter specifies?
These are called labels, which we'll also learn how to add today!
Pre-Coding Connection: Parameters
Let's go back to our my dance block and add both a parameter and a label so we can add the number of times we want it to run right from the block itself.
When creating our procedure block, we just click on "Add an input, number or text" to add the empty parameter area where we'll enter a value. Give the parameter a name to help identify it.
Then, click "Add a label." Type in the text you want to display after the parameter.
Pre-Coding Connection: Parameters
We now have a define block that looks like this that we copied the my dance code over to. How do we tell the procedure what amount stands for?
All we have to do is drag amount to the spot that it should stand for. Here, it is the number of times we want the whole thing to repeat so we'll need to drag in another repeat block first.
Pre-Coding Connection: Parameters
Now, we want the number entered into amount to be the same as if we were using a repeat block, so we need to drag amount into the spot we would normally enter a number in the repeat block.
This tells our procedure to take the number entered into amount and use it as the value of the repeat block in our procedure.
Pre-Coding Connection: Parameters
In other words, if we enter a "2" in our finished procedure, it's like we entered a "2" into the repeat block that contains amount!
Pre-Coding Connection: Parameters
Here's where our vocabulary is illustrated in the procedure we just made:
Now, let’s add parameters and arguments to custom procedure blocks in Scratch!
Close out
Let’s Review! Lesson Vocabulary
procedure (n): a group of code that has been given a name; also called a function.
parameter (n): the name of a piece of data or information in code that helps make it more specific and requires input, or an argument.
argument (n): the value of a parameter that is input; also called input in Scratch.
Discussion: Animation Cycles
Why is it useful to make procedures that also have parameters?
What other ways can you think of to use procedures that have parameters to improve your programs?