0% found this document useful (0 votes)
519 views69 pages

Programming in Scratch

Scratch is a visual programming language used for educational purposes. It has four main elements: the stage, sprites, scripts, and programming palette. Sprites are images that perform actions controlled by scripts. There are eight categories of blocks: motion, looks, events, control, sensing, operators, variables, and sound. A project is created by adding sprites, backgrounds, scripts to make the sprites move and interact. Projects can be saved and run in presentation mode for testing before sharing.

Uploaded by

simeon taiwo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
519 views69 pages

Programming in Scratch

Scratch is a visual programming language used for educational purposes. It has four main elements: the stage, sprites, scripts, and programming palette. Sprites are images that perform actions controlled by scripts. There are eight categories of blocks: motion, looks, events, control, sensing, operators, variables, and sound. A project is created by adding sprites, backgrounds, scripts to make the sprites move and interact. Projects can be saved and run in presentation mode for testing before sharing.

Uploaded by

simeon taiwo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 69

PROGRAMMING IN

SCRATCH
DAY 1: INTRODUCTION TO
SCRATCH
WHAT IS SCRATCH?
Scratch is a high-level block-based visual programming language. It is
an educational tool for programming.
Explaining key terms: A high level programming language is a
programming language with strong abstraction from the details of the
computer. A visual programming language is any programming
language that lets users create programs by manipulating program
elements graphically rather than by specifying them textually.
There are four main elements in Scratch: the stage, the sprites, the
script, and the programming palette.
RUNNING APPLICATION IN
PRESENTATION MODE
Presentation mode, also called full screen
mode is accessed by clicking on the button at
the top right of the scratch program. This
displays your application in full screen, it
presents your project. Projects are tested
before uploading. While in presentation
mode, projects cannot be edited.
WORKING WITH SPRITES
Sprites are images you can create and program in the
scratch interface. They can take the form of shapes,
characters, animals, people, and more.
A sprite performs functions controlled by scripts. Think of
a sprite as an object in your program that will perform
actions.
You could work with multiple sprites, animate them, make
them interact. Sprites are like cast in a show or movie.
WORKING WITH SCRATCH
TOOLBAR
The toolbar is located at the top of the program and it contains many
important functions in Scratch.
At the extreme left is the text ‘SCRATCH’ .
Next is an image of a grey sphere or a globe. Clicking on this offers a drop-
down list with all the languages that Scratch is available in.
Next, there are several menu options:
File menu:
• New: creates a new project from a blank template.
• Load from your computer: opens an already existing project saved on
your computer.
WORKING WITH SCRATCH
TOOLBAR
• Save to your computer: this saves your current project.
Edit menu:
• Restore: this would undo the last action carried out in the current
project.
• Turbo mode: sets the player into turbo mode where the code is
executed very quickly.
Tutorials: this shows a series of guidelines on how to create various
projects.
Scratch project: this just species that you’re working on something.
WORKING WITH SCRATCH TOOLBAR

The question mark sign: located


