23
Week 1; Lecture 2 Introduction to Programming using Scratch

Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1; Lecture 2

Introduction to Programming using Scratch

Page 2: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 2

ScratchBehavior Actions Program

Page 3: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 3

Statements

● Simple Statements

● Events

● Control

● Expressions

{

Page 4: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 4

Events: Starting Programs

● Starts programs

● Events are actions that occur outsidethe program.

– E.g. Clicking green flag

● Programs can generate events using“broadcast”

– Broadcast is an asynchronous event

– Broadcast and wait is a synchronousevent

Page 5: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 5

Simple Statements: Motion

● Lets you move the sprite

● You can type numbers into thewhite areas

● You can select from the drop downmenus

Page 6: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 6

ExampleProgram

Behavior

To Run Program

Page 7: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 7

Simple Statements: Pen

● Lets you play draw on the stage

Page 8: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 8

Draw a Square 1

● Reset

● Draw a line

● Turn 90 degrees

● Draw and turn three moretimes

Page 9: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 9

Improving the program

● Lines of code a copied

● If possible avoid duplicatelines

– To change, need to changeall.

– Easy to miss one of thelines.

Page 10: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 10

Control: Choosing next action

● Selection and Iteration

● Selection (if) chooses betweenone of two actions

● Iteration (repeat and forever)repeat actions

– Repeat n times

– Repeat until

Page 11: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 11

Iteration: Repeated Action

● Repeat an action several times

– Number of time to repeat

● Repeat forever

– Requires a way to stop the program

Page 12: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 12

Draw a Square 2

● Reset

● Start drawing

● Four times

● Draw a line

● Turn 90 degrees

Page 13: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 13

Which actions are repeated

● Actions surrounded by the repeatloop are repeated. Here

– 1. Move 100 steps

– 2. Turn 90 degrees

Page 14: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 14

Selection: Choosing Action

● If test is true do the action

– When to choose the action

● If test is true do the actionotherwise do the other action

– If test is true do this

– If test is false do this

Page 15: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 15

Sensing: Getting input

● Determines state of the program

– Diamond are tests

– Ovals are numbers

● Is key pressed

– True when the key is pressed

● We can quit when the space baris pressed

Page 16: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 16

Repeat until key is pressed

Page 17: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 17

Repeat Program

● Repeat forever

– If the space bar is pressed● Stop the program

– Otherwise● Turn 15 degrees

Page 18: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 18

Different description of behavior

● Run until the space bar ispressed

Page 19: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 19

Expressions: Testing andCalculating

● Perform calculations

● Arithmetic expressions calculatenumbers

– e.g. 1 + 2, 3* 4

● Boolean expressions evaluate totrue or false

– e.g. 1 < 2, 5 = 6

– e.g. 1 < 2 or 5 = 6

Page 20: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 20

New Program: What does is do?

Page 21: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 21

More Statements

Sound and Looks

Page 22: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 22

Simple Statements: Sound

● Lets you play sounds

Page 23: Introduction to Programming using Scratchsp.nathanielgmartin.com/wk01/W1L2-Scratch_Control.pdf · Week 1 4 Events: Starting Programs Starts programs Events are actions that occur

Week 1 23

Simple Statements: Looks

● Lets you change the appearance ofthe stage and the sprite