Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.

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

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
1 Fall 2009ACS-1805 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique shown in text) Directed.
Repetition Structures
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2009ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
Xin November 22, Exercise start Skater turns towards skater2 Skater2 turns towards skater Skater moves to pose 2 Skater2 moves to pose 2 Bunny move.
Fall 2009ACS-1805 Ron McFadyen1 Functions A function is a collection of statement, similar to a method, but a function is defined to return a value to.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
Fall 2007ACS-1805 Ron McFadyen1 Functions and if-else A function is a collection of statement, similar to a method, but a function is defined to return.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
1 Fall 2008ACS-1805 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique) Text presents one of these.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 7 Repetition.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 8 Recursion.
Fall 2009ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
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.
Execution Control with If/Else and Boolean Functions
Execution Control with If/Else and Boolean Questions Part 1 Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
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.
1 Fall 2007ACS-1903 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique) Text presents one of these.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Mathematical Expressions, Conditional Statements, Control Structures
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
Fall 2009ACS-1805 Ron McFadyen1 Chapter 2 Program Design & Implementation.
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.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 2 Creating Your First Animation (An Introduction to Programming)
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Program Organization Sequential Execution: One line done after the other Conditional Execution: If a test is true, one section is done, otherwise another.
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.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Programming: Simple Control Structures Sec 46 Web Design.
Fall 2008ACS-1805 Ron McFadyen1 Event-driven programming Chapter 5 covers event-driven programming. Events are user or condition driven and so each event.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
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.
Programming: Simple Control Structures
Chapter 3: Decisions and Loops
Programming: Simple Control Structures
Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Design and Implementation
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.
Programming with Alice
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
Event-driven programming
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.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces

Fall 2007ACS-1805 Ron McFadyen2 The Pieces Chapter 3 introduces the fundamentals of programming. Construction of a program usually requires us to include: Simple instructions Control structures Functions Expressions

Fall 2007ACS-1805 Ron McFadyen3 The Pieces A simple instruction - Commanding an object to do a certain action E.g. getting the ice skater to turn left:

Fall 2007ACS-1805 Ron McFadyen4 The Pieces Control structure: Alice offers several types E.g. choosing between two alternatives - in the World.BarrelRoll method of the flight simulator:

Fall 2007ACS-1805 Ron McFadyen5 The Pieces Control structure: Alice offers several types E.g. repeating something – in the flight simulator World.BeginFlying contains the loop where collisions are tested for continuously:

Fall 2007ACS-1805 Ron McFadyen6 The Pieces Function In the flight simulator, once the plane is within a metre of a ring the plane is considered to have gone through the ring and the ring disappears. The code uses a built in function to determine this:

Fall 2007ACS-1805 Ron McFadyen7 The Pieces Expressions Certain information needed for a simulation may require us to calculate things using arithmetic The flight simulator keeps track of the number of rings acquired:

Fall 2007ACS-1805 Ron McFadyen8 Examples Consider the rock, alien and robot in the First Encounter. We shall demonstrate Simple instructions Functions Expressions Do together If/else Loop

Fall 2007ACS-1805 Ron McFadyen9 Example Consider the rock and the robot We want the robot to move towards the rock A simple instruction can command the robot to move towards the rock:

Fall 2007ACS-1805 Ron McFadyen10 Example Consider the rock and the robot We can use the distance function to find out how far apart the robot and the alien are. We can do more, consider the distance calculated using functions and an expression : The above is complex but when we know what we want Alice lets us build it fairly easily

Fall 2007ACS-1805 Ron McFadyen11 Example Consider the rock and the robot We need the robot to be walking Using the Do Together control structure we have the moving and walking occurring at the same time :

Fall 2007ACS-1805 Ron McFadyen12 Example Consider the rock and the robot If the robot is shorter than the rock we want the robot to raise its head, otherwise it doesn’t have to : The above uses an If/Else decision structure to determine if an action needs to be executed or not.

Fall 2007ACS-1805 Ron McFadyen13 Example Consider the rock and the robot Previously we had the robot walking to the rock, but the robot took 1 step with each of 2 legs regardless of the distance. Suppose we want the walking effect to appear with each metre travelled – we can use a Loop: See next slide for a more advanced “times” calculation

Fall 2007ACS-1805 Ron McFadyen14 Example Consider the rock and the robot An expression to calculate the number of times to move a single metre:

Fall 2007ACS-1805 Ron McFadyen15 Functions Functions are designed to return certain kinds of values Number (e.g. number of metres to move) Boolean (produces a value of true or false)

Fall 2007ACS-1805 Ron McFadyen16 Expressions Expressions are designed to return certain kinds of values Arithmetic expressions return numeric values Expressions involving, >=, ==, != return boolean values The values returned by the height function for the robot and the rock are compared to determine if the robot is shorter than the rock

Fall 2007ACS-1805 Ron McFadyen17 Tips/Techniques Some properties of objects and world: Texture maps: we can change the appearance of an object by altering its texture. This is done by importing a “gif” and using it as the texture for an object. The text modifies a place to give the appearance of a cookie. Fog: we can incorporate fog in a world and adjust its density for a special effect.