Part II: Scratch Programming

CS 1150 PEEE — Fall 2017

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.

General Scratch Background/Information

Storytelling Background

The specifications for the first Scratch assignment are: 1) multiple sprites, 2) animation, 3) sprite interaction, 4) sound, and 5) passing the green flag test. Some further information about those specs is provided below.

I created and shared (in the class studio) my knock knock program. Hopefully, you got a chance to look at it. In any case we will   review it quickly [ run it, and respond to questions ].

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: Work on Storytelling Project

Logistics

Scratch Programming Activity

The main activities for today are:

Next Time:

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

Day 6: Introduce Initials Project

Logistics

Something I forgot

I took some notes when I read your PAC comments regarding the code.org course but forgot to discuss them last time. They are:

Comments? Wonderings?

The Storytelling Experience

I like to encourage/allow students to share what they learned from each assignment. So, What did you learn while doing the storytelling program? Anything you wish to share.   [ Accept & discuss student responses ]

Next: Initials

The next "simple" task will be to draw initials—UNI's and hopefully your own (for at least one partner). The learning activity description provides more information about the task. I will present some information today that should help you prepare and perhaps get started.

Initials Discussion

The initials assignment uses what is called "turtle graphics" to draw something (initials in this case). Turtle graphics originated with the Logo programming language in the 1960's. Essentially you give the turtle, sprite, robot moving instructions mixed with putting the pen down and picking it up to leave behind a trail of where you went. In Logo, the computer was a hemispherical robot with a pen mechanism in its middle. It was called a turtle because of its looks. As an aid to help their thinking children were told to pretend they were the turtle when trying to figure out how to get it to do what was needed. You might keep that in mind as you try to have the computer draw initials.

As with storytelling, planning before coding is a very good idea with the initials project but the planning may seem different because the problem context is different.   What do you think we might want to consider before we start programming?   [ Accept and discuss student responses ]   [ Ensure that those below are included. ]

Build your own blocks

I will briefly demonstrate the process of making your own blocks using the idea of drawing an "A with a height of 100 in the color blue using a pen width of 10. I want to be able to specify where the letter gets positioned. Some aspects of the plan are:

