Tutorial for Arrays and Lists By Ruthie Tucker. Description This presentation will cover the basics of using Arrays and Lists in an Alice world This presentation.

Slides:



Advertisements
Similar presentations
Visual Lists By Chris Brown under Prof. Susan Rodger Duke University July 2012.
Advertisements

Space Man Sam: Grammar Mistakes By Aleis Murphy Duke University, Under the direction of Professor Susan Rodger July 2010.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Alice Learning to program: Part Four Creating Sounds, Making Billboards, Fun with 3-D Text, New Events, and Rotating Objects by Ruthie Tucker and Jenna.
Lesson 5+: Using He- Builder/She-Builder And Adding Text! Slides are adapted from aliceprogramming.net or
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 2: Using Methods.
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 3: Billboards, Events, Sounds,
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Coloring Randomly: Random Selection in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
How Tall Are You? Introducing Functions By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made June 2014 by.
Vehicle Property and Inheritance By Ruthie Tucker, under the direction of Professor Susan Rodger, Duke University, 2008.
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Alice Learning to program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Google Earth How to create a Google Earth Tour and place it in your Wiki.
Adobe Forms THE FORM ELEMENT PANEL. Creating a form using the Adobe FormsCentral is a quick and easy way to distribute a variety of forms including surveys.
Making a Book Report in Alice by Jenna Hayes Under the direction of Professor Susan Rodger Duke University, June 2010.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Alice Learning to program: Part Three Camera Control, Invisibility, and 3-D Text By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger.
Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Methods Tutorial: Part Two By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Animating Objects in Groups: Using Arrays and Lists By Ruthie Tucker under the direction of Professor Susan Rodger Summer 2008.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Creating a Historical Tour in Alice By Jenna Hayes May 2010.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Learning to Program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Skater World: Part Three By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009.
An Introduction to Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University, June 2009 Updated June 2014 by Ellen Yuan.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Illuminating Computer Science CCIT 4-6Sep
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
VB.NET and Databases. ADO.NET VB.Net allows you many ways to connect to a database. The technology used to interact with a database or data source is.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Alice Learning to program: Part Three Camera Control, Invisibility, and 3-D Text By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger.
An Introduction to Alice (Short Version)
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Changing Color, Using Text Objects, and Random Selection in Alice
Alice Learning to program: Part Three By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger Duke University, 2008.
Methods Tutorial: Part Two
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
An Introduction to Alice
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
Getting Started With Alice
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Tutorial for Arrays and Lists
Professor Susan Rodger
Using Placeholders to Simplify your Methods: Learning Methods, Part 2
Professor Susan Rodger
Presentation transcript:

Tutorial for Arrays and Lists By Ruthie Tucker

Description This presentation will cover the basics of using Arrays and Lists in an Alice world This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens on a farm It uses a set of chickens on a farm Prerequisites Prerequisites Everything Everything This is the last tutorial you should do in this course This is the last tutorial you should do in this course

The Characters

Side Note Glitch in Alice Glitch in Alice Alice cannot compute your world if you put the same objects in a “List Visualization” as an “Array Visualization”. Alice cannot compute your world if you put the same objects in a “List Visualization” as an “Array Visualization”. I will demonstrate how to use the “List Visualization” later, but for now we are just going to make a regular list. I will demonstrate how to use the “List Visualization” later, but for now we are just going to make a regular list. However, you can use a list without the actual ListVisualization, if you also want to use an “Array” in your world. However, you can use a list without the actual ListVisualization, if you also want to use an “Array” in your world.

Getting Started What is a List? What is a List? A list is simply a way to organize information. A list is simply a way to organize information. What is an Array? What is an Array? An Array is a structure for collecting and organizing objects or information of the same type into a group. An Array is a structure for collecting and organizing objects or information of the same type into a group. In Alice Arrays and Lists are also visual objects which can be dropped into your world In Alice Arrays and Lists are also visual objects which can be dropped into your world

Cinderella Conducts We are going to make the world you just watched and use Lists and Arrays to make the chickens dance We are going to make the world you just watched and use Lists and Arrays to make the chickens dance This is the code to make Cinderella conduct while the chickens dance. If you want to add this to your world you can code it now and save it. We will use it at the end. This is the code to make Cinderella conduct while the chickens dance. If you want to add this to your world you can code it now and save it. We will use it at the end.

Making a List Create a world level method named “ChickenMove” Create a world level method named “ChickenMove” Drag the “For all Together” Button onto the method editor Drag the “For all Together” Button onto the method editor Select “Create new list” Select “Create new list”

