Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.

Slides:



Advertisements
Similar presentations
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Advertisements

Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Built-in Functions & Arithmetic Expressions.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Checking for Collisions Ellen Yuan Under the direction of Professor Susan Rodger at Duke University June 2014.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Checking for Collisions: Alternative Method Erin Taylor Under the Direction of Susan Rodger July 2015 Duke University.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Writing Our Own Functions Alice. Functionality A function receives value(s), performs some computation on the value(s), and returns (sends back) a value.
What we will do today Learn about functions in Alice.
Functions Alice.
Mathematical Expressions, Conditional Statements, Control Structures
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Today’s Agenda 1.Collect Pre-Lab 3 2.Alice Programming Assignment 3.Built-in Functions 4.Expressions 5.Control Structure 6.Assign pair programming teams.
Programming: Simple Control Structures
Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Simple Collision Detection By David Yan Under the direction of Professor Susan Rodger and Chari Distler Duke University, June 2015.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Obj: Programming: Simple Control Structures HW: Read section 3 – 2 AC3 D2 Do Now: 1.Log on to Alice. Open the file firstEncounter.a2w located in the folder.
Programming: Simple Control Structures Sec 46 Web Design.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Creating a UFO Rescue Game in Alice
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Obj: to recognize built-in functions and expressions HW: Read Section 3.1 and do HW4 Edmodo article due Sunday at 8pm Edmodo feedback due 8pm 10/17 Do.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Functions Sec 51 Web Design.
Learn about functions in Alice
Programming: Simple Control Structures
Programming: Simple Control Structures
Simple Control Structures
Functions Sec 8-11 Web Design.
Repetition Control Structures
Creating a UFO Rescue Game in Alice
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Checking for Collisions: Using Functions in Alice
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
Functions Alice.
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Programming: Putting Together the Pieces Built-in Functions and Expressions Alice

Putting together the pieces A major part of learning how to program is figuring out how to "put together the pieces" that compose a program. analogy: putting together the pieces of a puzzle The purpose of this session is to define the fundamental pieces of a program demonstrate how to put the pieces together

Four Fundamental Pieces Instruction Control Structure Function Expression

Instruction An instruction is a statement that executes (is carried out by the computer at runtime). Usually this is one line of code. In Object Oriented Programming, an instruction is defined as a method or procedure. In Bruce the shark, we used instructions to make objects perform a certain action. Examples: shark turn to face camera shark move forward 0.5 meters

Control Structure A control structure is a statement that controls which instructions are executed and in what order. In previous worlds, we used: Do in order Do together Count

Functions A function asks a question (to check a condition) or computes a value. In Alice, a function is used to get the information we need about the properties of objects Is the alien’s face red? the relationship of one object to another What is the distance between the mummy and pyramid? a current condition What key (on the keyboard) was pressed? Let's look at an example…

Problem Example In the world, the camera angle influences our perception of the scene. How many meters does the alien need to walk to reach the rock?

Built-in Functions

Values When a function is used to ask a question or perform a computation, an answer is returned. The answer is called a value. The type of value depends on the kind of function. In our example, we want to ask the question: What is the distance of the alien to the rock? We expect to get a number value. It could be a whole number or a fractional value, such as 3 meters or 1.2 meters

Demo Concepts illustrated in this example program: The built-in distance to function determines the distance from the center of one object to the center of another object. A function is not a "stand-alone" instruction; it is nested within another instruction.

Problem: Collision When the program is run, the robot collides with a rock. The problem is the distance between two objects is measured center-to-center. One way to avoid a collision is to subtract a small number (1 or 2) from the distance.

Expressions An expression is a math or logic operation on numbers or other types of values Alice provides math operators for common math expressions: addition + subtraction  multiplication * division /

Demo Concept illustrated in this example: Math expressions are created within an instruction. Available math operators are +, -, *, /

Demo Subtracting 2 meters from the distance is an arbitrary amount. To be more precise, we could subtract the width of the rock. The resulting expression subtracts the value of one function from the value of another function.

Using an If then else Drag the if statement to the editor – choose “true”

Replace “true” with a boolean expression ie. the alien is collidingWithrock

Another kind of if Drag the if statement to the editor – choose “true”

Another kind of if Click on the drop down menu beside the word “true”

Now, You do it. Set up goldilocks and 3 beds

Improve the program 1.Goldilocks seems to go right into the bed. Can you use the “math function” to subtract 1 from the distance she travels so she doesn’t quite bump into the bed? 2.Can you make it so Goldilocks moves closer to the centre of the bed as she lies down on it? 3.Have her try the other beds as well.