at the extreme left. When
clicked, produces a drop-down
menu: about, privacy policy, and
data settings.
SWITCHING BETWEEN CODE
BLOCKS GROUPS
Blocks are lines or blocks of code which you drag into your project to
create a script. A script can have as many blocks as possible.
Blocks are also known as puzzle-piece shapes that are used to create
code in scratch. The blocks connect to each other like a jigsaw puzzle.
Blocks are categorized based on their functionality, and blocks within
the same category share the same color.
Scratch gives you eight categories of block, each of which includes a
number of blocks you can use to do similar jobs.
It is possible to switch from block group to the next.
DAY 2: BASIC COMPONENTS OF
SCRATCH PROJECTS
WORKING WITH BLOCKS AND STACKS
As mentioned earlier, blocks are codes you drag into your project to create a
script.
A stack block is a rectangular block that is shaped to fit above and below
other blocks. These types of blocks make up the majority of block available in
Scratch, being available in every category except one.
Scratch has over 100 coding blocks, and each one has a unique use. They are
all color-coded into 8 different categories. You can also create your own block.
So basically, stack blocks are code blocks with a notch at the top and a bump
at the bottom. The notches and bumps show you how the blocks can be
snapped together, like Lego, to create a script.
THREE BASIC TYPES OF SCRATCH
BLOCKS
• Command blocks: Command blocks have notches at the top and bumps on
the bottom. They are designed in a way that allows them to be connected
(stacked) to other blocks.
• Blocks which link events with the running of the program: These blocks
have “hats”. This means that they can only be placed at the beginning of a
stack of blocks. We usually start a script with one of these blocks. On the
bottom, they have bumps, which allow new blocks to be added to them.
• Blocks which control the running of the program: Similar to command
blocks, the blocks controlling the running of the program have notches at
the top and bumps on the bottom. We can put them above other blocks,
as well as put other blocks below them.
EIGHT CATEGORIES OF SCRATCH
BLOCKS
There are eight categories of blocks in Scratch:
• Motion blocks: Motion blocks are what you use to place your sprites
on the stage or move them. They are dark blue. You can only use
motion blocks with sprites, not with the stage.
• Looks blocks: Looks is one of the ten categories of Scratch blocks. They
are color-coded purple, and are used to control a Sprite's appearance.
• Events blocks: Events blocks are the most important set of blocks you'll
use in Scratch. If you don't have an Events block, your script can't run.
Events blocks tell Scratch when to start running the program by setting
a triggering moment, such as clicking the green flag.
EIGHT CATEGORIES OF SCRATCH
BLOCKS
• Control blocks: Control blocks are color-coded gold and are used to
control scripts. The block pauses its script for the specified amount of
seconds, the wait can also be a decimal number. Blocks held inside
this block will loop a given amount of times, before allowing the script
to continue.
• Sensing blocks: Sensing blocks are one of the eight categories of
Scratch blocks. They are color-coded light-blue, and are used to detect
things. They can be used to determine the location of the mouse-
pointer, its distance from other sprites, and whether a sprite is
touching another sprite.
EIGHT CATEGORIES OF SCRATCH
BLOCKS
• Operators blocks: The Operators blocks are used to compare variables
and values, do calculations with numbers, and work with strings
(text).
• Variables blocks: This block is used to reports the value of a variable.
There is an extra category.
My blocks: These allow you to create new blocks for a sprite. You give
the block a name and then define what the new block does using other
blocks. You can use your new block in any script on the sprite that owns
the block.
DAY 3: MR. WIGGLY’S DANCE A QUICK
SCRATCH PROJECT
STEP1: CREATING A NEW SCRATCH PROJECT
Click the file project button, and then tap on new.
The first thing you see in the sprites section after
your new project finishes loading should be a
Scratch Cat Sprite. If you want that sprite for your
project, leave it.
STEP2: ADDING A BACKGROUND TO THE STAGE

Press the backdrop button near the sprites


and then go to costumes of backdrop to add
more backdrops. there are scripts to change
it while running program.
STEP3: ADDING AND REMOVING SPRITE
To add a new Sprite, click either the buttons beside new sprite. Choose
from the library, paint your own sprite, upload your own image or
sprite, or take a picture (from your webcam). You can drag the objects
to wherever you want.
Click on the small bin icon at the top right side of the sprite to remove
or delete it.
STEP4: ADDING MR WIGGLY’S MUSIC
To add music and sounds to your Scratch project, click on the sound
category in the upper left.
STEP5: PLAYING THE DANCE MUSIC
Once the sound has been added, click on the play button to play it. You
could also repeat the sound so that it would play a certain number of
times.
STEP6: MAKING MR WIGGLY DANCE
Add the desired sprite, then change the costume after you wait for a
little while, so that the sprite would take different positions, and this
would make him dance.
STEP7: SAVING AND EXCUTING YOUR NEW SCRATCH

