Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming.

Similar presentations


Presentation on theme: "Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming."— Presentation transcript:

1 Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming

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

3 Fall 2007ACS-1805 Ron McFadyen3 Simple instructions Simple instructions; examples: Commanding an object to carry out one of its actions Assigning a property a value

4 Fall 2007ACS-1805 Ron McFadyen4 Control structures Control structures: These affect the sequence of execution. Alice offers several types: Do together Do in order If/Else Loop While For all in order For all together

5 Fall 2007ACS-1805 Ron McFadyen5 Control structures The “mana” exercise used 2 of these:

6 Fall 2007ACS-1805 Ron McFadyen6 The Pieces Functions These are used to obtain certain calculations Each object has a set of pre-defined functions Proximity Size Spatial relation Point of view other

7 Fall 2007ACS-1805 Ron McFadyen7 The Pieces Expressions Certain information needed for a simulation may require us to calculate things using arithmetic E.g. the distance from the centre of the robot to the centre of the rock

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

9 Fall 2007ACS-1805 Ron McFadyen9 Example Instead of having the robot move towards the alien, we can have the robot move towards the rock that is in front of the alien A simple instruction can command the robot to move towards the rock:

10 Fall 2007ACS-1805 Ron McFadyen10 Example Consider the rock and the robot We can do better than moving 1 metre, we can move the robot an appropriate distance determined via a calculation how far apart are they? how far should the robot move? Consider:

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

12 Fall 2007ACS-1805 Ron McFadyen12 Example Suppose we want the robot to look toward the alien. But if the robot is shorter than the rock we could have the robot raise its head a bit If the robot is shorter than the rock we want the robot to raise its head, otherwise it doesn’t have to We can use an If/Else control structure:

13 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

14 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:


Download ppt "Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming."

Similar presentations


Ads by Google