Part II: Scratch Programming

CS 1150 PEEE — Spring 2018

Day 4: Scratch intro

Logistics

Hopefully, everyone joined my class and in the process joined Scratch. Sorry for the confusion.   Any remaining issues?   [ Address responses ]

We'll start today with information about Scratch that should set the stage for a more successful learning experience.

The information below with a light blue background shading is informational and was addressed in class only as students asked questions.

Scratch Intro

Scratch is a block-oriented programming language. That means that the programming environment will show you all the possible instructions. You just need to know how to find them. People say that Scratch has a low floor and a high ceiling, meaning that it doesn't take much to learn how to use it and there are lots of things you can do with it. We'll let you judge for yourself. Some things to know about Scratch are:

  • You can program on- or off-line (online in a Web browser or offline in an application you can download)
  • The URL is scratch.mit.edu (it was developed by the Lifelong Kindergarten Group at the MIT Media Lab)
  • There is a introductory tutorial

General Scratch Background/Information

  • Scripts

    Scripts are collections of blocks that can get executed as a group. All sprites and the stage can have one or more scripts. Scripts start execution when some event occurs. (Look under the Events palette to see the possibilities.) A script can be tested by clicking on it but that is not the same as running the entire program (all the scripts of all the sprites).

    Typically programs start by having the user press the green flag.

  • Each action/block runs until completion

    Within a given script, the first block begins executing when the controlling event occurs. (That is mostly true. The play sound __, say __, and think __ blocks start and the next block will start immediately—these are non-blocking actions.) Thereafter each block starts when the previous one is finished. (That is mostly true. The play sound __, say __, and think __ blocks start and then the following block will start immediately—these are non-blocking actions. You may find others.)

    For example if wait 10 secs is used the block after it will not start until the (approximately) 10 seconds has elapsed. If glide 5 secs to x:240 y:0 is used the block after it cannot start until (approximately) 5 seconds has elapsed.

  • Scripts run in "parallel"

    Scripts of different sprites or different scripts for the same sprite will all run in parallel—at the same time. An individual sprite can have two scripts, each to execute when green flag clicked. Running in parallel means they will both start when the green flag is clicked and run simultaneously. (Actually, true parallelism does not occur. Each script runs for a minute amount of time, then another, then another, etc. until the one that started gets another turn—this is called time-sharing. That's why the times noted above were "approximate".)

    You will want to be aware of parallel execution when you plan and debug your programs.

  • My Stuff (& the "cloud")

    The Scratch system has a record for each user and stores all the programs for each user. The programs are stored/saved on servers (computers) at MIT. You have control of those programs, i.e., can modify program code or the names; share programs (or unshare them); or delete programs (assuming the Scratch folks don't find them offensive in which case they will delete them). However, you have no control over back-ups of the programs and you cannot access them if MIT's server is down or you have no internet access.

    So, you may wish to download copies of programs to your computer to work on offline or to have available permanently.

    One advantage of the cloud is that the server being used is supposed maintain a current copy, i.e., be constantly saving the latest version of the program. However, the server getting very busy or your internet connection going down or ... can interfere with the saving process. You may wish to occasionally go to the File menu in Scratch and select Save now (or click "Save now" in the upper right corner of the screen).

    Also, be aware that if you change the name of the program, the copy under the old name is no longer available. If you wish to have copies of both the old and the new, you will want to use File | Save as a copy, then acces the "copy", enter a new name, and use File | Save now. And, be aware that when you load one of your shared program, you are making changes to the shared program—if you want to make changes without affecting the original, you'll need to save a copy.

    To gain access to My Stuff, click on your username (top right of the window) then click on My Stuff.

  • The ending state is the starting state

    Generally when a program runs, things change. Those changes remain if you run the program again. So, in order to be able to run the program again (and have it work correctly) you need to reset it. Unfortunately, unlike the code.org course, there is no reset button in Scratch. You will need to either set things back to the starting state when the program is done or set everything to the starting state when the program is run.

  • Trouble with right-click on a Mac?—use Shift-Click

Scratch Accounts and Joining My Class

Scratch combines the activities of joining my class and creating a new account. You begin that process by clicking on a link provided me by Scratch. The link for my current class is http://scratch.mit.edu/classes/75287/register/c0b5de6161a24996898c3ee7d3578096. If you have not already done so, click on the link.

Wait and check class status while everyone joins   Questions? Comments? wonderings?

Work on the Polygons and Spiralling Learning Activity

It is my intention that the rest of the class be spent working on the next learning activity. But first, let's make sure everything was okay with the Code.org activity and its PAC activity.   Any questions or issues with either of those?

Examine the Polygons and Spiralling learning activity.   Note that the activity description has a bunch of information included in it. Hopefully, most of your questions are answered there.   Review the specs individually and respond to questions.

The rest of the class period will be spent working on the learning activity. Remind students about the pair programming process—one student at the computer, one (both others) actively watching and suggesting; swap off after a bit (or at the end of each scripting activity). Each pair/group will need to figure out how to share the programs with each other. That could be via the Scratch sharing process or by downloading the program and sharing the file via e-mail, google docs, or some other process.

Pair Programming Reminder

As noted elsewhere, I think, pair programming is a particular way of working together in programming. There are two roles, driver and navigator. The driver sits in front of the computer and types code, runs tests, etc. The navigator watches carefully asking questions, making suggestions, noting possible problems etc. After a bit they swap roles. I suggest swapping occur after about 30 minutes or about half-way through the remaining class time. Questions? Wonderings? Comments?

Each pair will want to agree to ground rules about: whether there are two copies of the work and how that happens, what individual work, if any, is acceptable and if so, how does the absent partner get brought up to date, when you can meet outside of class, howe you will contact each other, etc.

Next Time:

Day 5: Review/Work on Polygons & Spiralling;

Logistics

Scratch Programming Activity

The main activities for today are:

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 6: Animation;

Logistics

Scratch Programming Activity

The main activities for today are:

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Tuesday.

Day 7: Review Polygon etc; Scratch Workday (Animation)

Logistics

Suggestions Arising from the Polygons, etc. Project

Before continuing to work on the animation project, I want to provide some feedback/suggestions based on what I saw with the previous project. I will use some of the projects you did as examples. In doing so, I may be criticizing the work but I am not criticizing the workers. To learn to do better you must be informed of instances where improvement could occur. And, you can also learn from others. So, even though I may not be using your program as an example, pay attention so you can learn also.

New blocks and their parameters

Everyone created new blocks (great)—some had parameters some did not. Some had parameters but did not use them. Most of you seem not to understand the mix of variables, parameters, what to do with the parameters, and how to incorporate user input. Let's look at Rachel, Ashton, & Heather's program.

Scratch script for the stage that controls some drawing

The image to the right is for the stage. It is designed to control the action that a sprite will carry out. (Good idea in my mind.) The image below includes some of the scripts for the sprite. Scratch script for a sprite to do some drawing
We can learn several things from this combination of scripts. First about the stage's capabilities.

But Scratch didn't tell us that anything was wrong, it just ignored the stuff it could not do. (That's why I'm telling you :-)

Next let's examine how the sprite knows what to do. The stage:  1) asks the user to indicate a drawing activity,  2) get's and saves the answer,  3) then asks for the number of sides,   and 4) tells the sprite to do the drawing using the value of sides.  Hmmmm ... How does that happen?