Click the ‘file’ button at the top left corner of your screen. Select ‘save
to your computer’. Choose the destination you want your project to be
saves at. Rename the file, and click on ‘save’.
DAY4:MOVING THINGS AROUND
WORKING WITH MOTION CODE BLOCKS
Just as the name says, motion blocks sets which ever sprite you’re
working on in motion. You could move a certain number of steps, or
turn around, go to a specified position, amongst many others.
All you need to do is drag the block you would want to use.
MOVING AND ROTATING SPRITES
If you want the sprite to move, then use the following code:
When green flag clicked forever if up arrow pressed change y by 10, if
right arrow pressed change x by 10, if left arrow pressed change x by -10,
and if down arrow pressed change y by -10. If you want it to go faster or
slower, change the numbers in code.
To rotate a sprite:
It has a single input parameter where you can set the number of
degrees it should rotate the sprite.
Blocks that designate direction can be used instead of a number
by placing them in the circle to replace it.
SETTING SPRITE DIRECTION
A sprite's direction value controls how much a sprite is rotated. It is
measured in degrees (°) and ranges from -180° to 180°.
Select the ball sprite from the sprites list, and find the script that
contains the point in direction () block.
Let's simplify the direction change. Drag the green number block that
currently contains the calculation 90 - direction out of the value of
the point in direction() block. You can drag it down to a blank spot in
the scripts area. Change the value of the point in direction block to 180.
CHANGING AND REPOSITIONING OF SPRITE
The look of a sprite can also be changed by using costumes. The current
costume of a sprite can be changed by clicking on the "costumes" tab
and clicking on the desired costume of choice, or by using Looks blocks
to select the sprite's costume.
Go to Your Starting Point, reset your sprite at the beginning of the
game. Drag your sprite to where you want it to start. Then, click the
motion category.
WORKING WITH SCRATCH CARDS
Scratch Cards are cards that are used to teach Scratchers(these are
people that use Scratch) how to program in Scratch. These cards do not
require a computer to learn Scratch; users can quickly learn how to
program in Scratch, no matter where they are. Scratch Cards can also
be used for reference. 
Because of their portability and simplicity, Scratch Cards can be used
when Scratchers first start learning Scratch, and can be used by Scratch
clubs and classes.
DAY 5: PROJECT
DAY 6: SENSING SPRITE POSITION AND CONTROLLING
ENVIRONMENTAL SETTING
The Scratch Folder environment setting is the location of a folder you
can use to write file-based data, such as shapefiles, text files, and layer
files. Writing output to the scratch folder will make your code portable,
as this folder will always be available or created at execution time.
The primary purpose for the scratch workspace environment is for use
by Model Builder. Model Builder needs a workspace to write
intermediate datasets—datasets that are of no use once a model is run.
Although its primary purpose is for Model Builder, there may be times
when you want to set it for tool dialog boxes.
WORKING WITH SENSING CODE BLOCKS
Sensing blocks can be used for a number of different things. They can
be used to keep track of how long things take within your program.
They can be used to ask questions and then store the answers to be
used within other blocks, and they can also be used to detect whether
a key has been pressed on your keyboard or if there’s been movement
of your mouse.
RETRIVEING MOUSE BUTTON AND COORDINATE STATUS

Scratch determines where to display sprites through a coordinate


