Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

23
Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch Paul Tennent http://paultennent.wordpress.com/G50PRO. html paul.tennent @nottingham.ac.uk Room C41

description

Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch. Paul Tennent http://paultennent.wordpress.com/G50PRO.html [email protected] Room C41. What is Scratch?. - PowerPoint PPT Presentation

Transcript of Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Page 1: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Introduction to Programming G50PRO

University of NottinghamUnit 2 : Introduction To Scratch

Paul Tennenthttp://paultennent.wordpress.com/G50PRO.html

[email protected]

Room C41

Page 2: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

What is Scratch?

Scratch is a free programmable toolkit that enables users to create games, animated stories, and interactive art

Enables users to share programs over the Internet Scratch is developed by the Lifelong Kindergarten

Group at the MIT Media Lab, with funding from the National Science Foundation, Microsoft, Intel Foundation, Nokia, and the MIT Media Lab research consortia.

Page 3: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch
Page 4: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Getting Started With Scratch

Open new project Choose, create or edit your Sprite Choose your background Write your program

Page 5: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Programming In Scratch Click on the sprite you want to program, and select the

“Scripts” tab. The Scripts area is where you “build” your program by using

the programming blocks. In the upper, left-hand corner of your Scratch window, you will

see 8 buttons . Each of these buttons have programming blocks in those

particular areas.

Page 6: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Programming In Scratch

To program a sprite, drag blocks from the Blocks Palette to the Scripts Area. To run a block, click on it.

Create scripts (programs) by snapping blocks together into stacks. Click anywhere on the stack to run the whole script, from top to bottom

Page 7: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Scratch Stage

The Scratch stage is 480 pixels wide and 360 pixels high.

-240

240

180

-180

Page 8: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Scratch Blocks

Motion Animate sprites

Control and Sensing controls how many times an event happens, how long an

event happens, or when an event happens. conditional statements (“if statements” or “if-else

statements”) Write code so that if the user presses the Space key on the

keyboard, the sprite will move 20 steps and change direction.

Page 9: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Scratch Blocks

Sound Looks Pen Operators Variables

Page 10: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Starting From Scratch

Scratch has all of the common elements used in all programming languages.

Conditional statements Loops Variables Events

Page 11: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Branching (Conditional Statements)

Make TeaSTART

Is kettle full? Fill kettle

yes

no

Boil Kettle

Page 12: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Conditional Statements

If [Boolean] Then

Do this Else

Do the other

Page 13: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Comparisons

== Equals < Less than > More than <= Less than or equal to >= Greater than or equal to != Not equal to

Page 14: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Loops

Simplify the coding of repetitive tasks Giving the people in a company a 10% rise

Employee 1 salary = 1.1*Employee 1 salary Employee 2 salary = 1.1*Employee 2 salary … Employee 99 salary = 1.1*Employee 99 salary

Page 15: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Loops

Simplify the coding of repetitive tasks Giving the people in a company a 10% rise

For i = 1 to 99 Employee i salary = 1.1*Employee i salary

Page 16: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Loops

There are a lot of different standard types of loop

Scratch only has some of them

Page 17: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Flow control

Flow control In computer science flow control refers to the

order in which the statements or instructions are executed or evaluated.

Branches (Conditional Statements) Loops

Page 18: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Variables

a variable is a facility for storing data One of the most powerful features of a

programming language is the ability to manipulate variables.

A variable is a named location that stores a value.

Values are things that can be printed, stored or operated on. (numbers, letters, Strings, etc.)

Page 19: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Variables

each variable will have Name Value Location in memory

X = 100

Y = 20

Page 20: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Assignment statement

Declare str

str = “Hello”

the idea is straightforward: When you declare a variable, you create a named

storage location. When you make an assignment to a variable, you

give it a value.

Page 21: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

BankBalancePayment

Check Balance

700

700700

Page 22: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Events

You can’t run all of the elements of a program at once

Things happen when the relevant event triggers them

The main event in Scratch is the green flag There are other custom events that you can

add

Page 23: Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch

Summary

Scratch Programming Blocks Conditional Statements allow us to make

decisions about what to do next Loops allow us to perform repetitive tasks Variables record the values and state of

elements of a program Events trigger different elements of the

program to be run at the correct time