Reading code

Starting from Scratch - Lesson 2

Objectives

  • To become familiar with the Scratch programming environment (blocks, sprites, stage, canvas, controls).
  • To understand and use coordinates in programming.
  • To accurately read, predict and explain visual code.
  • Suggest changes to existing code.

Before the lesson

There are two files for you to download and then upload to Purple Mash to use in the lesson with your class. If you do not have access to Purple Mash, a PDF version of the file is available for you to print. Students can complete the task on paper instead.

First, download this file(Reading Code lesson 2.purplemash). When it opens, click the download button in the top-right of the screen and save it to your computer.

 

 

Then log in to Purple Mash and open your Work section from the menu in the top left.

 

 

From here, click on the upload button.

 

 

Then drag in or browse for the file you saved to your computer and click Done.

 

 

Once it appears in your Work list, click on Set 2Do.

 

 

Then work through the steps to add the Title, description and add the 'Reading Code lesson 2' file as a supporting document.

 

 

Then complete the task dates and assign it to your class as a 2Do to be used in the lesson.

Now repeat this process for the second file Reading Code Quiz.purplemash.

  1. Download it to your computer,
  2. Upload it to the 'Work' area in Purple Mash.
  3. Set it as another 2Do for your class.
  4. Direct students to it at the end of the lesson in the plenary.

 

Using Scratch

If you haven't already, we'd recommend setting up a teacher Scratch account for yourself and student accounts for your class. More information about the benefits of this, and links to where and how you can do both can be found in the 'Before you start' section on the unit homepage. The students won't need their accounts for this lesson, but they will for future lessons and it can take a few days sometimes to get accounts set up. 

Introduction

In the last lesson, we focussed on reading code with the students, first with symbols representing code for a Bee-Bot, and then code from Scratch Jr. In this lesson, we will continue reading code but progress onto the full version of Scratch.

Begin by recapping the previous lesson, ask the students what can you recall from that lesson? What were we focusing on?  The emphasis was on them reading code - being able to interpret and explain a sequence of instructions written in different coding languages. So far, Bee-Bot button symbols and icon-based code from Scratch Jr.

Explain that in this lesson we are going to look at more examples of reading code, but that we are moving on to looking at the full version of Scratch.

Use the images in the teacher slides to display these images of the main screens in Scratch Jr and Scratch. Ask the students, what looks similar and different between the two programs? 

 

 

 

Both have the cat sprite as their main character but have other sprites available as options. Both have a stage (background) that can be changed and edited. There are common colours used for the block categories, e.g. Event blocks are yellow, Motion blocks are blue, Looks blocks are purple and Control blocks are orange. Both have the green flag to use as a 'go' button.

Scratch, however, has a far larger library of coding blocks, the blocks are word-based rather than icons and the possibilities of what you can create are far greater. 

Go to scratch.mit.edu, and click Create at the top of the homepage to start a new blank project.

 

 

 

Give the students a quick tour of the screen in more detail so they get a feeling for some of the main features. The following image is part of the lesson slides.

 

 

Give them 5 minutes to open their own empty Scratch project and explore the screen, and in particular, ask them to take a look through the coding blocks available to see if they can understand any of them for themselves. They should not start building code at this point. 

Ask a few students to share things they have found, but don't expand on any of their findings yet.

Coordinates

There is one concept that will probably need a small amount of pre-teaching for the students to be able to interpret some of the code used in this and the following lessons, and that is coordinates. Coordinates play a major part in the position and movement of sprites on the screen. There are some resources in the lesson slides to introduce the basics of coordinates with first a simple graph.

 

 

And locations on a map. Pick a few of the objects and ask the class to tell you the coordinates for each one, reinforcing the use of X and Y, and that the X number always comes first.

 

 

We can use coordinates in Scratch to set starting positions or change the position of a sprite instantly or by seeing the sprite 'glide' across the screen to a new coordinate.

These two blocks in the dark blue Movement section, are the key to that.

 

 

Scratch uses a four-quadrant coordinate grid that allows you to describe the position and movement of sprites with an X and Y coordinate.

This image shows how the dimensions of the Scratch stage, although it is never visible on the screen.

 

 

The X axis goes from -240 (far left) to 240 (far right). The Y axis goes from -180 (bottom of the screen) to 180 (top of the screen). Students are unlikely to cover these types of coordinates in maths lessons until Year 6, but many already have a basic understanding of coordinates from games such as Battleships or Minecraft, or from maps.

The key things for them to understand are that:

  • The X and Y numbers describe a position on the screen using two number lines (axis).
  • They should know that an X number describes the horizontal (left/right) position and the Y number describes the vertical (up/down) position.
  • A negative number means left (X) or down (Y)
  • A positive number means right (X) or up (Y)

 

The ‘go to’ block makes your sprite jump immediately to the coordinate it displays. As you select the block from the block library you will notice that it will already contain coordinates. These will match the current position of the active sprite. Demonstrate this in Scratch by selecting one of these blocks, then dragging the sprite to a new position on the stage. Then click on the block and the sprite will jump back to its previous position, dictated by the coordinates.

 

 

Scratch makes it really easy for children to get started with using these blocks as they don't need to add the coordinate numbers themselves. They just need to understand what the block does and that each new block will have the coordinate numbers for the sprite's current position.

The ‘glide’ block works in a very similar way but makes your sprite glide across the screen to the coordinate you type in the boxes, rather than instantly appearing there. It also automatically adds the sprite's current coordinate to a block as you select it from the library.

 

 

You can control the speed of the glide by altering the number of seconds in the first box. The students should understand that the larger the number of seconds, the longer it takes for the sprite to reach the coordinate. Decimal numbers can be used in any number box in Scratch for fine control.

You can also see the current coordinates of your sprite under the stage. When you select any sprite you can see its X and Y position (and other information about it) in the box above the thumbnail. This can be useful if you want to make manual changes to the blocks above.

 

 

Main task

Once they have some level of understanding of coordinates and the 'go to' and 'glide' blocks they should be ready to complete the main activity.

This is done in Purple Mash using the writing frame described at the top of this page, or on paper with printed copies of the PDF version. If using Purple Mash, set this up as a '2Do' for your class before the lesson.

If needed, show the class how to access the 2Do you have set from the 2Do section or the notification icon at the top of the screen.

 

 

Explain to the class the activity and point out the 'Think about' section on the left of the screen.  They should read through the code in each box carefully and then use the text boxes to explain in as much detail as they can what they think the code will make happen. For anything they are not sure of, they should make an educated guess.

 

 

Plenary

You can see the actual code from the writing activity HERE in Scratch. You can run the code from there so the students can self-mark their predictions. Talk through each example with the class to reinforce their understanding of each block element.

Finally, ask the class to go back to their 2Do area in Purple Mash and open and complete the Reading Code Quiz. This will help assess their understanding of what they have learned about code written in Scratch today. They can also access it from this URL if you do not have access to Purple Mash: tinyurl.com/readingcodequiz.

You can make your own quizzes like this in 2Quiz!

Go to Tools > Quiz and Game Creation and have a go, they are really easy to make and have a great selection of different types of questions available for different uses.

 

 

We have now covered the Predict, Run and some Investigating aspects of PRIMM

In the next lesson, we will do more Investigating and also give the students chance to Modify existing code for themselves.

 

< Previous lesson

Next Lesson >