1 / 14

Functions and Expressions

Functions and Expressions. What will we learn today?. We will learn today What are functions and expressions Functions in real life Built-in functions in Alice How to use functions and expressions. Functions and Expressions. Function

toniag
Télécharger la présentation

Functions and Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Functions and Expressions

  2. What will we learn today? • We will learn today • What are functions and expressions • Functions in real life • Built-in functions in Alice • How to use functions and expressions

  3. Functions and Expressions • Function • A statement you can use to ask a question about conditions/properties of an object or to compute a value • Expression • A math operation on numbers or other kinds of values

  4. Functions in Real-Life • We use functions to compute the hours in any given number of days (hours=days*24) • The vending machine; you insert a currency into the machine and it dispenses items such as snacks, chocolates, water..etc to you automatically

  5. Functions • We use functions to get the information we need • Q:How far away the camel is from the palm trees??

  6. Built-in Functions • Alice system provides a set of built-in functions for each object • To view a list of built-in functions associate with an object in a world • Select the object in the object tree • View the functions in the details area

  7. Built-in Functions • The Built-in functions are divided into subcategories • Proximity: how close the object is to other objects e.g. distance to • Size: dimensions e.g. height, width and depth • Spatial relation: orientation compared to other objects in the world e.g. to right of • Point of view: position in the world • Other: miscellaneous items

  8. Expressions • Alice Provides math operators for common math expressions • Add(+), subtract(-), multiply (*) and divide(/) • Obtaining math expression

  9. Camel and distance to tree example • We want the camel to move towards the palm tree and stops there • Select the camel from the object tree • Click on the methods tab • Drag the ‘move’ method and place it into the program code editor (the large yellow pane)

  10. Camel and distance to tree example • Choose forward and 1m from the list shown • Select the functions tab and drag the ‘distance to’ function under ‘proximity’ into the ‘1 meter’ box

  11. Camel and distance to tree example • Choose ‘plamTree’ from the list and the ‘entire plamTree’

  12. Camel and distance to tree example • Click on the arrow as shown below and choose math, camel distance to palmTree-1

  13. Camel and distance to tree Simulation

  14. Let’s work with Alice • We will take the “raceCar” simulation and make the car • Move to the palmTree • Turn to face the lampPost • Move forward half the distance to the lampPost

More Related