system, or a mathematical grid of infinite values. It uses the Cartesian
coordinate system in which on a two-dimensional plane, a point has
two values to locate or reference its exact position.
Scratch's coordinate system uses 2 coordinates, "X position" and "Y
position", to determine the location of a sprite on the stage. The "X
position" value determines the horizontal location of the sprite and the
"Y position" value determines the vertical location or height.
KEY, SPRITES COLLIDE
The Touching ()? block is a sensing block and a Boolean block. The block
checks if its sprite is touching the mouse-pointer, edge, or another
sprite (a reporter block which returns the sprite's name, usually
a variable can be used). If the sprite is touching the selected object, the
block returns true; if it is not, it returns false.
This block behaves differently when the sprite is hidden. Every check
for collisions with other sprites return false, however, it still senses the
mouse and the edges. Because this block checks if its sprite is touching
another sprite or an edge, it is widely used in detecting collisions.
DISTANCE
The Distance to () block is a sensing block and a reporter block. The
block reports the distance in pixels, between it and the mouse-
pointer or a specified sprite’s costume centre, even if the specified
sprite is hidden.
If there is nothing in the drop-down insert of the block, or if a sprite
that was deleted is still in the drop-down insert, it reports the distance
as 10,000.
This block is case-sensitive.
TIMER
To see this timer displayed on your screen, navigate to the Sensing
category in the block menu and check the box next to the timer
variable. Now, it should show up in the stage next to the other variables
in your project. Find the timer variable in the Sensing category, and
check the box to add it to your stage.
The Timer is a feature in Scratch that records how much time, in
seconds, have passed since the last time the green flag was clicked or
the timer was reset.
The timer is extremely accurate and the value itself is not affected by
lag.
RETRIEVING STAGE, SPRITE DATA AND AUDIO DATA

The stage is the background of the project, but can have scripts,


backdrops(costumes), and sounds, similar to a sprite. It is 480pixels
wide and 360 pixels tall.
All sprites have a particular position on the stage. However, no sprites
can move behind the stage, it is always at the back layer.
To recover deleted sprites, click Edit and choose “Restore”.
Sounds are in the Scratch sound library.
DAY 7: PROJECT
DAY 8: STORING AND RETRIEVING DATA
WORKING WITH APPLICATION DATA
CREATING SCRATCH VARIABLES
It is possible to create your own variable in Scratch, and give it
whatever name you choose.
Click on Variables in the Code tab, then click on Make a Variable. Type
in the name of your variable. You can choose whether you would like
your variable to be available to all sprites, or to only this sprite. Press
OK.
ASSIGNING VARIABLES TO SPRITES AND THE STAGE

A variable is a changeable value recorded in scratch's memory.


Variables can only hold one value at a time. These values can be either
numbers or strings (any text). Clicking on an isolated variable in the
scripts area displays a small bubble reporting the value of the variable.
Unlike many other programming languages, Scratch does not allow
variables to be created by a script as it runs. Instead, variables are
created with the "Make a Variable" button in the Block palette.
ASSIGNING NAMES TO YOUR VARIABLE
It is possible to name any variable you create. There are some rules to
naming variables:
• Name your variables based on the terms of the subject area, so that
the variable name clearly describes its purpose.
• Do not begin variable names with an underscore.
• Do not use variable names that consist of a single character. Short
variable names are only allowed for loop counters.
• Name variables that describe binary states ("true" or "false") after the
state that matches the "true" value.
UNDERSTANDING VARIABLE SCOPE
Scope works a little differently in Scratch than in other languages. A
variable that is "For this sprite only" can still be read by other sprites,
but only the sprite that owns it can write to it. Variables that exist "For
all sprites" act like global variables. This can help students when
deciding what scope of variables to use for different tasks.
DELETING VARIABLES
Go to the “Data” section of the block lists, right click on
the variable you want to remove, and select “Delete”
to remove that variable.
ACCESSING VARIABLE OF OTHER SPRITES
The () of () block is a sensing block and a reporter block. The block will
report a specified value of the specified sprite or the stage.
If the block is used on a sprite which has clones, the reported value will be
of the original sprite, and never of the clones. This makes it impossible to
access information about clones using this block.
If there is nothing in the second drop-down, or if a sprite that was deleted
or is non-existent is in the second drop-down, it reports the value as 0.
This block allows sprites and the Stage to have access to other sprites'
special values. With this, projects can have a lot of connectivity between
sprites.
WORKING WITH VARIABLE MONITOR
Monitors are often used for displaying variable data in a project or
troubleshooting. For instance, monitors may be used to display a score.
Monitors allow users to see the effect of commands such as "change x
by 1", helping them build a mental picture of how variables work
DAY 9: BASKETBALL QUIZ PROJECT
DAY 10: MATH
ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION

These operations can be done with the operators block.


