Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Where are we? Alice is a “toy” language Fundamentals are exactly like “real”

Slides:



Advertisements
Similar presentations
Space Man Sam: Grammar Mistakes By Aleis Murphy Duke University, Under the direction of Professor Susan Rodger July 2010.
Advertisements

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,
CS320n –Visual Programming Class-level Methods and Inheritance – Part 1 Mike Scott (Slides 4-3-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger.
Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Class-level Methods and Inheritance Part 1 Alice.
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
PIIT Computer Science Summer Camp - Alice July 10, 2012 Brenda Parker Computer Science Department MTSU.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Alice Methods and Classes. Methods and Classes Methods – Coordinated sequence of instructions carried out when requested (e.g. move, turn to, etc.) Class.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday.
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Functions and Visual Effects Chapter 6 Part 3. Built-in Functions We have been using built-in functions so far 2.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Alice: A Visual Introduction to Programming Chapter 1 Part 2.
Programming in Alice Chapter 2 Part 2. Events Editor Identifies what method is executed (run) when the “Play” button is hit 2.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Classes / Objects / Methods
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
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.
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.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 3 Simple.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
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.
Alice: A Visual Introduction to Programming Chapter 1 Part 2.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Exam scores by range 3-1.
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.
Variables and Inheritance Part 1
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Mathematical Expressions, Conditional Statements, Control Structures
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Creating a Historical Tour in Alice By Jenna Hayes May 2010.
1 Quiz Template: Using the ‘ask user’ functions By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 2009.
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.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 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.
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
Chapter 2: Programming in Alice
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),
Alice in Action with Java Chapter 2 Methods. Alice in Action with Java2 Objectives Build world-level methods to help organize a story into scenes and.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Class-level Methods Alice.
Making Procedural Methods
Chapter 2: Programming in Alice
Introduction to Object-Oriented Programming in Alice
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Class-level Methods and Inheritance
Presentation transcript:

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Where are we? Alice is a “toy” language Fundamentals are exactly like “real” languages Concepts of parameters, reuse, design are classic First half of the semester, we talked about problems scientists and particularly computer scientists solve Second half we look at the fundamental tools used in solving those problems 5-1

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Computer Science – is it for you? Some of you have a real talent for this. Computer Science degrees earn $51K starting and over $100K after a few years. There are jobs now and only getting more! Projected to increase by 38 percent over the next ten years, which is much faster than the average for all occupations. This occupation will generate about 324,000 new jobs, over the next decade, one of the largest employment increases of any occupation. Try CS 1400 next semester 5-2

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition by Tony Gaddis Chapter 13: Methods, Functions, and More about Variables

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-4 Writing Custom Class-Level Methods If a class does not provide a method, a custom method can be written. Have it YOUR way. A VERY IMPORTANT CONCEPT For example, we could have a method for our bopper which goes to an item and bops! Write the pseudocode Primitive methods are available for various classes - Move, Turn, Roll, Say, Think, etc. Some classes have customized methods written just for them --flap, hop, walk, jump 5.1

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Suppose I want to create rollable wheelies – where as they move forward the wheels move. How would I get make it so my other programs could use rollable wheelies? What is a billboard? Give an instance where you would want to use one. What is a pose? Why would you want to use one? 5-5

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-6 Writing Custom Class-Level Methods Class-Level Methods –Methods that are part of a class Create an instance of the class –Select the instance –Create new method –Enter a name for the new method (remember to use camelCase!) 5.1

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Try one Takes any object and makes it jump What is input? What is the point of producing methods? 5-7

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Who “owns” the method? You can also have ‘world’ methods – that belong to the world. The method should be part of the most ‘logical’ group. “I have rights to everything I am using.” If you make ‘disappear’ a part of the world, when the magician is moved to another world, he/she won’t know how to make objects disappear. Reuse – means creating to be used again! 5-8

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-9 Saving an Object to a New Class Custom methods are for only a single instance of the class. If you “copy” the instance, the new instance will also have the methods. If you create a new instance or add to one of two instances, they don’t share methods. If methods will be needed in other worlds, need to create a new class. Saving as a new class, adds the new method to that object permanently. For example, if you get a chicken to walk, you might want to allow the class to be used by others (and yourself) Programming becomes very creative. The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures... Frederic Brooks, Jr 5.2

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-10 Saving an Object to a New Class Right-click and Rename the object in the object tree 5.2 Right-click and Save Object… The new class ends has the new extension:.a2c (NOT.a2w like Alice worlds and programs!) From File, choose Import… Select file and press the Import button IMPORTANT!!! Make sure that when an object becomes a new class (and can be used in other worlds) that is it independent of the world If it depends on anything in the world and you use it in the new world, it may not work since it can’t “find” that old world!

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-11 Inheritance New methods were added and a new class was created. The new class still contains the methods that had previously been associated with the original object and class (such as Move, Turn, Say) The new class also contains the properties that had previously been associated with the original object and class (such as Color, Opacity, Vehicle) The new class inherited all the original methods and properties from the original class 5.2

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-12 Stepwise Refinement Better to start out with general idea and then develop the detail 5.3 Refined to have more detail added to it Algorithm becomes several methods

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-13 Stepwise Refine Example Note the reuse Original Algorithm: Raise the right leg Loop 10 times: Do together: Lower the right leg Raise the left leg End Do together Do together Lower the left leg Raise the right leg End Do together End Loop Lower the right leg Modified Algorithm: Call rightLegUp(+1) method Loop 10 times: Do together: call rightLegUp(-1) method call the leftLegUp (+1) method End Do together Do together call leftLegUp(-1) method call rightLegUp (+1) method End Do together End Loop call rightLegUp(-1)_ method 5.3

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-14 Stepwise Refinement The algorithm is not necessarily incorrect, it just needs more detail 5.3 Development and use of new methods means that code can sometimes be reused Development and use of new methods reduces the amount of code written

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-15 Passing Arguments Methods are written to accept arguments Arguments are values that are passed 5.4 Example of arguments: –Direction, distance traveled

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-16 Passing Arguments Passing arguments requires the use of parameters Parameters are variables that hold an argument that will be passed (or used) into the method Once created, the argument is required anytime the method is called or used 5.4

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Functions return a value where methods don’t. For the following identify inputs and possibly outputs: Solo for beetle Wheely moving around and turning near edge Checking if wheelies have crashed Making an object levitate Making all objects disappear 5-17

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using the class parameters It “real” languages, you are able to specify the type of the parameter. That allows you to use methods that all objects don’t necessarily have. Not being able to do that is limiting 5-18

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-19 Using Class-Level Variables as Properties Properties can be added to an object through the creation of class-level variables When the object is saved as a new class, the variables are saved with it Common properties are: –color –opacity –isShowing 5.5

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-20 Using Class-Level Variables as Properties Property is a variable that belongs to an object Properties hold data about that object and are referred to as class-level variables 5.5

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-21 Writing Class-Level Functions Function is a method that returns a value back to the instruction –such as: distance to Additional data is required by the function to return back a value –for example…ExerciseGirl can runInPlace forever, but she’ll get tired –a function can be created…but it needs to know how many repetitions it will take before she gets tired AND how many repetitions she has already completed 5.6

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-22 World-Level Methods and Variables Rather than creating one long method…several smaller world-level methods can be created Each smaller method performs a specific part of the overall animation Can also create world-level variables –These variables are available to all methods in the world. 5.7

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-23 World-Level Methods Class-level methods give unique behaviors to an object World-level methods are methods created for the object world Worlds can have many methods Commonly used to break a large complex algorithm into small manageable pieces –This is the divide and conquer approach 5.7

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-24 World-Level Methods Meant to simplify the program Once a method has been written, it can be used many times –Known as code reuse because the code is written once and used many times to perform the task 5.7

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-25 World-Level Methods Example 5.7

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-26 World-Level Methods Example 5.7

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-27 World-Level Variables Variable that belongs to the world object World-level variables act as properties for the world Exist as long as the world is running (playing) Available to all methods in the world 5.7

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-28 Using Clipboards Clipboards are locations for storing a copy of something Use the clipboard in Alice to copy an instruction from one method to another –Drag the instruction tile to the clipboard –Grab the clipboard and drag back to another method –Very flakey – doesn’t work well with parameters 5.8 Only one clipboard appears in Alice…the brown one is what an empty clipboard looks like and the white version has information stored in it.

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-29 Need More Clipboards? Increase the number of clipboards from Edit - Preferences 5.8

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-30 Tips for Visual Effects and Animation Billboards –Graphical images that have been inserted into the world –Can insert images that are JPEG, GIF, TIF –Known as “Billboard” –Images are flat, 2D with height and width no depth –Can be used as backgrounds or scenery or used to give instructions to the viewer! 5.9 Boy are you shallow, you’re only 2D!

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-31 Tips for Visual Effects and Animation Fog –Alice has a look of “mist” to the world –The entire world becomes less visible 5.9

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-32 Tips for Visual Effects and Animation Once an object has been put into a position or pose, the pose can be restored during an animation –Pose is a property of an objec –setPose is a method of an object 5.9

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-33 Tips for Visual Effects and Animation Programming the Camera –Camera can be programmed just like other objects –All the same primitive methods and functions are available for it: Point at, Move, Turn, etc. –Camera can also be a vehicle for other objects! 5.9

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-34 Tips for Visual Effects and Animation Creating Dummy Objects –Dummy objects are invisible objects that are placed in the world –Camera then moves to the invisible object to get different perspectives 5.9