1 An introduction to programming concepts with Scratch (in 5 hours + homework)

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Create a Simple Game in Scratch
30 min Scratch July min intro to Scratch A Quick-and-Dirty approach Leaving lots of exploration for the future. (5 hour lesson plan available)
Michael Parkes Dudley LA What can Scratch do? Make simple games, animations, presentations and stories.
Scratch for Storytelling Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Pong! “The oldest commercially available game in history” Resources created from the video tutorials provided by David Phillips on
Harry Potter Scratch Game
Adventures in Animation Harry Potter Game Pranali Choubal Kunal Shaw Barb Ericson Dec 2007.
1 An intro to programming concepts with Scratch Session 3 of 10 sessions Repetition and variations.
Write Your First Computer Game!. Coding: Programming Languages Just like you can speak Chinese to someone who understands Chinese to tell them what to.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Learn… Create… Program. Manipulation of Multiple Media Connects with youth culture Scratch is a new graphical programming language designed to support.
1 An introduction to programming concepts with Scratch.
An intro to programming concepts with Scratch Session 7 of 10 sessions Working with sounds and sprite communication.
An intro to programming concepts with Scratch Session 2 of 10 sessions I/O, variables, simple computing.
1 An intro to programming concepts with Scratch Session 1 of 10 sessions Looks and Motion.
ITEC Winter An intro to programming concepts with Scratch Quick intro for college citizens. George Stockman MSU CSE.
Digital Art in Scratch part 1 Barb Ericson Georgia Tech Oct 2010.
Scratch Workshop Thursday, August 26, 2010.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
2012 CSE-BEACON camp1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed for.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
Code Club Session 2 Dance Party. What will we learn ?  How to change the background  How to create animations  How to make objects talk to each other.
Introduction to Scratch!
Introducing Scratch the Cat
Objects and Methods in Scratch 1. 2 Scratch environment Stage is at upper right (where actors act and information is displayed) Sprite is another name.
ACO 101 Making a program. mb_your_brain_on_improv.html mb_your_brain_on_improv.html.
2012 CSE-BEACON camp1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed for.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
1 Understand how to use Scratch to: – Animate a sprite – Add sound to your script – Use the forever command to create a loop Lesson 2: Learning Objectives.
Digital Art in Scratch part 1 Barb Ericson Georgia Tech May 2011.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
TRIGGERS Triggers tell a script to start executing There are four types of triggers: When green flag is clicked When I am clicked When is pressed When.
PowerPoint Practice Exercise 1.Save this file on your computer. 2.Open this file in PowerPoint 3.Edit each slide according to the instructions provided.
Making a Sprite Dance Barb Ericson Georgia Tech June 2011.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
24 Background Building 25 Computing Terminology, and Speed/Velocity Module 4 Notes: Sensing, Or Operator, Conditional Logic 28 Module 4 Algorithms,
Variables and Random Numbers Computer App Session 4.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
 SCRATCH is a new programming language that lets you create your own interactive stories, animations, games, music, and art.
Scratch for Interactivity Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
ICT/COMPUTING RULES Only use software allowed by the teacher
Computer Programming Modeling a Passive Solar Home.
Computer Programming with Scratch JAOIT 8. Scratch Scratch is a programming language that makes it easy to create your own interactive stories, animations,
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Introducing Scratch Learning resources for the implementation of the scenario
Create a Halloween Computer Game in Scratch
Scratch for Interactivity
Madlib-Input, Strings, and Lists in Scratch
Spanish Mad libs with Scratch
Scratch for Interactivity
Introduction to Object-Oriented Programming
Learn… Create… Program
Learn… Create… Program
Scratch for Storytelling
An intro to programming concepts with Scratch
Learn… Create… Program
Learn… Create… Program
Creating a Simple Game in Scratch
CSC 221: Introduction to Programming Fall 2018
Presentation transcript:

1 An introduction to programming concepts with Scratch (in 5 hours + homework)

