30
Scratch Intermediate Programming Level 2

Scratch Intermediate Programming Level 2. What You’ll Learn… About computer programming and programming languages A basic understanding of object-oriented

Embed Size (px)

Citation preview

Page 1: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

ScratchIntermediate Programming Level 2

Page 2: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You’ll Learn… About computer programming and programming languages A basic understanding of object-oriented programming About states and behaviors of objects How to create the illusion of depth in a two-dimensional space Advanced use of Scratch tools and techniques to program a

computer animation or game To understand how programming statements can affect the

behavior or appearance of objects The process of programming and debugging

Stuff You’ll Need… Scratch Account

Page 3: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Evernote Suggestions… Write down three interesting things you learned every day that you used

Scratch. Keep a glossary of words you learn during these activities. Pay particular

attention to the bold, italicized words you find Keep a record of blocks you explore and list their function. Explain how you chose a sample or use an existing project for this

Challenge. Explain what the sample or downloaded project you chose does and how it

is programmed. Give examples of objects, states and behaviors.

Extra Credit: Explain how you modified the project to do something different. If you downloaded and modified someone else’s project, explain how yours

is different, what you changed, and why. Keep a record of your programming work in progress. Use screen captures

to show the steps you used to create a program. Describe how to debugged your program. Use screen shots to show how

you changed and tested your program until it was correct.

Page 4: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

Before beginning the activities in this Learning Launcher, you should already be familiar with basic programming in Scratch. You should:

Be familiar with the Scratch workspace and how to use its basic programming tools

Be able to create a simple animation using the Sprites, Palettes, and Blocks provided by Scratch

Know where to find Scratch resources online

If you are unfamiliar with these concepts, you may want to consider Redoing Scratch Level 1 first.

What you should already know!

Page 5: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…Computer ProgrammingComputers are essentially very complicated systems of switches. Each switch can be on or off. These two states are represented as a 1 or 0 in a system called binary code.

The first computer programmers had to actually program using binary code! As you can imagine, it was almost impossible to do anything very complex this way. Today, we program computers using programming languages that simplify our work tremendously.

Programming languages use simple commands. Commands can be organized in different ways to control the behavior of a computer.

There are many types of computer programming languages. Each language has different abilities and uses.

We use a mechanical switch to control this light.

The commands for light are simple. The light can be in one of two states,

“on” or “off”.

You might be surprised to learn that computers are

really just complex systems of switches that

work in a similar way!

Page 6: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…Hello WorldLearning a computer language is a challenge. One challenge that beginning programmers often try is called, “Hello World”. The challenge is to teach the computer to write, “Hello World” on the screen. Below are several examples of commands in different computer programming languages to tell the computer to write, “Hello World”.

Fortran 77 C++

JavaScratch

Page 7: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…Hello World

Notice the difference between Fortran 77 (a programming language created in 1977) and Scratch. Both tell the computer to write, “Hello World”. Fortran uses lots of letters and symbols. Scratch uses blocks. Scratch also controls objects, called Sprites, to perform the command so that you immediately see the results of your programming. In Fortran, you would run the program and the computer screen would show the words, “Hello World” on the screen.

Fortran 77 Scratch

Page 8: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

Scratch uses a popular type of computer programming called object-oriented programming to control the appearance and behavior of objects. Object-oriented programming simplifies the job of computer programming by bundling lots of instructions into a module or object.

Computer objects are like objects in the real world. Every object has a state and a behavior.

For example, let’s think about a dog. The dog’s state includes its name, its color, breed, size, and other characteristics. In object oriented programming, “state” are characteristics of an object. The dog’s behavior includes sleeping, running, barking, and the other things dogs do. In computer programming, “behavior” is the things an object can do.

The state of the dog on this page is white body with dark

brown or black spots. Its’ behavior is sitting.

Object-Oriented Programming

“Java”, one of the most popular programming

languages used today, is an example of object-

oriented program language!

Page 9: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

Computer objects can only look and behave the way you instruct them to look and behave.

Computer objects, like a Sprite in Scratch, can already be programmed with certain states and behaviors. You can program a game or animation with commands that use its existing programming, or you can use Scratch to modify or create new states or behaviors.

You can teach an old dog new tricks!!

Object-Oriented Programming

Page 10: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

In the Level 1 Learning Launcher, Computer Programming and Animation, we explored how to control the state and behavior of Sprites. We worked with various blocks from motion, looks, sound, and control palettes.

