1. Trang chủ
  2. » Giáo án - Bài giảng

Scratch programming

47 466 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 47
Dung lượng 0,96 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Common in programming, for instance, are "loops" whereby a program does something multiple times and "conditions" whereby a program only does something under certain circumstances.. A co

Trang 1

Programming & Scratch

Trang 2

Learning to program is ultimately about learning to think logically and to approach problems methodically

The building blocks out of which a

programmer constructs solutions,

meanwhile, are relatively simply

Trang 3

Problem-Solving and Project-Design Skills

Trang 4

Fundamental Ideas about Computers and Programming

computer programs tell the computer

precisely what to do, step-by-step

writing computer programs doesn’t require special expertise, just clear and careful

thinking

Trang 5

Common in programming, for instance, are

"loops" (whereby a program does

something multiple times) and "conditions"

(whereby a program only does something under certain circumstances Also common are "variables" (so that a program, like a

mathematician, can remember certain

values)

Trang 7

StatementsOne such block instructs a sprite to say something:

Trang 8

StatementsAnother such block instructs a sprite to go

to some location:

Trang 9

To create a program in Scratch, you need to think systematically about the order of steps

Trang 11

Boolean Expression.

Another such block is:

After all, it is either true that some number

is less than another number or it is false

Trang 12

Boolean Logic

and, or, or not are examples of boolean

logic

Trang 13

In programming, a condition is something that must be true in order for something to happen A condition is thus said to "evaluate

to true" or "evaluate to false." In Scratch,

any block whose label says "if," "when," or

"until" is a sort of conditional construct

Trang 14

ConditionsOne such block is:

Trang 15

The previous construct is generally known

as an "if construct." With it can we instruct

a sprite to say hello only if, say, the user has depressed the mouse button:

Trang 16

A related construct is the "if-else construct":

Trang 17

With the previous construct can we instruct

a sprite to say hello or goodbye, depending

on whether the user has depressed the

mouse button:

Trang 18

Realise that these constructs can be nested to allow, for example, for three different conditions This construct could be called an "if-else if-else

construct".

Trang 19

ConditionsAnother conditional block is:

Yet another such block is:

Trang 20

Conditional Statements

if, forever-if, if-else repeat-until and waituntil check for a condition

Trang 21

Sometimes, you want one or more

statements to be executed multiple times in

a row To implement this behavior, we turn our attention to loops

Trang 22

In programming, a loop can induce multiple executions of statements In Scratch, any

block whose label begins with "forever" or

"repeat" is a looping construct

Trang 23

LoopsOne such block is:

This construct allows us, for instance, to instruct a sprite to meow every other

second:

Trang 25

Iteration (Looping)

forever and repeat can be used for iteration

(repeating a series of instructions)

Trang 26

Sometimes, you want execute some

statement multiple times, each time varying your behavior ever so slightly We thus turn our attention to variables

Trang 29

The Variables category allows you to create

a new variable and use it in a program

Trang 30

In programming, a thread is like a

mini-program within a mini-program that can execute

at the same time as other threads

One such block is:

Trang 32

Threads

Trang 33

Notice how, in the above, the left-hand

thread handles meowing, if appropriate,

whereas the right-hand thread constantly

checks and remembers whether the user has muted or unmuted sound by pressing

’space'

Trang 34

Threads (Parallel Execution)

Launching two stacks at the same time creates two independent threads that execute in parallel

Trang 35

In programming, multiple threads can

communicate with each other by signaling events and handling events An event, then, is like a

message from one thread to another.

A block that signals an event is:

Trang 36

A block that handles an event is:

Trang 37

Not only can events be signaled by blocks, they can also be signaled by a user's actions Clicking Scratch's green flag, for instance, effectively signals an event that is handled by:

Trang 38

In Scratch, not only do events enable

threads to communicate, they also allow sprites to communicate with each other

Trang 39

Event Handling

when key pressed and when sprite clicked

are examples of event handling –

responding to events triggered by the user

or another part of the program

Trang 40

broadcast can coordinate the actions of

multiple sprites

For example, Sprite1 sends the message

winner when condition is met:

Trang 41

SynchronisationThis script in Sprite2 is triggered when the message is received:

Trang 42

Real-Time Interaction

mouse_x, mouse_y, and loudness can be

used as dynamic input for real-time

interaction

Trang 43

Time TriggeringScratch includes an internal clock that you

can access with timer.

Trang 44

Random Numbers

The pick random block selects random

integers within a given range

Trang 45

Object-Oriented ProgrammingEach sprite can have its own scripts and data

Trang 46

User Interface Design

You can design interactive user interfaces in Scratch – for example, using clickable

sprites to create buttons

Trang 47

Data Types

Different data types (such as numbers and booleans) are represented by different

shapes in Scratch

Ngày đăng: 07/07/2017, 09:35

TỪ KHÓA LIÊN QUAN