Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.

Similar presentations


Presentation on theme: "Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing."— Presentation transcript:

1 Lists Alice

2 Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing the same marching steps. In such situations, it is convenient to collect all the objects into a group (a collection)

3 List One way to organize objects into a collection is to use a list. In our daily lives, we use lists to help us organize things. For example, assignments list shopping list In programming, a list is known as a data structure.

4 Types of Lists In Alice, a list can be a list of numbers or a list of objects, colors, or other type …. In this session, we will use an example of a list of objects.

5 Example The famous Rockettes ® are preparing for their winter holiday show. You have been hired to create an animation for the holiday show that will be used on a web site where people can purchase tickets for the show.

6 Creating a list: Step 1 Create the initial world and add five rockette objects to the world. Then, create a new world- level variable in the properties panel. (Why should it be world-level rather than class-level?)

7 Creating a list: Step 2 In the popup dialog box, type in a name select Object type check “make a List” box click new item button 5 times to select each of the 5 rockettes, one at a time

8 Programming with a list Now that a list has been created, how do we use the list in a program? One of the most useful operations with a list is to repeatedly perform some action with each item in the list. We call this iteration or "iterating through a list."

9 Iterating through a list Iteration can be done in two ways: in order (one at a time) all together (simultaneously)

10 Example: Iteration in Order A typical chorus line dance involves each dancer (one after the other) kicking up one leg. Possible storyboard: For all dancers in order item_from_dancers kickUpRightLeg kickUpRightLeg Parameter: whichRockette Do in order Do together whichRockette right thigh turn back whichRockette right calf turn forward whichRockette right calf turn back

11 Steps to create the first turn instruction in kickUpRightLeg 1.Create an instruction to turn one of the rockettes backward.25 revolutions 2.Then, drag in the part named function for the rockette and drop it on top of the rockette tile. 3.Click to the right of part name and enter the exact name of the part- Alice is case sensitive: type it correctly! hips.rightThigh 4.Now drag the whichRockette parameter tile down to drop it on top of the rockette.

12 For All in Order The For all in order statement executes the action for all list items in order.. For All in Order tile is dragged into the editor The expression World.dancers is selected as the name of the list Inside the the For All in Order, call the World.kickUpRightLeg with which Rockette = item_from_dancers


Download ppt "Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing."

Similar presentations


Ads by Google