Lists Name it “ChickDanceTogether”, select “object” as the type. Name it “ChickDanceTogether”, select “object” as the type. A white box will come up that says “initialize list”. Click new item until all the chickens are in your list. The first item starts at 0. Keep your chickens in order. A white box will come up that says “initialize list”. Click new item until all the chickens are in your list. The first item starts at 0. Keep your chickens in order.

Lists We want the chickens to roll left and right together. First you need to right the code to have one chicken roll left and then right. Above is the code to have one chicken roll left and then right I selected Chicken 2 but any chicken will work

Lists Now drag the tab label “item_from_ChickensDanceTogether” over the box that was previously labeled “Chicken 2” Now drag the tab label “item_from_ChickensDanceTogether” over the box that was previously labeled “Chicken 2” Repeat this for each command to make the chickens roll Repeat this for each command to make the chickens roll

Lists Now we have programmed the Lists to have all the chickens roll left and then right at the same time. Now we have programmed the Lists to have all the chickens roll left and then right at the same time. But what if we want them to do something, one at a time? But what if we want them to do something, one at a time? This is where ‘For all in order’ comes in. This is where ‘For all in order’ comes in. We will now program the chickens to kick up their left leg, one at a time. We will now program the chickens to kick up their left leg, one at a time.

Lists Click on the “For all in order” tab at the bottom of your screen and drag it into your method Click on the “For all in order” tab at the bottom of your screen and drag it into your method Now create a new method named “KickUpRightLeg” and give it an object parameter called “WhichChicken” Now create a new method named “KickUpRightLeg” and give it an object parameter called “WhichChicken” Below is how the code will look when we have finished the next few slides Below is how the code will look when we have finished the next few slides

Part Named Key Make a simple command using any object like “chicken” and have it do the command. Then, create a parameter and drag it into the original object. Click on any object (like chicken) Now go to functions and scroll down to “Part named Key” insert it everywhere you have a parameter

Part Named Key Continued Now, click on the white box (circled in red) and scroll down to “other”. Now, click on the white box (circled in red) and scroll down to “other”. Once you click on “other” and type in the appendage that you want to command. In this case the left leg. Remember the syntax must be the same as it is listed on the object

Part named key conclusion Finally take your object parameter and drop it back in where it says chicken Finally take your object parameter and drop it back in where it says chicken Your code should look like the picture below when you are done Your code should look like the picture below when you are done

Lists Now go back into your first method and drag your “KickUpRightLeg” method into the “For all in Order” space, in your world level “chicken move” method. Now go back into your first method and drag your “KickUpRightLeg” method into the “For all in Order” space, in your world level “chicken move” method. Select Expressions and then Item_from_ChickensDanceTogether Select Expressions and then Item_from_ChickensDanceTogether

Lists Now that this portion is programmed all the chickens will roll right and then left at the same time for the “Together Functions” and kick up their legs one at a time for the “For all in order Functions” Now that this portion is programmed all the chickens will roll right and then left at the same time for the “Together Functions” and kick up their legs one at a time for the “For all in order Functions” This saves lots of time and lines of code This saves lots of time and lines of code Imagine if we had to program each chicken to do this individually! Imagine if we had to program each chicken to do this individually!

List Visualizations If you are not also using an Array and would like to visualize your list you can select the list visualization class from the Visualizations folder If you are not also using an Array and would like to visualize your list you can select the list visualization class from the Visualizations folder DO NOT DO THIS RIGHT NOW (BECAUE WE ARE GOING TO CREATE AN ARRAY AS WELL)OR IT WILL MESS UP THE LIST YOU JUST CREATED DO NOT DO THIS RIGHT NOW (BECAUE WE ARE GOING TO CREATE AN ARRAY AS WELL)OR IT WILL MESS UP THE LIST YOU JUST CREATED After entering in all of the Chickens they should be aligned in a row that looks like this. After entering in all of the Chickens they should be aligned in a row that looks like this. If you “Set is Showing to False” the List Visualization will disappear, but it is still there. If you “Set is Showing to False” the List Visualization will disappear, but it is still there. If we were not going to create an Array you could add the List Visualization without problems.

Arrays Lists are great for coding a group of objects to all do the same thing (either together or in order). Lists are great for coding a group of objects to all do the same thing (either together or in order). But what if we want to code only some of the objects in our group to do something. But what if we want to code only some of the objects in our group to do something. This is where Arrays come in. This is where Arrays come in. The following slide will show the place that you need to go to find the Array. It is called “Array Visualization”. The following slide will show the place that you need to go to find the Array. It is called “Array Visualization”. Drop it into your world. Drop it into your world.

Starting the Array Go to add objects Go to add objects Select the folder at the end of the list entitled “Visualizations”. Select the folder at the end of the list entitled “Visualizations”. The first object on the left should be a class called “Array Visualizations”. It should look like a strip of concrete. Select it

