Introduction to Scratch Programming v1.4 (Second Ed) Lesson 6 Calculator

Similar documents
Lesson 3 Creating and Using Graphics

Lesson 10 Using and Sorting Lists

You can delete the default blank background by clicking on its Delete button.

Lost in Space. Introduction. Step 1: Animating a spaceship. Activity Checklist. You are going to learn how to program your own animation!

Lost in Space. Introduction. Scratch. You are going to learn how to program your own animation! Activity Checklist.

Scratch Lesson 2: Movies Made From Scratch Lesson Framework

SCRATCH MODULE 3: NUMBER CONVERSIONS

Mailman Max. The postcode is a great way to work out the next sorting office a letter should go to, so you ll use that.

Add in a new balloon sprite, and a suitable stage backdrop.

Teaching Kids to Program. Lesson Plan: Catch the Ball

Make a game in which you play the notes of a song as they scroll down the stage.

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

ONE HOUR ANIMATION. Will you be a Scratcher upon completion of this session? Definitely. Learn how to write a basic script to animate a sprite.

Lineup. Introduction. What you will need. Import your costumes. What you will make. What you will learn. Hardware. Software

With the Photo-face project learners can incorporate digital media digital photos, and then transform these images in creative and surprising ways.

CPS111 Victory Thru Scratch Lab

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

What is a Fraction? Fractions. One Way To Remember Numerator = North / 16. Example. What Fraction is Shaded? 9/16/16. Fraction = Part of a Whole

S3 Scratch Programming

To build shapes from scratch, use the tools are the far right of the top tool bar. These

The Environment. Scratch Programming. The Environment. The Environment. The Environment. The Environment. Lesson 1: Introduction THE STAGE

IT82: Multimedia Macromedia Director Practical 1

Final Revision. 1)Put ( ) or ( ):

INVIGILATED BY MARKED BY MARKS TALLIED BY

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

M i c r o s o f t E x c e l A d v a n c e d. Microsoft Excel 2010 Advanced

EXCEL PRACTICE 5: SIMPLE FORMULAS

Spreadsheet Concepts Using Microsoft Excel

M O T I O N A N D D R A W I N G

Excel. Spreadsheet functions

ICS 61 Game Systems and Design Introduction to Scratch

Lesson 13: Exploring Factored Form

Software Reference Sheet: Inserting and Organizing Data in a Spreadsheet

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

VISUAL PROGRAMMING BY SCRATCH

Making a maze with Scratch

Crossley Fields - Computing Vocabulary

Lesson 18: Creating a Hierarchical Block

Grade 8 FSA Mathematics Practice Test Guide

Computer Science Concepts in Scratch

Measuring in Pixels with Scratch

The City School PAF Chapter Comprehensive Worksheet May 2016 ICT Class 6

Version History: 1.0: ab initio. Planning Notes:

Computer Science Concepts in Scratch

Decimal Operations Using Base-10 Blocks

Section 26: Associativity and Order of Operations

Year 5 PROMPT sheet. Negative numbers 4 7 = -3. l l l l l l l l l Place value in numbers to 1million = 4

Agenda. First Example 24/09/2009 INTRODUCTION TO VBA PROGRAMMING. First Example. The world s simplest calculator...

Introduction to Scratch

Key Stage 2 Scratch, Python and Kodu (Beginners)

In this section I m going to explain how to construct a formula, and give you some guidelines to ensure that your formulas work correctly.

SAMPLE. 1 ICT Spreadsheet Essentials. Lesson 1: Introduction to Spreadsheets

( 3) ( 4 ) 1. Exponents and Radicals ( ) ( xy) 1. MATH 102 College Algebra. still holds when m = n, we are led to the result

GRADE 7 MATH LEARNING GUIDE

Scratch. Creative Computing

Ch- 3,NOTEPAD. Q2. Define the following. Notepad: Notepad is a basic text editor used for creating and editing text documents.

Summer 2012 Animation

Teacher Cheat Sheet - Game Coding Challenges

EXCEL BASICS: MICROSOFT OFFICE 2007

Basic Math in Microsoft Excel

The Beauty and Joy of Computing 1 Lab Exercise 1: Introduction to Scratch/BYOB - Animations and Communication

Day 28 Arithmetic Sequence. Find the next two terms of each sequence. Then describe the pattern. The equations will be completed later.

SCRATCH. Introduction to creative computing with Scratch 2.0

Introduction to Spreadsheet

Lesson 9: Decimal Expansions of Fractions, Part 1

A PRACTICAL TUTORIAL TO EXCEL

Digital Technologies in focus:

FSA Algebra 1 EOC Practice Test Guide

Use the Associative Property of Multiplication to find the product.

All Blocks of Scratch

Printing Tips Revised: 1/5/18

Meet the Cast. The Cosmic Defenders: Gobo, Fabu, and Pele The Cosmic Defenders are transdimensional