2 Who computes? Scientists Engineers Businessmen Social scientists Artists FBI agents Brain surgeons Gamers Grandparents Everyone uses information in some way. Computers do information processing.

3 What can we do with Scratch? Learn some computing concepts. Learn some practical algorithms. Use Scratch as computing tool. Have fun with Scratch creating stories, games, art.

4 Part I: Looks and Motion Goals: – Learn Scratch programming environment – Learn the looks and motion menus – Write a sequence of instructions

5 Start scratch and let’s go! Click on the cat icon Scratch programming environment comes up We will first do simple things

6 Our Scratch environment Stage is at upper right (where actors act and information is displayed) Sprite is another name for actor. Instruction menus/panel at left (instructions for the actors) A script is another name for program or method; a script tells the actor what to do. Programming area in center; here is where we construct scripts for the sprites

7 We start with the cat sprite We will learn to use many other sprites later. For now we use the cat as our only actor. We script the BEHAVIOR of our cat.

8 The LOOKS menu Has instructions for setting the color, size, and visibility of a sprite. Costumes will be used later.

9 The “hello” script (program) Choose the Looks menu Click on the “say hello” lego block Check your sprite behavior at the right Then click “say hello for 2 secs” Your very first Scratch program!

10 Try some other looks operations (click on menu items) Change color effect by 25 Change color effect by 25 again Hide Show Change size by 10 Change size by 10 again Set size to 100%

11 Let’s write a script to Say “hello” for 2 seconds Then change color by 25 Then think “Hmm..” for 4 seconds Then change color by 75 Then change size by 200 Drag each instruction from the menu to the center script area. Connect them into a single block. Edit the parameters to get the numbers we want.

12 Our script (program)

13 A sequence or block is a simple script or program The first instruction is done first The second instruction is done second The last instruction is done last. (if any one instruction is done, then every on of them is done)

14 The WAIT instruction WAIT is needed to slow down the acting so we can see or hear it properly (computers are too fast sometimes) Get the wait instruction from the CONTROL menu. Ignore the other menu options for now. Insert a wait in our looks script

15 3 second pause between changing color and size

16 Student exercise: write a script to do the following Double the size of the sprite Wait 2 seconds Change the color of the sprite to green Wait 4 seconds Change the whirl effect to 100 Say “That’s all folks!”

17 The MOTION menu How to locate and orient a sprite; moving a sprite.

18 Position on the stage Using the Looks menu, shrink our cat to 25%. Click on the Motion menu. Click to check the box for x-position and y-position Drag your cat around and note its x-y position.

19 Exercises: goto instruction In the Motion menu, drag the “goto xy” instruction to the script panel. Edit the coordinates and click to see the sprite’s position A) goto x=200, y=0 B) goto x=-200, y=0 C) goto x=200, y=-100 Where does the cat go?

20 The “glide-to” instruction Drag the “glide-to” instruction into your script panel. Edit the coordinate values and click to see where your sprites goes.

21 Exercise Create a script to glide the sprite along the sides of a triangle. The first vertex of the triangle is (-100, -100). The second vertex is (200, -100). The third vertex is (50, 100). Make sure you complete the triangle. Change the speed of gliding and run again.

22 Angles and directions Making your sprite go this way and that way

23 Exercise Script Start at ( -100, 100 ) Move 200 steps Turn right 90 degrees Move 200 steps Turn right 90 degrees Move 200 steps Turn right 90 degrees Move 200 steps Use waits if needed to make the motion look smooth

24 Exercise/Homework Script Sprite starts at home base at x=-100; y=-50 Sprite says “I hit the ball” for 2 seconds Sprite runs (east) 200 steps to 1 st base Sprite changes color Sprite runs 200 steps to 2 nd base (north: left turn from 1 st base) Sprite doubles size Sprite says “I hit a double” for 5 seconds

25 End of Part I: Outcomes Student should be able to control the looks of a sprite and its location on the stage. Students should be able to construct sequences of instructions controlling looks and location on the stage.