Starting the Array We are going to use our Array for the chickens We are going to use our Array for the chickens When you add the Array to your world this box called “Initializing Array” will appear When you add the Array to your world this box called “Initializing Array” will appear Count the number of chickens you have and select the button “New Item” for that many. Count the number of chickens you have and select the button “New Item” for that many. Remember it will start at 0 Remember it will start at 0

Array continued Once you have entered all of your chickens into the Array your screen should look like this. Once you have entered all of your chickens into the Array your screen should look like this. If it does, click ok. If not, hit “undo” at the top left and try again If it does, click ok. If not, hit “undo” at the top left and try again Once you hit ok your chickens should be neatly lined up on the Array. Once you hit ok your chickens should be neatly lined up on the Array.

Arrays Click on your “Array Visualization” and then “properties”. Set “Is showing to False” to hide your Array Visualization so that the chickens do not look like they are standing on anything. Click on your “Array Visualization” and then “properties”. Set “Is showing to False” to hide your Array Visualization so that the chickens do not look like they are standing on anything. However, the Array is still there and functional However, the Array is still there and functional

Array Continued This is how our code will look when we are done. This is how our code will look when we are done. Note the small red circle on the left Note the small red circle on the left This is how your array will appear in your tool bar. This is how your array will appear in your tool bar. The large circle on the right is the beginning of how we will use our Array to animate our chickens.

Arrays Continued First, lets have our chickens all turn to face Cinderella. Again you can code this with any chicken. See below First, lets have our chickens all turn to face Cinderella. Again you can code this with any chicken. See below

Arrays Continued Now create a parameter Now create a parameter You can name it whatever you would like You can name it whatever you would like Drag it into your chicken command ( picture on right) Drag it into your chicken command ( picture on right) Now go to Array Visualizations, properties, and drag the “elements” tab down to your parameter. Select 0, repeat this step for each chicken in your Array

Complete Turn to Face Code Note that each element in the Array is coded separately but they are all doing the same thing. Now let’s get them to do different things. Note that each element in the Array is coded separately but they are all doing the same thing. Now let’s get them to do different things.

Getting Chickens to do Different Things To get the chickens to move up and down at different times you will follow the same steps that you just performed with" Turn to Face” in the Cinderella slide. To get the chickens to move up and down at different times you will follow the same steps that you just performed with" Turn to Face” in the Cinderella slide. See the code below See the code below Note that we only selected chickens 0, 2 and 4 to perform this task. After making the even number chickens move up and down, add code to make the odd number move, separately.

Arrays Continued Once you have finished plugging in the Array your code should look like this Once you have finished plugging in the Array your code should look like this Note that only chickens 0, 2, and 4 are going to move. Note that only chickens 0, 2, and 4 are going to move. This is the beauty of the Array It allows you to only move selected objects in your Array Whereas with the List you must move everything

Arrays This is the visual This is the visual Note how Chickens 0, 2 and 4 are moving down while chickens 1, 3, and 5 are moving up. Note how Chickens 0, 2 and 4 are moving down while chickens 1, 3, and 5 are moving up. You can program each chicken individually or in any number you want to You can program each chicken individually or in any number you want to

Putting it all together For the Final construction I created a BDE event and did the same trick that was used in the vehicle tutorial. Put an invisible bunny in the world and have him change colors. While he is one color Cinderella conducts, while he is a separate color she does not. For the Final construction I created a BDE event and did the same trick that was used in the vehicle tutorial. Put an invisible bunny in the world and have him change colors. While he is one color Cinderella conducts, while he is a separate color she does not. The bunny will turn one color while the chickens begin to dance, this will trigger Cinderella to start conducting. When the chickens finish, the bunny will turn a different color, which will signal Cinderella to stop. The bunny will turn one color while the chickens begin to dance, this will trigger Cinderella to start conducting. When the chickens finish, the bunny will turn a different color, which will signal Cinderella to stop.

Final construction And that’s all folks!

Recap When we put all of these elements together you can see how Lists and Arrays can be used interchangeably to animate your Alice world. When we put all of these elements together you can see how Lists and Arrays can be used interchangeably to animate your Alice world. The ‘For all together’ command in Lists allows you to animate a group of objects to do something together. The ‘For all together’ command in Lists allows you to animate a group of objects to do something together. The ‘For all in order’ command in Lists allows you to animate the whole group of objects to do the same thing, but one at a time. The ‘For all in order’ command in Lists allows you to animate the whole group of objects to do the same thing, but one at a time. The Array allows you to have a group of objects do different things. The Array allows you to have a group of objects do different things.