DAY 28 - ARITHMETIC SEQUENCES

Section 5. Pictures. By the end of this Section you should be able to:

Cartoon Animation Tutorial

Table of Contents. 1. Creating a Microsoft Excel Workbook...1 EVALUATION COPY

BEETLE GEOMETRY MODULE 2: INVESTIGATION 1. Exploring Pen

Collaborative Authoring Tool

Drawing. Chapter 12. Beam. A. Insert Views. Step 1. Click File Menu > New, click Drawing and OK. Step 2. Click Model View. on the View Layout toolbar.

FSA Geometry EOC Practice Test Guide

1. Math symbols Operation Symbol Example Order

Excel 2013 Part 2. 2) Creating Different Charts

Grade 6 Math Circles February 19th/20th

Objective: Find areas by decomposing into rectangles or completing composite figures to form rectangles.

FSA Algebra 1 EOC Practice Test Guide

Algebra 1. Standard 11 Operations of Expressions. Categories Combining Expressions Multiply Expressions Multiple Operations Function Knowledge

PART ONE: Learn About Area of a Parallelogram

Making Your First Character

The Size of the Cantor Set

In this lesson you will learn: How to capture the input from the user. How to write programs using variables and lists. Athletics Swimming Gymnastics

Workbook Also called a spreadsheet, the Workbook is a unique file created by Excel. Title bar

1.- DECIMAL PLACE VALUE: tenths, hundredths, thousandths. 1.1 Ordering decimals. 1.2 Rounding CALCULATIONS. 2.- ADDITION AND SUBTRACTION OF DECIMALS

Maths Levels Criteria

Designing & Creating your GIS Poster

EXCEL BASICS: MICROSOFT OFFICE 2010

The City School. Prep Section. ICTech. 2 nd Term. PAF Chapter. Class 8. Worksheets for Intervention Classes

EXCEL + POWERPOINT. Analyzing, Visualizing, and Presenting Data-Rich Insights to Any Audience KNACK TRAINING

4 + 4 = = 1 5 x 2 = 10

The City School. Prep Section. ICTech. 2 nd Term. PAF Chapter. Class 7. Worksheets for Intervention Classes

Transcription:

Lesson What you will learn: how to perform simple calculations using Scratch how to use variables how to develop a design how to use the else if function how to create animated buttons Contents Exercise 1 Simple Calculator... 2 Exercise 2 More Advanced Calculator Design... 4 Introduction to Scratch Programming (2 nd Edition) Page 1 of 13 ZigZag Education, 2013

Exercise 1 Simple Calculator It is easy to create a simple calculator in Scratch. 1. Start a new Scratch project. Delete the cat and create the variables as shown (one for first number, second number, operator and answer). Operator this will be the addition, subtraction, multiplication or division need in the sum. 2. Set the variable display on the stage as shown. Introduction to Scratch Programming (2 nd Edition) Page 2 of 13 ZigZag Education, 2013

3. Input the instructions as shown below. This section resets all the number variables in the calculator to zero when the green flag is clicked. This section prompts the user to enter the first and second numbers and the operator needed for the sum. This section ensures that the correct answer is calculated according to what operator has been chosen. You have made a simple calculator. Introduction to Scratch Programming (2 nd Edition) Page 3 of 13 ZigZag Education, 2013

Exercise 2 More Advanced Calculator Design Now that you have made a calculator that works, you will move on to make a traditional layout calculator with buttons that can be pressed on the screen instead of being entered by typing. It is important when starting a new project to have an idea of what you re trying to achieve at the end of it. Think about the diagram below. First number to be entered This will be a variable (something that can change). Operator Add, subtract, multiply, divide (or blank). Second number to be entered This will also be a variable. Answer (variable worked out by a formula). Numbers Each button will be a sprite. Clicking the sprite will cause a number to be entered. Cancel button When this sprite is clicked, it will reset all the variables to default values (usually zero). Operators Each operator button will be a sprite. Clicking the sprite will set the operator and set the number pad to enter the second number. Equals button Clicking this sprite will cause the first number to be in a sum with the second number according to the operator that has been selected. There will be three elements of this work that you will need to create: a) the variables that will hold the data b) the buttons that will be sprites drawn by you c) the scripts that perform the functions of the calculator Introduction to Scratch Programming (2 nd Edition) Page 4 of 13 ZigZag Education, 2013

Create sprites for the buttons that you will need. Use the paint new sprite option. Use the rectangle and text tools to create each sprite. Set the costume centre to the centre of each sprite as shown. Name each sprite with a sensible name (not sprite1, sprite2, etc.). Create all the sprites as shown, each with a sensible name. (There is an equals button and an equals symbol which will not be a button.) Introduction to Scratch Programming (2 nd Edition) Page 5 of 13 ZigZag Education, 2013

