CS320n –Visual Programming

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.
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 2: Using Methods.
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.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
CS320n –Visual Programming Indefinite Loops (Slides 7-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Alice: A Free 3D Animation World for Teaching Programming Barbara Ericson Georgia Institute of Technology Oct 2005.
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.
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 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.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
Lists Tutorial By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
What we will do today Learn about functions in Alice.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
CS320n – Elements of Visual Programming Lists Mike Scott (Slides 9-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Advanced Recursion (Slides 8-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
CS320n – Elements of Visual Programming Sending Parameters to Event Handler Methods (Slides 5-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
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.
CS320n –Visual Programming Definite / Counted Loops (Slides 7-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
CS320n –Visual Programming Problem Solving Case Study (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
CompSci 4 Chap 10 Nov 22, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
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.
FOP: Multi-Screen Apps
Skater World: Part Four
Functions Sec 51 Web Design.
Learn about functions in Alice
CS320n – Elements of Visual Programming
Professor Susan Rodger
Chapter 3: Variables, Functions, Math, and Strings
Classes, Objects, and World-level Methods
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Changing Color, Using Text Objects, and Random Selection in Alice
Functions Sec 8-11 Web Design.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Class-level Methods Alice.
Methods Tutorial: Part Two
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
Alice: A Free 3D Animation World for Teaching Programming
Functions Alice.
Alice: A Free 3D Animation World for Teaching Programming
Headshots in Alice Duke University Professor Susan H. Rodger
Using Placeholders to Simplify your Methods: Learning Methods, Part 2
Making Objects Move in Unison: Using Lists
Functions Alice.
Class-level Methods and Inheritance
Functions Alice.
Functions Alice.
Class-level Methods and Inheritance Part 2
Presentation transcript:

CS320n –Visual Programming Class-level Methods and Inheritance – Part 2 Mike Scott (Slides 4-3-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slides.

Class Level Methods - Part 2 What We Will Do Today Work on more class level methods Learn about built in functions Learn to use expressions Review the asSeenBy option Visual Programming Class Level Methods - Part 2

Guidelines for Class-Level Methods Should a method be a class-level method or a world-level method? For class level methods avoid hard coded references to other objects avoid calls to world level methods Play a sound only if has been imported and saved as part of the new class. (sounds can be imported to world or individual objects) If these guidelines are not followed and an instance of a class is added to another world, an error message is generated Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Bad Example 1 A class level method should not call world-level methods. Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Bad Example 2 Visual Programming Class Level Methods - Part 2

But I want to skate around things Is it reasonable to want a class-level method for the advanced skater where she skates around things? In this particular case, a penguin? Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Solution A solution is to write a class-level method with an object parameter that allows you to pass in the 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 Visual Programming Class Level Methods - Part 2

Parameterized Version of skateAround Making the object to skate around a parameter now removes the tie to the penguin in this world calling skateAround Visual Programming Class Level Methods - Part 2

Translating design into code Most of the skateAround storyboard design is straightforward and easy to code. The last two steps, however, require some thought: advancedSkater move to target -- What distance should the cleverSkater move? advancedSkater turn around target -- how do we tell cleverSkater to turn (in a circle) around another object? Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 The distance to move We can work out how far to move the skater based on initial position of objects and a little experimentation Pick a distance, play the movie, more or less, refine until it looks good Is this a very general solution though? only works for one initial set up look to make it work for many set ups Visual Programming Class Level Methods - Part 2

Built-in Functions. (a.k.a. questions) The built-in function, distance to can be used to determine the distance the skater must move. Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Calling the Function drag and drop the function advancedSkater distance to from the function menu to the distance portion of the move method and pick expressions -> target call to move looks like this now Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Problem? What will happen when the skateAround method is called? Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Too Much Skater intersects penguin told to move forward the distance to the target moves skater all the way so centers of objects coincide distance measured center to center Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Expressions We don’t want the skater to move all the way to the target to avoid collision use math operator and create an expression that moves to within 2 meters Math operators is Alice: +, -, *, / Example: Visual Programming Class Level Methods - Part 2

Creating an Expression 1 3 2 4 Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 More on Expressions Creating expressions with the pop up menus can be a pain In this case, text based programming languages may be easier to use Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Result of Expression Stops before running over penguin And skates around What if already less than 2 meters from an object? Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 asSeenBy To have the skater skate around another object, pass whichObject as an argument to the asSeenBy parameter in a turn instruction. yes, passing a parameter to another method as a parameter For more details on asSeenBy, review Tips & Techniques 2. Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 More on AsSeenBy Use invisible objects or dummy objects (isShowing property set to false) to have objects fly around in circles Example: Have gunfighters circle each other Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Circling Gunfighters Visual Programming Class Level Methods - Part 2

Class Level Methods - Part 2 Testing Each time you create a new class, test it: Add an instance of the new class to a new world. Write a short testing program to test each new method. Testing increases your confidence in the ability to reuse your code in other worlds. Visual Programming Class Level Methods - Part 2