Shorter of two objects and changing color

Click here to load reader

  • date post

    22-Feb-2016
  • Category

    Documents

  • view

    22
  • download

    0

Embed Size (px)

description

Shorter of two objects and changing color. Functions, events and setting the color in sequence and randomly. Susan Rodger, Duke University July 2009. What this tutorial shows. You’ve used built-in functions. Now you will write your own functions. - PowerPoint PPT Presentation

Transcript of Shorter of two objects and changing color

Shorter one and changing color dynamically

Shorter of two objects and changing colorFunctions, events and setting the color in sequence and randomlySusan Rodger, Duke UniversityJuly 2009

What this tutorial showsYouve used built-in functions. Now you will write your own functions.

NOTES: Not all objects can change color. The chicken and snowman can change color, which is why we use them. The bunny cannot change color, the object was just designed that way.PartsPart 1: Create a world function that returns the shorter of two objects make it a world function because it uses two different objectsPart 2: Create a chicken function that returns a color (cycling through 4 colors) and use the function to change the color of the chickenPart 3: Create a snowman function to returns a random color and use the function to change the color of the snowman randomlyPart 4: Create a snowman function to return the color as a word and use the function to have the snowman say what color it is.Part 1: Start Alice world with sand and add in chicken, snowman, bunny, and joey

Create World function ObjectThatIsShorter select Type as Object

The new function appears notice the Obj means this function returns an object

What this function will doA function computes an answer and returns the answer. The function ObjectThatIsShorter will compare the chicken and the snowman in height and the answer is the one that is shorter. The function returns the shorter object. Since the function type is object the function must return an objectDrag up if/else

Compare chicken and snowmans heights from world functions, drag over the a 0 and colorNumberb, then fill in with colorNumber > 0

Click on the last white down arrow, select logic, and, and true

Drag in the a 0 and colorNumber