The Operator Sprite The operator sprite, which displays at the top of the calculator, needs to have five costumes, one for each operator plus a blank one. Which operator is shown (which costume is shown) will depend on the value of a variable that is set when the different operator button is clicked. Create the costumes as shown: For each new costume, click Paint then create the costumes in the same way as you have for the individual sprites. Creating the Variables that You Will Need for the Project Variables hold values that can change. You need to create five variables as shown in the diagram. 1. Set first number, second number and answer to show (by clicking the check box). Set operator and sequence to not be shown. 2. The operator will contain five values which are zero to five (corresponding to addition, subtraction, multiplication, division and not chosen). 3. The sequence will contain two values: 1 and 2, according to whether the first number or the second number is to be entered. Introduction to Scratch Programming (2 nd Edition) Page 6 of 13 ZigZag Education, 2013

Drawing the Background of the Calculator Click on the stage icon. Then click the Backgrounds tab. Then click Edit. In Paint Editor, draw the background grid for the calculator. Click OK. Introduction to Scratch Programming (2 nd Edition) Page 7 of 13 ZigZag Education, 2013

Programming the Scripts Click on the stage icon and then create this start-up script which will reset all the variables. Setting sequence to 1 means that the first number clicked will be entered in the first number variable. Setting operator to zero will set the operator symbol to not chosen. The Cancel Button Script Use the same script as is on the stage as for the C button (Cancel). Choose the when cancel clicked starter button. The Operator Button Scripts Clicking the green flag or C button will set the operator variable to zero. Clicking each operator button will set the operator variable to a value between 1 and 4. Set the values by clicking the add button to 1, subtract to 2, multiply to 3 and divide to 4. Clicking any operator will also set the sequence variable to value 2. This means that the next click of any number button will send the number to the second number variable not the first number. Introduction to Scratch Programming (2 nd Edition) Page 8 of 13 ZigZag Education, 2013

Setting the Scripts on all the Number Buttons All the number buttons will have similar scripts. This script uses the IF ELSE function which is common in programming. Clicking the number sends the number to the first number variable UNLESS sequence has been set to 2 (by clicking an operator button), in which case it sends the number to the second number variable. Set the corresponding values for each of the buttons in the calculator, i.e. for button 1 enter a 1, for button 2 enter a 2, and so on. Setting the Script on the Equals Button Remember that the operator variable can be set to values from 0 to 4. The values 1, 2, 3 and 4 correspond as follows: 1 to add (+) 2 to subtract (-) 3 to multiply (*) 4 to divide (/) Introduction to Scratch Programming (2 nd Edition) Page 9 of 13 ZigZag Education, 2013

Setting the Script on the Operator Symbol Make sure that the operator symbol and the equals symbol are correctly located. You have made a calculator. Introduction to Scratch Programming (2 nd Edition) Page 10 of 13 ZigZag Education, 2013

Extension Activity 1 Entering Double Digit Numbers As it stands, the calculator can work with single digit numbers. This is a very limiting factor in the design of the calculator. The problem is that, if you type, say, a 7 into the keypad then you want to type another number, say, an 8, then the 7, which previously represented 7 units, now represents 7 tens. Changing the Script on the Zero Button 1. Adding a zero to any number is straightforward: 6 with an additional zero is 60, which is just 6 10. Change the script on the zero button as shown. First section: Sequence equals one and first number is greater than one this changes the first number to first number times 10. Otherwise the number pressed is the number added. Second section: Sequence equals two and second number is greater than one this changes the second number to second number times ten. Otherwise the number pressed is the number added. Using this script enables you to change 2 to 20 to 200 to 2000. There is no limit and the calculator will continue to work. Introduction to Scratch Programming (2 nd Edition) Page 11 of 13 ZigZag Education, 2013

Changing the Script on the Other Number Values Making the other buttons able to enter double digit numbers is slightly more complicated than with the zero. Look at the script below. This solution allows double digit numbers to be entered. It s up to you to design a solution for even bigger numbers. Sequence is set to 1 to make the number enter into the first number variable. If first number is greater than 0 and less than 10, then clicking the number sprite converts that number from units to tens and adds the new number. If first number is equal to zero, clicking the number sprite just enters that number. Now change the scripts on all the numbers to allow double digit entry. If the value stored in sequence isn t 1, then it will be 2 and the second part of the script will apply entering the number in the variable called second number (this is basically the same as the first section, but the data is entered into the second number variable, not the first). Introduction to Scratch Programming (2 nd Edition) Page 12 of 13 ZigZag Education, 2013

Extension Activity 2 Animating the Buttons It is easy to create an animation effect to animate the buttons. Working on the costume tab, click the copy button next to costume1 to create a new costume. 1. Click the Edit button next to costume2 and, in Paint Editor, slightly enlarge the button image (there is a button for this in the Paint Editor). 2. Switch back to the scripts tab and edit the script of that button as shown. 3. Repeat this process with all the buttons. Introduction to Scratch Programming (2 nd Edition) Page 13 of 13 ZigZag Education, 2013