26 Part 2: Repetition and Variation Goals: – Learn how to program with repetition – Learn how to change costumes – Learn to controll execution (behavior) using special keys

27 The sneezing cat script We repeat 20 times Say “AAAHHHH” for a short time Then grow the cat 5 bigger

28 Exercise: bring the cat size down to normal Repeat 20 times Briefly say “CCHHEEEW” Then shrink the cat’s size by 5 Repeat N times and repeat forever are in the Control menu

29 Exercise: Have the cat do a flip by rotating 20 degrees 18 times. Repeat from the Control menu: set the number of repetitions to 18 Rotate from the Motion menu: set the size of each small rotation to 20 degrees

30 Changing costumes Another way to change the appea rance of a sprite.

31 Making a new costume to animate the bat 1)Get bat2-a sprite from the “sprite box”. 2)Click on sprite 3)Click on “Costumes” 4)Click on “Import” 5)Now get bat-2b sprite from the sprite box

32 Use a loop to make the bat fly! 1) When and repeat from Control menu and 2) next costume from Looks menu.

33 Changing coordinates We can randomly set the location of the bat so it will “flutter”. Set X to a random number Set Y to a random number Move the bat to location (X,Y) Of course, the bat should remain on stage!

34 Using pick random Click the stop sign at the stage upper right to stop the forever loop. Do we need a wait in the loop? Try it to see the change in flying.

35 Controlling the bat’s direction Let’s create multiple scripts. Click space bar for random moves Click right arrow to move right Click left arrow to move left The bat will behave differently depending upon which key is typed! (So, could a gamer catch the bat?)

36 Multiple interactive bat flight 3 different behaviors for the bat

37 Adding a background Click on the Stage icon at lower right Click on Backgrounds Click on bat icon (Sprite1) Click on Scripts FLY AGAIN!

38 Homework/Exercise: Add a behavior (script) to move the bat up with the up arrow. Add a behavior to move the bat down with the down arrow.

39 End of Part 2: outcomes Student should be able to write a program controlled by a loop, and execute a script by clicking special keys. The student should also know how to use “costumes” to change the appearance of a sprite.

40 Part 3: Input/Output, Variables, Simple computing Goals: – Learn how the user and the program can communicate – Learn how to compute with formulas – Computing an average, perimeter of a geometric figure, etc

41 The SENSING menu Getting information from the user or some other machine

42 Asking the age of the user Program wants age of user (maybe to set a level of difficulty in a game) Program asks user for age User types in age Program stores the answer in a variable named “answer”

43 What is your age? Depends on who you are For one person it’s 12 For another person it’s 27 For yet another, it’s 19 IT’S VARIABLE!

44 Use the SENSING menu 1)Ask the user for age; 2) user types in age; 3) result stored in “answer”

45 User types “13” and the script stores the answer “answer” is a Special Scratch variable

46 OUTPUT: Giving the user information with say answer Say is in Looks menu; drag “answer” from Sensing menu; click

47 Using the Variables menu We can save an answer in our own named variable; Then we can program with many data items using many variables

48 Making an “age variable” 1)Click Variables menu; 2) click “Make a variable” 2)Type in “age” and click OK Do you want to display for all sprites or just one?

49 We have an “age variable” Displaying variable “age” Operations for “age”

50 We can join text and a number to say things Build this instruction from the parts above it. From Looks From Operators From Sensing Make the join

51 Storing a value in a variable; then saying it to the user 1)Set from Variables menu; 2) Say from Looks menu; 3) Join from the Operators menu joins your text with the “answer”

52 Using variables in programs A script might have to remember information How far is the cat from the dog? How fast is the rocket moving? Where did the user click on the stage? What is my score in the game? What is the user’s skill level?

53 Computing C = A + B (1 of 3) Make 3 variables, A, B, and C Type in the values of A and B Set the value of C to the sum of A and B

