Intro to CS Monday, August 29
Today’s Objectives Review SNAP! one more time Explore More Blocks If/Else Repeat Forever Broadcast Ask/Answer Boolean (and, or, not) Global and Local
SNAP! User’s Manual http://snap.berkeley.edu/SnapManual.pdf Ch 1. Blocks, Scripts, Sprites Ch 2. Saving and Loading projects Ch 3. Building a Block Ch 4. First Class Lists Ch 5. Typed Inputs Ch 6. Procedures as Data Ch 7. Object Oriented Programming Ch 8. The Outside World Ch 9. Continuations Ch 10. User Interface Elements Index
The Actors in the “Play” The Stage Actor 1 (Sprite 1) Actor 2 (Sprite 2) Actor 3 (Sprite 3) Scenery Script 2 Script 3 Script 1 Costume 1
Customizing a Costume
Example: Find a Mario costume First, find one you like. One way is to search for “mario” in Google Images. Then drag the one you like to your desktop.
Example: Find a Mario costume Then, import it as a costume for one of your Sprites by dragging it from your desktop.
Exercise 1: Add, remove and reposition sprites Find an image that you would like for your Sprite Add it to your workspace as a Sprite “costume” Replace existing costume with your new one Repeat this process – but only this time draw a STICKMAN Sprite with one leg longer than the other using the graphical editor.
What worked? What was difficult? Lab Exercise 1 Recap: Discussion What worked? What was difficult?
Lab Exercise 2: Rotation Create this simple script, then run it. Pick your stickfigure figure Sprite with one leg purposely longer than the other TIMING: 4 mins (total 8Mins) ACTUAL: 4 min (10 total), Today, let’s do a deeper dive into the Pen block set. Who can tell me what these do: - Pen Up - Pen Down - Clear - Set Pen Color? - Set Pen Shade - Stamp Who can tell me what the following block does?
Lab Exercise 2: Rotation Did any of you get this? Why? Click each of the three buttons and try it again. What was different? What happens with “rotate 180 degrees?” TIMING: 4 mins (total 8Mins) ACTUAL: 4 min (10 total), Today, let’s do a deeper dive into the Pen block set. Who can tell me what these do: - Pen Up - Pen Down - Clear - Set Pen Color? - Set Pen Shade - Stamp Who can tell me what the following block does?
Did any of you get this? Why? Lab Exercise 2: Recap Did any of you get this? Why? TIMING: 4 mins (total 8Mins) ACTUAL: 4 min (10 total), Today, let’s do a deeper dive into the Pen block set. Who can tell me what these do: - Pen Up - Pen Down - Clear - Set Pen Color? - Set Pen Shade - Stamp Who can tell me what the following block does? can rotate only face left/right can’t rotate
What worked? What was difficult? Lab Exercise 2 Recap: Discussion What worked? What was difficult?
Exploring More Blocks: Variables What is a GLOBAL VARIABLE? When would you use a GLOBAL variable instead of a SCRIPT variable?
Exploring More Blocks: Broadcast What does this do? It puts the scripted value into “message”
Exploring More Blocks: Ask and Answer What does this do? It puts the value typed by the keyboard into “answer”
Question? What are the differences between When would you use each?
Example of all 3 at once
Lab Exercise 3: Variables There is a problem with this script. Can you find it? Write your own script that fixes it.
What worked? What was difficult? Lab Exercise 3 Recap: Discussion What worked? What was difficult?
Exploring More Blocks: Sensing
Exploring More Blocks: Control These CONTROL blocks control the operation of the SCRIPT. (As opposed to SENSING blocks that control the SPRITE.) What do they do?
Exploring More Blocks: Operators What is a BOOLEAN OPERATOR? How do these work? Conditions that when evaluated result in the answer of “true” or “false.”
Exploring More Blocks: Boolean Operators If BOTH Condition “A” and Condition “B” are true, then TRUE If EITHER Condition “A” or Condition “B” is true, then TRUE If NOT Condition “A” then TRUE When you NEST boolean operators, solve inside out
AND (both have to be true) Battery Switch A Switch B Switch A closed Switch B closed? Lightbulb ON No Yes YES!
OR (either one has to be true) Battery Switch A Switch B Switch A closed Switch B closed? Lightbulb ON No Yes YES!
OR (either one has to be true) Battery Switch A Switch B Switch A closed Switch B closed? Lightbulb ON NOT Switch B closed? (Switch B NOT closed) Lightbulb On? No Yes YES! Yes No YES! No
Lab Exercise 4: If/Else & Boolean Start with your Lab 3 script. Add a variable that counts the number of times your Sprite has hit an edge. Call it “# WALL HITS.” If the Sprite hits the wall AND the # wall hits is less than 3, change directions and keep going. If the Sprite hits the wall, and the # wall hits is 3 or more, then say Game Over and stop.
What worked? What was difficult? Lab Exercise 4 Recap: Discussion What worked? What was difficult?
Review: Today Reviewing the SNAP! IDE Costumes More Blocks Stage, Palette, Blocks, Scripting area, Toolbar Costumes Import, Draw, Rotation More Blocks Control: forever, repeat, if, if/else, wait Sensing: ask/answer; broadcast/message Variable: global, script Operators: and, or, not
Reminders Read Chapter 2 before the start of class on Wednesday, September 2nd Quiz – Sept 6nd Test on Friday, Sept9 on computer parts and SNAP!