Controlling repeat blocks

When thinking about repetition, it is very important to identify when/how the repetition should stop. Several projects worked similarly to this program. Examine the above code for the stage. Think about how the stage manages to ensure we get a chance to do all three actions.  How does it do it?   Would some other number work?   Comments/suggestions? 

Scratch block definition for a sprite to do a spirograph

Sometimes the repetition should stop after repeating a certain number of times, e.g., 10. Sometimes we will have a variable that tells us how many times to repeat, e.g., the user telling us the number of sides for a polygon. Sometimes will will need to calculate the number of times to repeat, e.g., doing the spirograph. For the spirograph we would probably like to repeat until we would start drawing over what we have already drawn.  When would that happen?  The calculation in this case depends on the how far we turn between drawing each polygon in the spirograph. Consider how much you might want to turn each time.  What amount do you suggest?   Why?  Once you decide how far to turn, it is relatively easy to calculate how many times you need to repeat (essentially, the same as calculation as drawing a polygon).

Scratch block definition for a sprite to draw a spiral

The stopping mechanism for the spiral is probably something different. Consider what happens in a spiral and when you might want to stop.  Without thinking about how to do it in Scratch, what would you like to see happen to stop the drawing of the spiral?  Once we decide how/when we might stop, we need to figure out if we can do that in Scratch. If not (or if we can't think of anyway to do it), we would want to seek help or find a different stopping mechanism. So, let's consider some options—1) after repeating a good guess at the number of times to repeat;  2) after the sides get relatively large (perhaps most of the vertical limit);  3) when the sprite gets to an edge;   4) something else.  Which do you like?   Can/How would we do that in Scratch?  (Repeat for other options.)