54 Computing C = A + B (2 of 3) Make 3 variables, A, B, and C Type in the values of A and B Set the value of C to the sum of A and B

55 Computing C = A + B (3 of 3) Make 3 variables, A, B, and C Type in the values of A and B Set the value of C to the sum of A and B Drag + operator from Operators menu From Variables menu drag variables A and B into the slots

56 Algorithm for computing the average of two numbers Let the first number be A; say A=12 And the second number be B; say B=15 To compute the average _____________ So the average of 12 and 15 = ________

57 Programming the average A is the first “variable”: A = _____ B is the second “variable”: B = _____ V is the third variable: V = _____ Take the value of A, add the value of B, divide this sum by 2, then set the value of V to this answer. V = (A+B)/2 (how to do it in Scratch?)

58 Script from Variables and Operators menus Drag the variable names into the slots of the operators A formula from the Operators menu Script not yet executed

59 After clicking to execute script The variable V now stores the computed average of A and B

60 Exercise Put a Wait 5 secs in the script between the two set operations for variable V Execute the script and observe the changes in the value of V

61 Exercise Change the values of A and B by editing the script (keep the Wait); Input the age of grandchild and age of grandparent; Click on your script to compute the average of the new A and B

62 Homework/Exercise: average program Modify the average program Ask the user for a value of A Ask the user for a value of B Compute V as the average Report the average to the user Run the program for different As and Bs

63 HW Exercises Average 3 numbers; say 12, 33, and 21

64 Computing perimeter of a rectangle: algorithm Ask the user for length L Ask the user for width W Compute P = (L+W)*2 Report P to the user L=15 W = 10 P = (15+10)*2 = 50 example

65 Review: Getting length from user Ask “What’s the length” and wait Set length to answer Drag from Sensing menu Create this variable Drag from sensing menu

66 Review: Reporting the value of a variable to the user Say join “length =“ length for 2 sec Looks menu Operators menu Drag length variable from Variables menu You type this in

67 Review: Program with user input and output

68 HW Exercise: create the Scratch program we designed Ask the user for length L Ask the user for width W Compute P = (L+W)*2 Report P to the user Show your program to your Grandparent.

69 End of Part 3: outcomes Student should be able to write a program to ask the user for data, compute using the data, and report the answer to the user. Students should be able to compute using common formulas.

Part 4: working with sounds and sprite communication

Part 4 goals Learn how sprites can communicate by sending messages Learn how to play sounds and to input your own voice

Communicating sprites: taking turns by message passing Get cat and dog sprites Suppose cat speaks first When finished, the cat can send a message to the dog to speak When the dog is finished, the dog can send a message to the cat to speak

First behavior for the cat After saying hello, cat sends a message to dog (actually to all sprites)

Dog is activated by hidog1 message Dog send message back to cat (and any other sprites)

Cat’s turn again after hicat2 message from the dog

Dog can have 2 nd touching behavior

Sprites can have many behaviors Activated by clicking green flag Activated by clicking the sprite Activated by a key being pressed Activated by a message from another sprite Activated by touching another sprite

Using sounds Sound library; Speaking in the mike; Importing music

Composing with drum beats

Jodi jumps on the drum Story teller script Jodi’s script

Recording from a mike (or an iPod or other music player) 1. Plug in microphone 2. Pick the speaker sprite 3. Click “Sounds” 4. Click “Record” 5. Click red button and speak 6. Click square button to stop 7. Click triangle to hear it 8. Click “OK” if it’s OK 9. Use name of sound in a play-sound instruction

The Friends Story (play it)

Variations in stories Have several scenes Scenes change with messages or variables Make characters move Make characters hide or show Behavior can change with variables, touching, mousing. Background music for each scene

Learning from examples 1.Click on the FILE tab 2.Click on the OPEN tab 3.Click on the Examples tab 4.Choose an example: for example, try STORIES and MAD LIB 06/02/10

End of Part 4: outcomes Students should be able to program by passing messages. Students should be able to program their sprites to make sounds.