Let’s test your knowledge about using palettes and blocks to control the Sprite’s appearance and behavior.

Look at the set of blocks above. What

will happen when the green flag is clicked?

Record your answer in your Portfolio.

Programming with Scratch

Answer: The Sprite will take one step, the drum will beat once as the Sprite steps. The behavior will repeat 10 times.

Page 11: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

Did you get the right answer?

Now, compare these two sets of blocks. Notice that the same blocks have a different order.

Set 1 tells the Sprite to move 1 step, the drum to play when the Sprite moves, and repeat this 10 times.

Set 1 Set 2What happens when the green

flag is clicked for Set 2?Hint: Look at the order of the

blocks.

Before going on, answer the question and save it in your

Portfolio.

Programming with Scratch

Answer: After clicking the green flag, the drum beats once then the Sprite takes one step 10 times. The drum does not repeat.

Page 12: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

We learned that the order of the blocks can change the behavior of the Sprite!

Set 2

Set 1What can we learn from comparing Sets 1 and 2?

Remember this exercise. It’s important to check each set of blocks to make certain that the Script will perform the way you want!

Programming with Scratch

Page 13: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…More about Motion Blocks

Let’s review two approaches. One system uses angles, from 0 to 360 degrees. Another uses the coordinate system and pairs of numbers (X,Y).

In order to create games and advanced animations, we need to learn more ways to move the Sprite.

In your science and math classes you have learned different ways to describe the position and direction of movement of objects.

Page 14: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

Your Sprite appears in the center of the Stage when you open a new project.

To get the Sprite to turn clockwise or counter clockwise, use the turn blocks and enter the number of degrees, 0-360, you want it to turn.

The Turn block tells the me to turn 90

degrees clockwise.

Motion: Turn Blocks

Page 15: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…Motion: X,Y Coordinates

x: 100 y: 50

Finding X and Y

To tell the Sprite to move to a specific place on the Stage, use the X,Y coordinate system. The Sprite begins at the center of the grid where X = 0 and Y = 0. Select the “go to” block and enter the X and Y values. The block below shows the values (100,50). Compare the position of the Sprites.

To find the X,Y values for a place on the Stage, place your cursor where you want the object to go. Next, read the X, Y values in the bottom right corner of the Stage.

Page 16: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

How do you make an object appear to move away or toward you on a two-dimensional (flat) Stage?

Hold your finger in front of your nose. Move your finger toward and away from your nose. Notice that the finger appears to change size. Does it really? No. But, as your finger moves away from your eyes, it appears to shrink.

To give your Sprites the illusion of movement, you need to change their position and size. Notice that the size of the airplane changes in the two pictures. The cat Sprite stays the same so it appears that the plane is moving towards the cat.

The Illusion of Depth in 2D Space

Page 17: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

There are two ways to change the size of a Sprite.

Right click on the Sprite to set the size of the Sprite from the start.

Use Looks blocks to program a change in the size of the Sprite during the animation.

The Illusion of Depth in 2D Space

Page 18: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…Explore More Blocks

Trial and ErrorAdd a block to a green flag and see what happens to the Sprite.

Right Click & ReadRight click on the block to learn what it does.

Take the next 10-20 minutes and explore the many different blocks you’ll find in the Scratch palettes. There are two ways to figure out what a block does – trial and error, and right-click and read. Try both. Which do you prefer?

Page 19: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

We covered the next two slides in Level 1, but it’s worth taking another look!

Remember that almost EVERY program goes through a debugging process! Take your time and try not to get too frustrated. The answer is always somewhere right in

front of you!!

Page 20: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…

“It didn’t work!!” You’ll find yourself saying that a lot as you work with Scratch (or, for that matter, any other method of computer programming).

That’s because computer programs are rather “simple-minded”; they do exactly what they’re told – no more, no less. They don’t know what you want your program to do, they can only perform each instruction literally and in the exact order given.

When creating a program with a complex set of instructions, you are bound to miss an important step or have something in the wrong order.

When this happens (and it will), you need to debug your program. The most important element of the debugging process is always the same: Don’t get discouraged, you can fix this!!

SmartLabs are all about problem-solving, so approach it like a puzzle and have some fun!!

Programs only do what they’re told

Page 21: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

What You Should Know…Debugging Your ProgramHere are some important things to keep in mind:

You’re not alone! Virtually every computer program must be debugged. In fact, software companies often continue debugging for years after software is released to the public!

First, think about how the program is behaving unexpectedly – often that will be your best clue to the problem.

