Mathematical Expressions in Alice

Similar documents
2 Programming in Alice: Program Design and Implementation

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

First Bytes Programming Lab 2

Imaging Systems Laboratory II. Laboratory 4: Basic Lens Design in OSLO April 2 & 4, 2002

Get The Picture: Visualizing Financial Data part 1

Named Memory Slots. Properties. CHAPTER 16 Programming Your App s Memory

CALCULATING THE AREA OF A FLOWER BED AND CALCULATING NUMBER OF PLANTS NEEDED

MECHANICAL PRINCIPLES HNC/D MOMENTS OF AREA. Define and calculate 1st. moments of areas. Define and calculate 2nd moments of areas.

3D-GIS in the Cloud USER MANUAL. August, 2014

Calculating Area, Perimeter and Volume

EFX Keying/Alpha plugins for After Effects

Introduction to Measurement Tools

Create a Poster Using Publisher

Section 7.2 Area. The Area of Rectangles and Triangles

Mathematics (Project Maths Phase 1)

Wilson Area School District Planned Course Guide

Show that when a circle is inscribed inside a square the diameter of the circle is the same length as the side of the square.

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

Objective. Materials. TI-73 Calculator

CNC Turning Training CNC MILLING / ROUTING TRAINING GUIDE. Page 1

Microsoft FrontPage 2003

Tutorial Creating Vector Graphics

Sage Timesheet Web Access How To Use Timesheet

PLOTTING DATA AND INTERPRETING GRAPHS

Chapter 1 Learning to Program With Alice

Printer Setup. What Is the Printer Setup Module?... B-2. How to Access the Printer Setup Module... B-3. Reference Information. Standard Procedures

NVCC Alexandria Campus

SMART NOTEBOOK 10. Instructional Technology Enhancing ACHievement

POLYNOMIAL FUNCTIONS

What You ll Build. CHAPTER 3 MoleMash

Timeless Time and Expense Version 3.0. Copyright MAG Softwrx, Inc.

The Circumference Function

Surface Area Quick Review: CH 5

MATH 110 Landscape Horticulture Worksheet #4

Graphical Integration Exercises Part Four: Reverse Graphical Integration

Using Image J to Measure the Brightness of Stars (Written by Do H. Kim)

Chapter 11 Number Theory

Content Author's Reference and Cookbook

Microsoft Word 2010: How to Resize and Move Clip Art

Lesson 26: Reflection & Mirror Diagrams

Creating Maze Games. Game Maker Tutorial. The Game Idea. A Simple Start. Written by Mark Overmars

CLOCKWORK Training Manual and Reference: Inventory. TechnoPro Computer Solutions, Inc.

MATHEMATICS FOR ENGINEERING BASIC ALGEBRA

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Tutorial Microsoft Office Excel 2003

Geometry Solve real life and mathematical problems involving angle measure, area, surface area and volume.

Lego Robot Tutorials Touch Sensors

Excel -- Creating Charts

An introduction to 3D draughting & solid modelling using AutoCAD

Lesson 21. Circles. Objectives

Welcome to the topic on Master Data and Documents.

CHAPTER 14 Understanding an App s Architecture

N Q.3 Choose a level of accuracy appropriate to limitations on measurement when reporting quantities.

CREATING SCENERY WITH THE PHOENIX RC CREATOR PROGRAM

I ntroduction. Accessing Microsoft PowerPoint. Anatomy of a PowerPoint Window

Graphic Design. Background: The part of an artwork that appears to be farthest from the viewer, or in the distance of the scene.

How Cubing is Differentiated Not all students receive the same cube. You can differentiate the tasks n cubes according to readiness, interest or

We are going to investigate what happens when we draw the three angle bisectors of a triangle using Geometer s Sketchpad.

Kristen Kachurek. Circumference, Perimeter, and Area Grades Day lesson plan. Technology and Manipulatives used:

Color quality guide. Quality menu. Color quality guide. Page 1 of 6

Teacher Answer Key: Measured Turns Introduction to Mobile Robotics > Measured Turns Investigation

Microsoft Office PowerPoint Creating a new presentation from a design template. Creating a new presentation from a design template

Investigation 6: What happens when plates collide?

Total Indicated Runout, Version 2

As we study each type of perspective, we will look both art work and photographs that exhibit each type of perspective.

Clip Art in Office 2000

SAT Math Strategies Quiz

1. Kyle stacks 30 sheets of paper as shown to the right. Each sheet weighs about 5 g. How can you find the weight of the whole stack?

MAKE AN A-MAZE-ING GAME

Solidworks Lesson 6 - Assembly & Part Drawings. UCF Engineering

Using Excel to find Perimeter, Area & Volume

Radius, Diameter, Circumference, π, Geometer s Sketchpad, and You! T. Scott Edge

Perimeter, Area, and Volume

Teachers should read through the following activity ideas and make their own risk assessment for them before proceeding with them in the classroom.

Auto Clicker Tutorial

ShoutCast v2 - Broadcasting with Winamp & ShoutCast DSP Plugin

AwanaGames Circle. Official. Diagram 1. Key to diagram: Pin & Striped Bean Bag C Diagonal or Starting Line. B Scoring Pins, or Center.

Create A Collage Of Warped Photos

CHAPTER 18 Programming Your App to Make Decisions: Conditional Blocks

Grade 7/8 Math Circles November 3/4, M.C. Escher and Tessellations

m ac romed ia Fl a s h Curriculum Guide

Creating Posters in Excel (2007 & 2010)

Designing Games with Game Maker

