Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.

Slides:



Advertisements
Similar presentations
Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Advertisements

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.
CSC1401 Animation Creating methods/instructions (class-level)
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Parameters Alice.
Introducing While loops (and random numbers too) Alice.
Fall 2009ACS-1805 Ron McFadyen1 Functions A function is a collection of statement, similar to a method, but a function is defined to return a value to.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Fall 2007ACS-1805 Ron McFadyen1 Functions and if-else A function is a collection of statement, similar to a method, but a function is defined to return.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
More About Recursion Alice. A second form of recursion A second form of recursion is used when the solution to a problem depends on the ability to break.
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
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.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Alice: Functions Alice Chapter 6 September 19, 2005.
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.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Variables and Inheritance A More Complex Example Alice.
Writing Our Own Functions Alice. Functionality A function receives value(s), performs some computation on the value(s), and returns (sends back) a value.
What we will do today Learn about functions in Alice.
Functions Alice.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Creating An Animation Program Alice. Step 1: Design Decide on the problem to be solved Design a solution We will use a storyboard design technique, commonly.
Creating An Animation Program Alice. Recall We began the animation creation process We introduced the concept of storyboard We will continue using the.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
Programming: Simple Control Structures
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Creating An Animation Program Alice. Recall We began the animation creation process We introduced the concept of storyboard We will continue using the.
Parameters Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
Parameters Alice. Overview The need for more flexible methods Passing a parameter to a method Demos Using the Alice interface to write code for a parameter.
Creating an Animation Program Alice. The programming steps.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Creating an Animation Program Alice. Step 1: Design Decide on the problem to be solved Design a solution We will use a storyboard design technique, commonly.
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.
Functions Sec 51 Web Design.
Learn about functions in Alice
Creating your Function
Functions Sec 8-11 Web Design.
Parameters Alice.
Alice and Media Computation August 2009
Class-level Methods Alice.
Programming: Simple Control Structures
Functions Alice.
More About Recursion Alice.
Parameters Alice.
Functions Alice.
Class-level Methods and Inheritance
Functions Alice.
Functions Alice.
Class-level Methods and Inheritance Part 2
Presentation transcript:

Questions Alice

Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.

Types of questions The type of a question depends on the type of value it returns. a calculated value (a number) a specific object a color etc.

Built-in questions We used one of Alice's built-in questions in the skateAround method for the cleverSkater. Let's take a look at another example.

Example A common task in sports game programs is to bounce a ball. To illustrate how this is done, let's bounce the ball over the net. (The ball has been positioned 1 meter from the net.) The ball should move up and forward and then down and forward in a pattern that looks something like this: Note: This looks easy – but do not be deceived!

Design Storyboard A design for a world-level method: To reach the top of the net, we know the ball should move forward 1 meter (we positioned the ball 1 meter in front of the net) but how far upward should the ball move to clear the net? World.ballOverNet: Do in order toyball turn to face the net Do together toyball move up toyball move forward Do together toyball move down toyball move forward

Height We can use the built-in height question to determine the height of the net and move the ball up that distance.

Demo Demonstrate program for bouncing the ball over the net.

Problem The ball does not bounce over the net. The problem is that we cannot easily tell "which way is up" – from the perspective of the ball.

Solution Actually, we are thinking "up" and "down" relative to the ground – so we can orient the ball (and also the net) with the ground. Now, when the code is run, the ball will bounce over the net.

Rolling the ball Another sports game action involves rolling a ball along the ground. We want a realistic motion rather than a slide. The ball must simultaneously move and roll.

Demo: A first attempt

Revising the approach The ball is made to roll 1 revolution. Suppose we want the ball to roll a certain distance along the ground. How can we make the ball roll the correct number of revolutions to cover a given distance along the ground?

Number of revolutions The number of revolutions depends on the size of the ball The number of revolutions is distance/( P * diameter) But there is no built-in question to return the number of revolutions We will write our own! one revolution four revolutions

Parameters We want to return the value computed as distance / (  * diameter) Obviously, what is needed is the ball’s diameter the ball object has a built-in width question the distance the ball is to travel can be sent as a parameter to the question

numberOfRevolutions Question

Demo: Calling the Question This is a test value. We should run the animation with several test values to be sure it works as expected. What happens if you use a negative value?

Levels of Questions As with methods, you can write questions as either class-level or world-level. (The question just presented was class-level.) The guidelines for class-level methods also apply to class-level questions: No references to other objects. No references to world-level questions you have written (built-in world-level questions are fine to use).

Assignment Read Chapter 6 -1, Questions Lab 6-1