14
Introduction to Scratch Computer Programming Modeling a Passive Solar Home

Computer Programming Modeling a Passive Solar Home

Embed Size (px)

Citation preview

Page 1: Computer Programming Modeling a Passive Solar Home

Introduction to Scratch

Computer ProgrammingModeling a Passive Solar Home

Page 2: Computer Programming Modeling a Passive Solar Home

Scratch is a visual computer language Uses graphical blocks to create a program

as opposed to typewritten commands. Output is primarily visual Made to be simple to use, but it contains all

the elements of a programming language

What is Scratch?

Page 3: Computer Programming Modeling a Passive Solar Home

The output is displayed on a stage, which can have several different backgrounds

Sprites are characters or objects that are moved about the stage and which also can change appearance

The inputs and results of calculations are also displayed on the stage

Scripts, or programs, are used to change the background and to move or change the appearance of sprites

Overview

Page 4: Computer Programming Modeling a Passive Solar Home

Characters or pictures in the animation that you can manipulate◦ Move, Glide, Shrink, Grow, Alter, appearance

The first Sprite that shows up is the Cat In the lower right hand part of the screen are

where the Sprites are loaded, created, or altered

Sprites do not have to be characters. They can also be objects that you want to change or move, such as a lamp that can be on or off or a ball moving across the screen

Sprites

Page 5: Computer Programming Modeling a Passive Solar Home

The white area in the upper right that has a background and on which the sprites move.

The stage can have multiple backgrounds which can be changed by the script

Selecting Stage, just to the left of the Sprites, brings up three tabs for the stage in the center of the window: Scripts, Backgrounds and Sounds◦ Under the Background tab, you can load in pictures

that will serve as the background behind your Sprites.◦ You can paint a background, import a background that

Scratch provides (in the Backgrounds folder), or import in your own background picture

Stage

Page 6: Computer Programming Modeling a Passive Solar Home

Scripts are the computer programs that govern the movement and appearance of each Sprite or Background

They are created by dragging commands from the left column into the center column

Commands are arranged in categories shown in the upper right of the window

Scripts

MotionLooksSoundPen

ControlSensingOperatorsVariables

Page 7: Computer Programming Modeling a Passive Solar Home

Variables hold numeric values◦ Create them under the “variables” commands◦ Can set or change a variable using “set” and

“change” commands Operators perform calculations

◦ Addition, subtraction, multiplication◦ Operands include existing variables and numbers◦ Operators give results that are used in “set”,

“change”, “move to”, and other commands

Calculations and Values

Page 8: Computer Programming Modeling a Passive Solar Home

Start – starts the script via flag, message, or clicking

Stop – stops the script or all of the scripts Loops let you repeat parts of a script Other control blocks allow a script to

change its behavior if certain conditions are met

Controlling the Program

Page 9: Computer Programming Modeling a Passive Solar Home

Follow the steps below to create a program to add two numbers together.

Steps◦ Open scratch and click on the “stage” in the lower right.◦ Select backgrounds in

the middle panel, then “edit”

◦ Use the line tool to draw a “+” and a line, as one might do for addition with a pencil and paper.

◦ Move the Cat sprite out of the way (we won’t use the sprite in this example)

A Simple Calculator

Page 10: Computer Programming Modeling a Passive Solar Home

Select “Variables” in the upper left Select “Make a Variable” and create three variables.

Suggested names are “number 1”, “number 2”, and “sum”. These appear on the stage.

Move them so theymake sense, withthe sum below theline and the numbersabove

Create Variables

Page 11: Computer Programming Modeling a Passive Solar Home

Click on the “Script” tab in the center panel Click on “Control” button on the upper left and drag the “When

stage clicked” into the center panel Click on the “variables” button and drag the “set” block to the

center panel, just under theexisting piece. A white line will appear that will tell you when the piece is fitting correctly.

Use the small arrow in the “set” block to change the variable from “number 1” to “sum”

Write the script

Page 12: Computer Programming Modeling a Passive Solar Home

Click on “Operators” in the upper left

Drag the top operator (with the plus) so that it falls into place on the “set” block where the 1 used to be

Go back to the “variable” area and drag the “number 1” and “number 2” variables into the “+” operator. The placeholders will be highlighted when the fit is correct.

Go back to the “control” area and drag the “stop script” block to theend of the script

Write the script (continued)

Page 13: Computer Programming Modeling a Passive Solar Home

On the stage, double-click on the “number 1” and “number 2” variables. Both will have a small slider beneath them.

Double-click twice on the “sum” variable. It will turn into a larger number.

Use the sliders to changevalues of“number 1” and “number 2”

Single-click anywhere onthe stage and the value of “sum” will change to be the sum of the other two variables.

Run the Script

Page 14: Computer Programming Modeling a Passive Solar Home

Use scratch to calculate the change in temperature in a house due to heat loss

Activity