Section 1: Ribbon Customization

SellerDeck 2013 Reviewer's Guide

ACE: After Effects CC

To Begin Customize Office

Advanced Excel 10/20/2011 1

The Lighting Effects Filter

Introduction to the TI-Nspire CX

1.0-Scratch Interface 1.1. Valuable Information

Published : License : None. INTRODUCTION 1. Learning with Turtle Art

Search help. More on Office.com: images templates

Carrie Schoenborn Molly Switalski. Big Idea: Journeys

If you know exactly how you want your business forms to look and don t mind

Advanced Programming with LEGO NXT MindStorms

FREE FALL. Introduction. Reference Young and Freedman, University Physics, 12 th Edition: Chapter 2, section 2.5

Circumference and Area of a Circle

GRAPH MATCHING EQUIPMENT/MATERIALS

Transcription:

Some of the information about an Alice world, and its objects, is stored in properties. In general, only the properties used in setting up the world (e.g., color or opacity) are listed. There are many other properties (such as height, width, and position) that are very useful, particularly as our program executes. In order to make use of these other properties, Alice provides functions, which are programming statements that can be used to ask questions about various properties of objects (e.g., height and width), as well as relationships between objects (e.g., distance between objects). When the built-in functions do not provide the answers you need, it is also possible to form mathematical expressions that allow the programmer to refine their answer. These mathematical expressions can be used with functions or user input to provide necessary details for the animation of your program. Mathematical Expressions You are probably familiar with mathematical expressions from math class, where you use algorithms to perform calculations. Examples are calculations of the slope of a line, or the area of a circle. The most common mathematical operations are addition, subtraction, multiplication, and division. Most (perhaps all) programming languages, including Alice, provide a variety of mathematical operators, including the basic operators shown in the following table. Operator Description + Addition - Subtraction * Multiplication / Division For example, consider a simple calculation that relates the diameter of a circle to the radius. You may recall that the mathematical relationship is radius = diameter / 2. Page 1 of 5

To perform this simple operation in Alice, we will need: 1. Variables to store the values for diameter and radius. 2. User input to provide the diameter of the circle. 3. A mathematical expression to calculate the radius from the given diameter. As you can see, we have created our variables (diameter, radius), and initialized them to both have values of zero. Although Alice, by default, initializes numeric values to one, it is a better programming practise to initialize numeric values to zero. Since a diameter of zero isn't very interesting, the user is asked to enter a value (number) for the diameter. We have also set the radius equal to the diameter, but this isn't the correct calculation. This was simply the starting point. In the set value to operation, click on the diameter to see additional options. There is a Math option, which shows mathematical operations that can be performed on diameter. We want to divide diameter by something, so choose the diameter /, and set the value to 2 (i.e., divide diameter by 2). Unfortunately, this program doesn't actually do anything useful, but we have looked at the way to use mathematical expressions in our program. Page 2 of 5

Exercise 1 Using Math to Avoid Collisions Mathematical Expressions in Alice In graphics programming, a collision is when two graphical objects come into contact with each other. Quite often, the objects will continue and pass through each other, or end up occupying the same space. Here you will create an Alice world where one object moves to another object but does not collide with it. Consider the following problem: A snowman and a snowwoman are standing, facing in the same direction. The snowman turns to face the snowwoman, and then the snowwoman turns to face the snowman. The snowman moves to the snowwoman and stops just in front of her. He engages her in a conversation A simple design, using pseudocode, might look like: snowman turns to face snowwoman snowwoman turns to face snowman snowman moves forward to the front of the snowwoman snowman says something snowwoman says something The majority of this program contains concepts you are already familiar with. The real issue is the move instruction, shown in blue. As a first attempt, our Alice instruction would probably look like the one shown below. Unfortunately, this movement will result in a collision, where the snowman and snowwoman are completely overlapping each other. Since there doesn't seem to be a better primitive function to use, we will need to create a mathematical expression to refine our result. The problem is that the distance to function calculates and returns the distance between the centres of the objects. We need to calculate the distance between the front of the snowman and the front of the snowwoman. Page 3 of 5

distance between centres snowman depth snowwoman depth From our simple diagram, the unwanted distance is related to the depth (front-to-back distance) for the snowman and snowwoman. If we can account for this, the movement should occur without a collision. To make things a bit easier (for now), we will notice that the depth of each figure is approximately the same, so instead of using half of each, we will simply use the full depth of one of them. The snowwoman seems to be slightly larger, so we'll use that one just to be on the safe side. Our new code will subtract the depth of the snowwoman from the distance between them. Now that our distance is getting complicated, it's probably a good idea to use a variable to store the distance between the snowpeople. 1. Create a new Alice world using the snow template. Add an instance of the Snowman class and the SnowWoman class (both from the People collection). 2. Create a variable named distance that is of type Number. Set the initial value to zero. 3. Create the instructions as shown. Since the distance variable is initialized to zero, the snowman won't move when you run the program. 4. Now we will add the distance calculation using a mathematical expression. Drag the distance variable between the second and third lines in the code. a) Start by setting the distance to the distance between their centres. Page 4 of 5

b) Perform the subtraction operation by using the menu on the set value to instruction. You will need to use a default value for now (zero is suggested). click here c) Replace the default value from step (b) with the depth of the snowwoman, which is another function from the snowwoman object. 5. Play the world. The snowman should move close to the snowwoman, but they should not be touching. Try moving the snowman and snowwoman to random locations and ensure the program still works. Save your program as snowmandistance.a2w Page 5 of 5