COMPARISON OPERATORS
You can make decisions in Scratch, too. Using comparison operators,
you can compare the values of two variables or expressions to
determine whether one is greater than, less than, or equal to the other.
Comparison operators are also called relational operators because they
test the relationship between two values.
LOGICAL COMPARISON
In Scratch there are three logical operators, 'and', 'or', and 'not' , that
are the primary foundation for logical connectives in conditional
statements.
ROUNDING NUMBERS AND RETREVING REMAINDERS

The Round () block is an Operators block and a Reporter block. The block


rounds the given number to the nearest integer.
The () Mod () block ("mod" is short for “modulo") is an operators block and
a reporter block. It reports the remainder when the first input is divided by
the second. For example, when 10 is put in the first input and 3 in the
second, the block will report 1; 10 divided by 3 gives a remainder of 1.
() Mod () supposes the quotient (result of division) is always rounded
down, even if it is negative. For example, -10 mod 3 = 2, not -1, because
the quotient -10/3 is rounded down to -4, giving a positive remainder
BUILT-IN MATH FUNCTION
Mathematical functions and formulas can be expressed using the
Scratch operators block.
There are some built-in functions like:
sin, cos, tan, log, and more.
DAY 11: NUMBER GUESSING GAME QUIZ PROJECT
DAY 12: CONDITIONAL AND REPETITIVE LOGIC
SCRATCH CONTROL BLOCKS
Control blocks are color-coded gold and are used to control scripts. The
block pauses its script for the specified amount of seconds, the wait can
also be a decimal number. Blocks held inside this block will loop a given
amount of times, before allowing the script to continue.
EVENT PROGRAMMING
Events in Scratch are represented by yellow code and include: the green
flag, clicking on character, bump code and broadcast. Broadcasting in
Scratch helps with interactions between sprites like pacing their
conversations.
PAUSING SCRIPT EXECUTION
We could have a pause and play button and scripts. They are much like
the stop scripts but they pause the scripts instead of stopping them
forever.
EXECUTING LOOPS
Loops are commonly used in programming to repeat an action over and
over. There are three types of loops in Scratch: repeat, repeat until, and
forever loops.
If you want to repeat an action more than once, loops will help you do
it.
In some programs, we need to terminate the loop earlier without
running through all the iterations. Using the methods discussed here,
we can exit from the loop. Breakable loops help to make the code
simpler
SENDING AND RECIVING BROADCAST
A broadcast is a message that is sent through the program,
activating scripts with the matching hat blocks. Broadcasts are sent with
the blocks Broadcast() and Broadcast() and wait, and are received by
the hat block When I receive().
Broadcasts allow scripts to continue into other sprites, as some values are
different to different sprites. They can also be used to branch a single
sending script into many receiving scripts, or to close many sending scripts
into a single receiving script.
Broadcasts are useful in games and animations, as they trigger specific
scripts. They are similar to events, which are scripts triggered when certain
actions, like mouse moves or key presses, are performed.
NESTING CONDITIONAL CONTROL CODE BLOCKS
The IF THEN ELSE statement is used to control which parts of the code
run based on variable conditions – often times input from the
program’s user. (This is called a conditional logic or control flow.) The
programmer can put in several alternate pieces of code – which one
runs depends on the values currently in the program. For example, if a
number is greater than 50, then the program will say it is a big
number. Else, the program will say it is a little number.
PREVENTING ENDLESS LOOP
 “Repeat until” works like a forever loop except it will stop when you
meet the condition. 
This is a good way to prevent an endless loop.
TERMINATING SCRIPT EXECUTION
Control blocks is one of the nine categories of Scratch blocks. They are
color-coded gold, and are used to control scripts
We can run a script in Scratch by clicking on the green flag on top of our
script area, and we can stop it by clicking the red button.
DAY 13: DEVELOPING THE BALL CHASE GAME
DAY 14: CHANGING THE WAY SPRITES LOOK AND BEHAVE
A QUICK PROJECT
DAY 15: FINAL SCRATCH PROJECT

You might also like