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.

Slides:



Advertisements
Similar presentations
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 3: Billboards, Events, Sounds,
Advertisements

Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
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.
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.
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
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.
Repetition Structures
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.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
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.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
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.
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.
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
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.
Alice Tips and Techniques. Tips and Techniques I suggest you read the tips and techniques sections at the ends of the chapters. Tells you how to do things.
Poses Tutorial Alex Boldt Under the direction of Professor Susan Rodger Duke University July 2015.
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 Where are we? Alice is a “toy” language Fundamentals are exactly like “real”
What we will do today Learn about functions in Alice.
Functions Alice.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
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.
Programming: Simple Control Structures
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1, 2009.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Programming in Alice IT-IDT-9 Design, develop, test and implement programs using visual programming. 9.1 Utilize drag and drop software to develop programs.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Presenter: Carol Liss Timberlane Regional Middle School 6 th and 7 th grade Tech. Educator Co presenters:
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
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),
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
Functions Sec 51 Web Design.
Learn about functions in Alice
Teaching Characters to Walk: Learning Methods, Part 1
Functions Sec 8-11 Web Design.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
CS320n –Visual Programming
Programming: Simple Control Structures
Class-level Methods Alice.
Programming: Simple Control Structures
Programming: Simple Control Structures
Getting Started With Alice
Functions Alice.
Programming: Simple Control Structures
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Headshots in Alice Duke University Professor Susan H. Rodger
Functions Alice.
Programming: Simple Control Structures
Class-level Methods and Inheritance
Functions Alice.
Functions Alice.
Class-level Methods and Inheritance Part 2
Presentation transcript:

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 level object Examples o A person walking o A skater skating Unlike world class-level methods o Which has access to multiple classes

Example Skater object does not have a skate method To create a skate method for ice skater objects We need to: (1)Tell Alice to associate a new method with iceSkater class (2)Write a new method to animate ice skater skating

Associate Animation with Skater Select iceSkater tile in Object Tree Select methods tab in details panel Click on create new method button

Storyboard for skate Method The slide actions each require several motion instructions Break down these two actions into smaller steps skate: Do together move skater forward 2 meters Do in order slide on left leg slide on right leg

Stepwise Refinement Refinement of slideLeft Do in order Lift right leg and turn upper body forward Lower right leg and return body upright Skate: Do together 1) move forward 2 meters 2) Do in order slideLeft slideRight Refinement of slideRight Do in order Lift left leg and turn upper body forward Lower left leg and return body upright

Demonstration Concepts illustrated o Method defined for a specific type of object defines action for that object o A method can call other methods skate method calls slideRight and slideLeft

Reuse Writing methods that make ice skater perform skating motion is complex task Would like to reuse iceSkater skate in other worlds without writing methods again

Creating A New Class 1)Rename iceSkater as cleverSkater either a)Double click object name b)Or right click name 2)Right click name to save as a new class 3)Alice saves new class as CleverSkater.a2c Alice v2 Class

Inheritance The CleverSkater class o Inherits all properties and methods from original IceSkater class o Has newly defined methods  skate, slideLeft, slideRight In other programming languages o Inheritance - creates new class based on previously defined class

Importing CleverSkater An instance of the CleverSkater class can be added to a new world o Use File | Import o Set File Type to A2C o Choose class to import

Interacting With Other Objects Suppose you want to write a class-level method where another object is involved? Ex: method to make skater skate around another object, the penguin in this scene

Parameters in Class-level Method Solve skate around object by writing a class-level method with an object parameter Allows you to pass a specific object cleverSkater.skateAround Parameter: whichObject Do in order Do together cleverSkater turn to face whichObject cleverSkater lift right leg cleverSkater move to whichObject cleverSkater turn around whichObject

Guidelines To avoid potential misuse of class-level methods follow these guidelines o Avoid references to other objects  Use parameters if referencing another object is required o Avoid calls to world-level methods  Will not be saved with new class you created o Play a sound only if sound has been imported and saved out as part of new class

Demonstration Concept illustrated o Parameter whichObject is placeholder for the object value passed to it  Ex: penguin

Class-Level Variables as Properties  Property is a variable that belongs to an object  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: o color o opacity o isShowing

Tutorial 6-5: Turn Monitor On/Off Create class-level variable that keeps track of state of computer monitor: on or off On Off

Storyboard turnOnOff Do in order If monitor is on set screen color to black is on set to false Else set screen color to no color isOn set to true Endif

Storyboard Translated to Alice Notice how new method is preceded by monitor not world o Means it is a class-level method not world-level o Will be saved if class is saved o If world is saved the class will not be saved for future use in other programs  Can only use this in this new method in this specific program

Using turnOnOff Method Variable monitor.isOn is set initially to true In world.My first method o Turn off monitor using turnOnOFF  Variable monitor.isOn is now set to false o Wait 1 second to see effect o Turn on monitor using turnOnOFF

Built-in Functions We have been using built-in functions so far

How a Function Works A function o Receives value(s) as arguments in parameters o Performs computations on the value(s) o Returns (sends back) a value

Types of Functions The function type depends on the type of value it returns Examples o Number o Specific object o Boolean (true or false) o Color o Other property values…

Create Function Click on create new function in class or world you want it to be in Name function and choose type of function A blank function will be created with return statement Return statement will be returned when function is done o Place value you want returned in return statement

Function Window Since no action is performed in a function all instructions will be performed in sequential order o No need for Do in order and Do together o All will be Do in order Notice that you can place return elsewhere in function

Calorie Example A high school jock wants to know how many calories a cookie has He asks a lunch lady She consults the newly created calorie function o 1 meter wide cookie = 1000 calories Number Function calories Parameter: food Local Number variable: numCalories If food = cookie numCalories = cookie’s width *1000 Return numCalories

Storyboard Translated to Alice My first method has jock as lunch lady for the calories in the cookie The lunch lady checks how many calories with the calorie function and answers with the amount of calories

Visual Effects and Animation Billboards Fog Vehicles asSceneBy Circling Other Objects Pose Programming the Camera Creating Dummy Objects

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 info to the viewer! Boy are you shallow, you’re only 2D!

Information Billboard Can be used as sign for instructions

Creating Billboard Can import images using Make Billboard In File menu

Fog Alice can give a look of “mist” to the world The entire world becomes less visible

Vehicle Property To have two objects move as one One object will be carried by another object o Ex: person on horse  Horse is vehicle for person Choose properties tab o In property of object being carried  In vehicle choose object doing carrying

asSceneBy Argument All objects are egocentric To move one object in relation to another choose asSceneBy in more option of a method Ex: To rotate fish around island o Without asSceneBy fish would go in straight line

Circling Other Objects Object’s turn method spins the object around The turn method can also have an object circle around another object The asSeenBy argument causes an object to turn around the asSeenBy’s objects center point Example: the hawk turns one complete revolution, asSeenBy the tree, around the tree

Pose Once an object has been put into a position or pose, the pose can be restored during an animation o Pose is a property of an object o setPose is a method of an object

Programming the Camera Camera can be programmed just like other objects All the same primitive methods and functions are available for it: o Point at, Move, Turn, etc. Camera can also be a vehicle for other objects!

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

Homework Read chapter 6 sections 1,2,6,7 Answer questions in handout Do lab assignments after handing in answered questions Due one week after assigned with 1 week grace