The process for creating my "draw-A" block is provided below. (I will be using the

Any questions, comments, wonderings?

Approaches to Drawing Letters

There are two main approaches drawing letters—relative and absolute. In relative motion the sprite moves from where it is. Of course it must first point in (face) the appropriate direction. In absolute motions the sprite goes to a particular location. The code (script blocks) for each is somewhat different and the values needed to accomplish the task are somewhat different. A prospective math teacher might choose an approach in order to address particular mathematical ideas or calculations. With respect to drawing letters, each likely uses ratio and proportion as height and width of letters are related.

Location

Also with both approaches, we can think of having the letters drawn at some particular location. It is probably useful to think about location in terms of a box/rectangle that encloses the letter. The box will be of a given height and width—with width dependent on height and on the particular letter (an I is much narrower than a W and a P is somewhere between them).

Knowing the height and width and location of the box may not explicitly identify a starting location for drawing the letter. It seems likely that some letters can use the upper left corner as both the location and the starting position for drawing the letter, i.e., B, D, E, F, H, K, L, M, N, P, R, T, U, V, W, X, Y, Z. Others might want to use the top center of the box as the starting location, i.e., A, I, J, O, Q. And some will be very individualized, i.e., C, G, S. This can allow for (require) substantial thinking and planning before coding a solution.

Questions, comments, wonderings?

Relative motion

Relative motion requires the sprite to get to a starting location, face in a particular direction, put the pen down, move a particular amount, and (perhaps) pick the pen up. Often the next step can be accomplished by turning some amount and moving again. Sometimes drawing part of a letter would be followed by moving to a different position to continue the letter rather than turning and moving again. The data requirements for this approach include (at least):

Questions, comments, wonderings?

Absolute motion

For absolute motion one can plan and plot the lines for letters and incorporate height and width values while doing so. The knowledge needed is the starting and ending locations for each line. It (mostly) doesn't matter what direction the sprite is moving or how far apart the two points are. All the sprite has to do is get to the starting location, put the pen down, move (or glide) to the ending location, and pick the pen up.

For most of us this seems like the simplest solution. However, the location of the second point in line will usually be a calculation that involves either the height value or the width value (which may already be in terms of the height value. So, maybe it is not the simplest approach or easiest to understand.

And, for some people including (it seems) children it is more natural to think in terms of moving and turning instead of using the coordinate system. In any case, there are a number of considerations for deciding which approach to take. I suggest you choose the one you understand best (or the one you think your students will understand more easily).

Questions, comments, wonderings?

scratch script for drawing a half circle

Circular elements

For some letters, parts of circles are needed, i.e., B, C, D, G, J, O, P, Q, R, S, U. In these cases a mechanism for drawing arcs or perhaps half-circles (perhaps connected by lines) is appropriate. My examples include the definition for a half-circle instruction/block whereby reasonable curves can be drawn. The half-circle may not be precisely what is called for but we can usually get by with it.

The example given here is a 20-sided regular polygon (not a circle) but it looks like circle unless the diameter gets very large. The circular parts of the letter may need some additional straight lines with them to work properly. For example, the diameter of the circular part of a P should be about half the height but that alone leaves the rounded looking too narrow left-to-right.

Questions, comments, wonderings?

Other considerations

If the code for drawing a letter includes a glide… block or drawing part of a circle, that part typically takes longer than just moving from one place to another with either the move… or the go to… block. This makes part of the drawing occur instantaneously and part of it be visible. That is not good. Making all the parts instantaneous seems not to be the answer so we need to slow down the move… and go to… blocks. We do this by including them in a loop.

If we need to move 100 steps, instead of doing that we move only 5 or 2 steps at a time and repeat that instruction 20 or 50 times. Instead of go to x:-100 y:-80 followed by go to x:<100-height> y:<-80+width> we might replace the second go to… block with glide 0.25 secs to x:<100-height> y:<-80+width> block.

Questions, comments, wonderings?

Next Time

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

Day 7: Scratch Workday (Initials)

Logistics

The main activities for today are:

Next Time:

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

Day 8: Introduce the Game Project

Logistics

Discuss Initials Project

I like to encourage/allow students to share what they learned from each assignment. So, What did you learn while doing the initials program? Anything you wish to share.   [ Accept & discuss student responses ]

Games Background

Most of us have played simple little games on the computers. That will be our next learning activity. In the process we will gain additional experience with variables, see how to use indefinite repetition/looping, do some more animation (can't have a game without it, can you?), see how to use the cloning feature of Scratch, use the if … statement for various purposes, use modularization, and hopefully have a lot of fun.

The assignment/learning activity description contains information on many of the topics we'll address. Hopefully, you've read that.   Do you have any questions on anything addressed there?   [ Respond to student responses. ]

You were asked to consider ideas for your game.   What ideas for games did you consider/come up with?   [ Note & respond to student responses. ]  

The first step in developing a program is to plan the program's activity. As we have discussed before, in Scratch, this will often include:

Any questions or wonderings with respect to those?

Something we might not have talked about earlier is identifying data and data manipulations as a general task in program planning. In this case we probably need to explicitly consider that because one aspect of the activity is to have some "score keeping" capability and using it to provide progression of difficulty in the program.   Any questions or wondering about that at the moment?

And, it is often the case that novice programmers have some particular action in the program that they have no idea how to accomplish. That is not unusual, but it sometimes leaves the programmer in a quandary as to how to proceed.   Are there any issues like that with respect to your game that you would like to discuss?   [ Respond to student issues. ]

My sample game (pretty simplistic)

While finalizing the game activity description, I developed a program as an example. The plan for the program was to:

Have a star move across the top of the screen occasionally dropping a copy (clone) of itself toward the bottom of the screen. The cat sprite can move about on the screen in response to the arrow keys in an effort to "catch" the falling stars before they get to the bottom of the screen (or near it). I want to keep track of the number of falling stars and times they are caught to have a percentage of catches as the score. When a star is caught and the score (percentage of catches) is greater than 75% (or .75) I want to "level up" or add 1 to the level. Whenever the level gets higher the speed of the star's movement and of the falling stars will get higher (as will the cat's speed).

Any questions or wonderings about my plan?   [ Respond to student responses. ]

Demonstrate the program ...  Any questions or wonderings about the program?

Work Time

If there are no more questions or issues, we'll spend the rest of the class working with your partner on planning and developing your game program.

Next Time:

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

Day 9: Scratch Workday (Game)

Logistics

Discussion RE storytelling comments

Building off the pair programming comment above, pair programming is an expected part of this class. The navigator is supposed to watch and make sure s/he understands everything the driver is doing and to spot problems with what the driver is doing. And roles should be swapped about every 30 minutes or so. The only reason not to do pair programming is if you are the odd person out (i.e., Katy at this time). From now on, not utilizing pair programming will negatively affect your A & P score.. (You and your partner are free to discuss the possibility of someone swapping places with Katy.)   Any questions, comments, wonderings, ... ?  

Also, please remember that you are not to use cell phones during class or use your computer to read email or surf the web for anything that is not class-related, etc.

The main activities for today are:

Next Time:

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

Day 10: Scratch Workday (Game)

Logistics

The main activities for today are:

Next Time:

Day 11: Scratch Lists & Mad Libs

Logistics

Discuss Game Project

I like to encourage/allow students to share what they learned from each assignment. So,  What did you learn while doing the game program? Anything you wish to share.   [ Accept & discuss student responses ]

Mad Lib Learning Activity

We are going to start the next project today. It will be a mad lib generator that also allows users to enter new data for the mad lib (and then use the new data in mad libs). The main new thing is the use of lists, but there will likely be some complexity issues also. Hopefully the demo today and the discussion in the assignment description will will allow fairly smooth sailing. I anticipate having two work days on this assignment and that it will be due next Tuesday evening.  Any questions, comments, wonderings before we start?

Make a plan

The project will be much simpler if you do some planning. I used "Hey diddle diddle" as the basis for my mad lib. In doing so, I first laid out how I thought the mad lib might go. It is shown below.

planning for mad lib

My final product was not exactly like this but having the plan sure made working on the project less confusing to me than it would have been otherwise. So, ... Make a plan!

Demo program

I am going to show you my mad lib program which should provide insight into how you can go about producing your own. I will not be "sharing" the project because I feel it is important that you begin relying on my code less and less (if you have not already done so).  [ Run the program, exercising all (kinds of) parts. ]   Any questions, comments, wonderings?  [ Address questions. ] 

Review assignment description content

I want to review the information in the assignment description. You need to be trying to understand what is in there and wondering about things that are not present, i.e., trying to identify trouble spots and stuff I might have left out.  [ Display the assignment description and scroll down discussing aspect of it. ]   Any questions, comments, wonderings?  [ Address questions. ] 

Next Time:

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

Day 12: Scratch Workday (Mad Libs)

Logistics

The main activities for today are:

Next Time:

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

Day 13: Scratch Workday (Mad Libs)

Logistics

The main activities for today are:

Next Time:

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

Day 14: More Drawing with Scratch

Logistics

Discussion RE initials comments

Any other comments or questions?

A Note about Scratch

Scratch sprites can draw while hidden and stamp and create clones. I had always thought that being hidden caused those things not to happen, but it looks like I was wrong (it could be that they changed scratch but probably I assumed and was wrong.)

Extra Credit Project

I have prepared an extra credit project in Scratch (I still need to proof read/finalize it). It asks you to use polygons and spirals to draw a scene. Let me know if you have questions about it.

Polygons

Discuss and demonstrate the following.

Questions? Comments? Wonderings?

Spirals

There are at least two ways to do spirals. One way is to draw a polygon, turn a bit; then repeat those two steps. Another way is to mess up your polygon a bit by turning too little (or too far) and to increase the side length with each turn.  [ Demonstrate both ] 

Next Time:

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

Day 15: Sample Exam

Logistics

The main activities for today are:

Next Time:

Questions? Comments? Wonderings?   ...   See you Thursday.