Power of repetition when combined with data

Scratch block definition for a sprite to draw a spiral, w/o repetition

The code at the right shows how your people often think about repetion before they have much experience with repetition, or more precisely experience with data and using variables in their programs. In this particular case, it is useful to try to think generally or abstractly about the problem. Instead of thinking move 5 steps for the first side and then move 10 steps for the next side, and so on, we want to learn to think about moving some-number steps, increasing the number, and repeating those two steps.

Scratch block definition for a sprite to draw a spiral, with repetition

The code at the right shows how data and repetition can be combined to do things easily (at least without a lot of code).

The hope is that this discussion has enhanced your understanding of programming and that you will be able to use these ideas to write better programs in the future.  Any questions/comments/wonderings? (about repetition, data, the polygon assignments, etc.)

Animation Assignment Work

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 8: Work on Animation

Logistics

Animation Assignment Work

Next—Story Telling

The next activity will be story telling. Actually, we often start Scratch programming instruction by having students do a story. But a major goal of PEEE is learning programming (rather than Scratch programming) and story telling does not readily lend itself to the inclusion of data in programming.

The story telling assignment will ask that you produce a program that will tell some story. The story can be something you make up or a fairy tale, a limerick, nursery rhyme, etc. School kids will typically enjoy this kind of activity as it provides an opportunity to them to choose what they do and, perhaps, to show their creative side.

So, ... any questions or wonderings about this activity? I will get the assignment created and posted tomorrow or Saturday. What you want to do now is identify your story and plan it out. Decide on actors you need (not necessarily specific sprites), what the overall story is, what the individual actors will do, situations that involve deciding on actions that should occur, situations that involve repeating some actions, etc.  Questions/Wonderings?

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Tuesday.

Day 9: Review Animation;  Work on Story

Logistics

Learning from Animation Activity

Anything learning about programming or Scratch from the animation activity that you want to share?  Some things that occurred that I think worth pointing out are:

Work on Story Assignment

Any questions or issues with the story telling assignment?   [address questions/issues]   [ students work on assignment ]

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 10: Scratch Workday (story)

Logistics

The main activities for today are:

Next Time:

Day 11: Scratch Workday (initials)

Logistics

Initials Learning Activity

I asked that you read/study the next learning activity addressing initials drawing.   Do you have any questions about the initials drawing activity?   [ after addressing question, students work on the assignment ]

Data is a focus

Note that a focus of this activity is data.

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 12: Scratch Workday (initials)

Logistics

The main activities for today are:

Next Time:

Questions? Comments? Wonderings?   —   Have a good weekedn! See you Tuesday.

Day 13: Scratch Assignment Intro (trivia)

Logistics

The main activities for today are:

Next Time:

Questions? Comments? Wonderings?   —   Have a good weekedn! See you Thursday.

Day 14: Unsupervised Work on Trivia Assignment

I am/will be off campus attending a conference. The goal is that students come to class and help each other work on the current trivia assignment

Next Time:

Questions? Comments? Wonderings?   ...   Have a good weekend! See you Tuesday.

Day 15: Scratch Trivia Workday

Logistics

The main activities for today are:

Day 16: Close out Scratch

Logistics

The main activities for today are:

For Next Time

Next time we will review the programming exam taken today and introduce the Logo programming language. Please complete the following tasks between now and next Tuesday's class.