CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.

Slides:



Advertisements
Similar presentations
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 2: Using Methods.
Advertisements

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.
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.
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.
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.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
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.
CS320n –Visual Programming Indefinite Loops (Slides 7-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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.
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 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.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Chapter 6: (Expressions,) Functions, and If/Else First we had animations – They “ran”/played the same way every time. – Neat, but a bit boring Then we.
CS320n –Visual Programming Introduction to Alice Mike Scott (Slides 2)
Calculator Challenge By: Chris Brown Under the direction of Professor Susan Rodger Duke University, January 2013.
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Alice: Functions Alice Chapter 6 September 19, 2005.
Shorter of two objects and changing color V2 Functions, events and setting the color in sequence and randomly This is a modification of the Changing Color.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
Alice Program Design and Implementation. Scenarios and storyboards The previous magician example illustrated a simple storyboard which depicts a scenario.
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.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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,
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.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
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.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
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.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
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.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
CS320n –Visual Programming Problem Solving Case Study (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
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.
CS320n – Elements of Visual Programming List Search Mike Scott (Slides 9-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Functions Sec 51 Web Design.
Learn about functions in Alice
Creating your Function
Functions Sec 8-11 Web Design.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
CS320n –Visual Programming
How Tall Are You? Introducing Functions
Functions Alice.
Functions.
Functions Alice.
Class-level Methods and Inheritance
Functions Alice.
Functions Alice.
Class-level Methods and Inheritance Part 2
Presentation transcript:

CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.

Visual ProgrammingFunctions2 What We Will Do Today Learn about functions in Alice Height

Visual ProgrammingFunctions3 Functionality A function –receives value(s), –performs some computation on the value(s), and –returns (sends back) a value. The values it receives or inputs are parameters like a method in some ways like asking a question and getting and answer

Visual ProgrammingFunctions4 Types of Functions Functions can be classified by the type of value they return – a calculated value (a number) – a specific object – a color – others 42

Visual ProgrammingFunctions5 Built-in Functions We used one of Alice's built-in functions in the skateAround method for the advancedSkater. asked for the distance between the advanced skater and the object, target. (In the specific example shown, target was a penguin.) Distance between center points.

Visual ProgrammingFunctions6 Another Example How do we make a realistic bouncing ball? Bounce it over a net –ball is 1 meter from net to start –ball should move forward –simultaneously ball should move up then down –parabolic motion Note: This looks easy – but do not be deceived!

Visual ProgrammingFunctions7 Design Storyboard A possible storyboard 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

Visual ProgrammingFunctions8 Height We can use the built-in height question to determine the height of the net and move the ball up that distance. Demo program. What happens?

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

Visual ProgrammingFunctions10 Solution We think “up” and “down” relative to the ground may be different for objects in the world orient ball to ground Now, when the code is run, the ball will bounce over the net.

Visual ProgrammingFunctions11 Realistic Motion Turn the camera to look at the bounce from the side. Is it realistic? The default style for motion is “gently” begin and end gently can get more realistic by –making forward motion abrupt, –up motion end gently, and –down motion begin gently

Visual ProgrammingFunctions12 Adjusting Style adjusting the style of motion makes the bounce more realistic

Visual ProgrammingFunctions13 Rolling the ball How do we create a realistic rolling action Not a slide The ball must simultaneously move and roll.

Visual ProgrammingFunctions14 Attempts at Rolling Why doesn’t this work? Will this?

Visual ProgrammingFunctions15 Revising the approach The ball is made to roll 1 revolution. What if we want the ball to roll a certain distance? A class level method for rolling, with the distance sent in as a parameter How can we make the ball roll the correct number of revolutions to cover a given distance along the ground?

Visual ProgrammingFunctions16 Math to the rescue! Number of revolutions The number of revolutions depends on the size of the ball –The number of revolutions is distance / ( Pi * diameter) But there is no built-in question to return the number of revolutions We will write our own function one revolution four revolutions Big Ball Little Ball

Visual ProgrammingFunctions17 Parameters We want to return the value computed as distance / ( Pi * diameter of ball) What information is needed? – the ball’s diameter the ball object has a built-in width function – the distance the ball is to travel can be sent as a parameter to the function

Visual ProgrammingFunctions18 Building a numberOfRevolutions function Step 1 Step 2: Drag distance parameter to replace 1 in return

Visual ProgrammingFunctions19 The numberOfRevolutions function Step 3: Select math and divide. Select other and key in 3.14

Visual ProgrammingFunctions20 The numberOfRevolutions function Step 4: Select the Pick math and 3.14 * Select 1

Visual ProgrammingFunctions21 The numberOfRevolutions function Step 5: Replace the 1 with the width of the ball from the functions

Visual ProgrammingFunctions22 Demo: Calling the Function 10 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?

Visual ProgrammingFunctions23 Creating a Roll Method Create a class level method for realistic roll problem: amount of time to roll. (Demo)

Visual ProgrammingFunctions24 Fixing Realistic roll Set duration of to function of distance. –Try 2 meters per second Fixes one problem, but what happens with negative numbers? What is result of -5 / 2? Fix, using a world level method that finds the absolute value of a number

Visual ProgrammingFunctions25 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).