Second, carefully examine each program step in order to identify the problem instruction(s).

If you have multiple program modules, try playing each one separately to see if that helps you find the problem.

Your program IS working; it’s performing each step exactly as instructed, it’s just not doing what you expected! So all you need to do is find the instruction that’s causing the unexpected behavior. Most of the time the problem comes down to something simple. A problem with a single instruction can often lead to dramatically unexpected behavior.

Don’t give up! With Scratch everything you need to solve the problem is

right in front of you!

Page 22: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Do It! Intermediate Programming ChallengeYour challenge is to explore an example Scratch project and then modify it to do something different!

First browse the sample project collection in Scratch. Click: File>Open>Examples

Page 23: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Do It!

The example projects that come with Scratch are organized by project category, like Animation, Games, and so on.

Simplest

Most Complex

Within each category folder, the projects start with the simplest and get more complex with each project.

So, for example, in the Animation category, 1 Playground is the simplest and 8 DayDream is the most complex.

Explore a variety of projects and pick whatever category and project looks most interesting!

Intermediate Programming Challenge

Page 24: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Do It!

Once you’ve selected your project, review the original script for the project you plan to modify. Make sure you understand how the project is programmed and can explain it in your Portfolio!

Intermediate Programming Challenge

Page 25: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Do It!

Downloading Projects & Galleries from the Scratch Website

If you prefer, you can check out Projects & Galleries on the Scratch website and download a project created by another Scratch user. Follow the steps below to find and download a project that interests you.

Study the existing scripts carefully and explain how the programming works in your ePortfolio.

1.Open the Project or Galleries Page2.Select the Project or Gallery3.Select Download this Project (or Gallery)4.Save the Project or Gallery5.Open the Project or Gallery in Scratch

Intermediate Programming Challenge

Page 26: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Do It!

Now, think about ways you can modify the project you selected. You can change it any way you want – add or change Sprites, change their motions and sounds, use new controls and sensors. Be creative!Be as specific as you can about how you will change the program – this will be your project objective!

Intermediate Programming Challenge

Once you’ve created your objective, you can begin programming. Be sure to document your programming and debugging process in your ePortfolio! Explain how each change to the script changed the state or behavior of the Sprite.

Page 27: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

A big advantage for programming in Scratch is the huge online user community! You can find lots of project ideas, tutorials, and helpful hints online. You can download other user’s projects and build upon their work. You can even post your own projects (the next slide will show you how)!

Go Online for Ideas, Help, Tutorials and to Share Projects

Check out the official MIT Scratch Site: http://scratch.mit.edu/ Browse the many great tutorials on YouTube (if you can’t access YouTube from

your SmartLab, you may have to do this from home) Explore the video tutorials at http://learnscratch.org/ Do an online search for other great Scratch resources and tutorials (HINT: Search

for “Scratch software” or Scratch MIT” to narrow your search)

Extend Yourself…

Page 28: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Scratch allows you to share your work with others who use Scratch.Steps: 1.Once you complete your project, select the Share menu. 2.Select, “Share This Project Online…”3.Complete the form and Click, “OK”.4.If you do not have an account, click on “Create account”.

a. Create account will take you to the Scratch website.

b. Select, “Signup” c. Return to Step #2.

Share Your Projects Online

Extend Yourself…

Page 29: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Extend Yourself… Explore other palettes and blocks to learn more ways to control the

behavior or appearance of a Sprite.

Create a list of links to helpful Scratch online resources for your classmates

Go online and explore careers in computer programming. What kind of education do computer programmers and software engineers require?

Go online to learn more about object-oriented programming.

Swap programming ideas with a friend to share and learn new ways to control the computer animation.

Explore the Scratch activity cards. Pick a card and see if you can solve the programming challenge. Or take turns challenging your partner!

Page 30: Scratch Intermediate Programming Level 2. What You’ll Learn…  About computer programming and programming languages  A basic understanding of object-oriented

Extend Yourself…The Power of Moore’s Law

In 1965, Gordon Moore, co-founder of Intel, recognized a pattern in the development of electronic circuits. The number of transistors added to a circuit increased at a predictable rate. Computers use transistors to communicate information. The more transistors on a chip, the faster it performs complex calculations or programs.

Go online to learn more about Moore’s Law. Do you think it is still true? If so, will it remain true in the future? Does anything else seem to follow a similar pattern?

"The number of transistors incorporated in a chip will

approximately double every 24 months."