Chapter 2: Programming in Alice

Slides:



Advertisements
Similar presentations
Mike Scott University of Texas at Austin
Advertisements

Visual Lists By Chris Brown under Prof. Susan Rodger Duke University July 2012.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Skater World: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger May 29,
PIIT Computer Science Summer Camp - Alice July 10, 2012 Brenda Parker Computer Science Department MTSU.
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.
Implementation with procedural methods. Recall: Step 3 Write statements (code) – a few steps at a time, not the entire program at once! Problem Statement.
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
SETTING UP CAMERA VIEWS LESSON Setting camera views using objects, based on a lesson by Bella. Adventures in Alice Susan Rodger Duke University July 2013.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009.
Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Programming in Alice Chapter 2. Today’s Agenda Designing a Program Writing Methods Executing Instructions Simultaneously Comments Tips for Setting Up.
Exploring Events. Try this Start Alice and create a blank world using the grass template. Add an instance of a BlueBallerina. Add an instance of a PinkBallerina.
Programming in Alice Chapter 2 Part 2. Events Editor Identifies what method is executed (run) when the “Play” button is hit 2.
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
Copyright 2011 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Implementation Algorithm  Code World.my first method Control blocks Statements (methods,
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
CS320n –Visual Programming Introduction to Alice Mike Scott (Slides 2)
Programming Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
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.
By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
Lists Tutorial By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Review for test! Alice Chapter 1&2 Test is tomorrow! - March 26 th March 25th.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July 2013 Updates.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1, 2009.
BDE tutorial By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 13, 2008.
Alice: A Free 3D Animation World for Teaching Programming.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Lesson 8C Animation and Events. Step 3: Animation Drag it into the method and have him say “let her go!” Click on the knight in the object tree and scroll.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
Presenter: Carol Liss Timberlane Regional Middle School 6 th and 7 th grade Tech. Educator Co presenters:
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
Programming in Alice Chapter 2.
Skater World: Part Four
Professor Susan Rodger
Chapter 3: Variables, Functions, Math, and Strings
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko
The Alice Interface.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Classes, Objects, and World-level Methods
Chapter 2: Programming in Alice
Making Objects Move in Unison: Using Lists
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
Introduction to Object-Oriented Programming in Alice
Headshots in Alice Duke University Professor Susan H. Rodger
Presentation transcript:

Chapter 2: Programming in Alice

Chapter 2 Objectives To understand: method naming conventions what dot notation is what a primitive method is and which objects have them what is meant by “calling” what an argument is in a program. differences in naming conventions the steps of the program development cycle what a logical error is the need for commenting

Lessons Writing Methods Naming Conventions Designing a Program Comments Tips for Setting Up an Initial Scene Executing Instructions Simultaneously Exporting Your Code for Printing

2.1 Writing Methods In chapter 1 we learned the basics of placing objects in an Alice world and then manipulated the way those objects appear. The worlds did not perform any actions. If we want the objects in an Alice world to perform actions, we have to write a program.

Writing Methods What is a method? set of instructions that execute 2.1 Writing Methods What is a method? set of instructions that execute create methods by dragging tiles into the Method Editor these tiles are the instructions my first method

the period is called a “dot” 2.1 Naming Conventions All methods have a name. dot notation world.my first method dot (period) separates pieces of information left side: object that the method belongs to in this case…the method belongs to the WORLD object right side: name of the method in this case… “my first method” the period is called a “dot”

2.1 world.my first method Events Editor identifies which method plays or is acted upon when the “Play” button is hit

tile world.my first method 2.1 world.my first method Methods play the instructions (tiles) that are dragged into the Method Editor Each tile represents an action that will take place when the world is played. tile

2.1 Primitive Methods All objects have a common set of built-in method for performing actions. These “primitive methods” all objects to move, turn, change size, and more. Example: Hare has primitive methods: move, turn, roll, resize, say, … Name of object.Name of method

Adding a Method to a Program 2.1 Adding a Method to a Program Highlight the object, drag and drop the method into the Method Editor, select the arguments.

Adding a Method to a Program 2.1 Adding a Method to a Program Or Right click on the object, choose the methods menu, choose the method from the list, choose the arguments

Terminology argument argument method object editing tag 2.1 Terminology Calling the method Executing a method Argument: piece of information that a method needs in order for it to execute hare.move…which direction? the direction…up, down, left, right…is the argument Passing the Argument: the method is called and the arguments are presented argument argument method object editing tag

Editing Tag Holds additional arguments 2.1 Editing Tag Holds additional arguments What appears depends on the method called duration is a common one specifies amount of time for action to take place default (1 second)

Table 2-1 summarizes all the primitive methods. 2.1 Table 2-1 summarizes all the primitive methods. orient to turn to face point at set point of view to set pose stand up move at speed turn at speed roll at speed constrain to face constrain to point at move turn roll resize say think play sound move to move toward move away from

Deleting Instructions 2.1 Deleting Instructions Right-click the instruction and select delete or Drag the instruction tile to the trash can

Copying Instructions Right-click the instruction and select copy 2.1 Copying Instructions Right-click the instruction and select copy Drag the instruction tile to the clipboard when the clipboard turns green, drop the tile click on the clipboard and drag it back to the Method Editor

2.1 Custom Methods In addition to primitive methods (the things that ALL objects can do)…some objects have custom methods Custom methods are methods that only objects of a specific class can do. When objects is selected from gallery, a listing of custom methods appears. Names of the custom methods give clues as to what the method does. What do you think the foottap custom method does?

2.1 Custom Methods When you add an object and then select that object, tiles representing its custom methods (if it has any) appear above the tiles for the primitive methods in the Details Panel.

2.1 p. 62 Tutorial 2-1 Happy Hare aka Hare jumps up then down.

p. 67 Tutorial 2.2 Really Happy Hare 2.1 p. 67 Tutorial 2.2 Really Happy Hare aka hare jumps up, spins around, comes down, and says “that was fun”

2.1 Checkpoint p. 72 1. In an Alice world you have an object named hare. The hare object has a method named move. How would you write the method name using dot notation? 2. What causes a method to be executed automatically when a world is played. 3. What is a primitive method? 4. How do you see a list of the primitive methods that an object has? 5. When specifying a distance for the move method, what happens when you select other…. from the menu? When would you use this selection?

Checkpoint p. 72 continued 2.1 Checkpoint p. 72 continued 6. A fellow classmate has placed an instruction in the Method Editor. You ask her what the method does, and she says, “It calls another method.” What does she mean by that? 7. What is an argument? 8. What is a custom method? Do all classes provide custom methods? 9. How can you see a list of the custom methods that a class has?

Which one coaches the Mustangs and which one coaches the Eagles? 2.2 2.2 Naming Conventions Names are known as identifiers…because they identify items in a program. Use a name that provides meaning Name of method should indicate the method’s purpose. Which one coaches the Mustangs and which one coaches the Eagles?

namingConventions Most programming languages do NOT recognize spaces. 2.2 namingConventions Most programming languages do NOT recognize spaces. Alice allows spaces method.my first method Since spaces are not allowed, how do you combine more than one word in naming? Capitalize subsequent words Called camelCase Note the space Note the space Which is easier to read? onehumpcamel or oneHumpCamel 24

Class Names method names begin with a lower case letter 2.2 Class Names method names begin with a lower case letter Class names are capitalized No spaces, so each word is capitalized This convention is called PascalCase

Renaming Objects Methods 2.2 Renaming Objects Right-click object’s tile in the object tree and select rename. Methods Select the world object Select the method’s tab from the Details Panel Right-click the my first method tile and select rename.

Checkpoint p. 77 10. Why is it important that you give meaningful names to objects? 11. In most traditional programming languages, it is acceptable to have spaces in object or method names? 12. What is the camelCase naming convention? When is it used? 13. What is the PascalCase naming convention? When is it used?

2.3 2.3 Designing a Program Design the program Write the methods Test the methods Debug the methods Design requires planning…that follows the above steps Called Program Development Cycle Cycle is repeated until NO errors appear in the program.

Designing the Program Determine what the world is supposed to do. 2.3 Designing the Program Design the program Write the methods Test the methods Debug the methods Determine what the world is supposed to do. Read a problem statement that describes the which objects will appear in the world, and the actions that are to take place. What is the “Story”? 29

2.3 Designing the Program Design the program Write the methods Test the methods Debug the methods Break the problem statement down into series of steps Pseudocode or Flowchart 30

2.3 Writing the methods Design the program Write the methods Test the methods Debug the methods Design steps (pseudocode or flowchart) provides model for writing the methods Drag tiles into Method Editor to assemble instructions Instructions should follow the order of the Design steps Pseudocode and flowchart may NOT be at the detail of the final instructions 31

Testing Test to make sure it meets the following criteria: 2.3 Testing Design the program Write the methods Test the methods Debug the methods Test to make sure it meets the following criteria: Does it do what it was intended to do? Does it have any errors? Any undesired results? Is it efficient? Are there unnecessary steps? If the criteria are NOT met, then debugging occurs 32

2.3 Designing a Program Design the program Write the methods Test the methods Debug the methods Debugging means to determine what must be corrected or modified to get the program to work correctly Logical errors (bug) is a mistake that produces an incorrect result, but the program still runs. Instructions in an incorrect order may produce incorrect results Passing incorrect values as arguments can cause logical errors 33

Tutorial 2-3 Using the program design cycle 2.3 Tutorial 2-3 Using the program design cycle Story: Recreate the opening scene of Lewis Carol’s Alice’s Adventures in Wonderland. Alice sees White Rabbit run by her, saying to itself, “Oh dear! Oh dear! I shall be late!”

2.3 Checkpoint p. 87 14. What are the steps in the program development cycle? 15. What are two tools that you can use to break down a problem into a series of steps? 16. What is a logical error? 17. When testing a method, what are three criteria that you should make sure the method meets?

2.4 Comments //comment tile A comment is a note explaining the code. Crucial part of the code. Makes the code understandable. Alice ignores comments when it plays your program. //comment tile

2.4 Tutorial 2-4 Inserting Comments

Checkpoint p. 90 18. Why are comments important? 2.4 Checkpoint p. 90 18. Why are comments important? 19. Do comments affect the way a program runs? 20. What symbols appear on the comment tile in Alice? Why were these symbols chosen?

2.5 Tips for Setting Up the Initial Scene Use the primitive methods to setup the scene. Select the object in the Object Tree, then select a method. Use the primitive methods to position the objects. Doing so from the Object Tree positions the objects outside of the program.

Tips for Setting Up the Initial Scene 2.5 Tips for Setting Up the Initial Scene Moving an object to the center of the world Use the move to method and choose the entire world as the method’s argument Places the object’s center point at the world’s center point of (0, 0, 0) 40

Tips for Setting Up the Initial Scene 2.5 Tips for Setting Up the Initial Scene Positioning objects a specified distance apart Use the move to method and choose asSeenBy the other object for the method’s argument Places the object’s center point at the world’s center point of (0, 0, 0) 41

Tips for Setting Up the Initial Scene 2.5 Tips for Setting Up the Initial Scene Moving the camera to an object Right-click the object and choose Camera get a good look at this Camera moves to a position so the object is in plain view 42

2.6 Executing Instructions Simultaneously By default, instructions are executed one after the order…in the order they appear in the Methods Editor For simultaneous actions, drag Do together into the Methods Editor Other instructions can be placed within the Do together tile Make sure the duration for all items in a Do together are the same

The Do in order Structure 2.6 The Do in order Structure By default, all instructions are performed in order they appear in the Methods Editor Do in order structure used when more than one set of actions must occur simultaneously…but has steps that must be done in order

Tutorial 2-5 Creating simultaneously executed instructions 2.6 Tutorial 2-5 Creating simultaneously executed instructions Story: Two penguins (a brother and a sister) are facing each other, 2 meters apart. The brother penguin says, “Hey sis!”. Then the sister penguin says, “Hey brother!” Then the two penguins simultaneously move ½ meter toward each other and stop. Then they simultaneously jump in the air.

2.6 Checkpoint p. 104 21. How do you cause instructions to execute simultaneously? 22. How can you cause some of the instructions in a do together structure to be executed in order?

2.7 Exporting Code for Printing Code can be exported to an HTML file Open the file and Print From File – Choose Export Code for Printing You must add your name as the author Author’s name is printed with the exported code Author’s name

Review Questions p. 105 Short answer p. 107

Exercises 1. Scene from Alice’s Adventures in Wonderland 2. Animated Underwater World 3. Magic Cookies, Part 1 4. Magic Cookies, Part 2 5. Animal and Bicycle 6. Drag Racing 7. Playing Ball 8. Dancing 9. Apollo 15 Experiment 10. Tables, Chairs, and a Magic Broom 11. Movie Scene