Creating your Function

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

Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
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.
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
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.
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.
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Created by Josh Ziegler
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.
Tutorial for Arrays and Lists By Ruthie Tucker. Description This presentation will cover the basics of using Arrays and Lists in an Alice world This presentation.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Alice: Functions Alice Chapter 6 September 19, 2005.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
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.
Methods Tutorial: Part Two By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Animating Objects in Groups: Using Arrays and Lists By Ruthie Tucker under the direction of Professor Susan Rodger Summer 2008.
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.
Alice 3.0 A Guided Tour Mike R-D YRDSB. Agenda General Walkthrough of Alice 3.0 Loops, Variables, Threads Methods / Properties Arrays Misc.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
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.
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.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Use SPSS for solving the problems Lecture#21. Opening SPSS The default window will have the data editor There are two sheets in the window: 1. Data view2.
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.
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.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
Getting Started With Alice: The Basics. Step 1: Background Open up Alice, and choose a background for your Alice world. Your world is something you can.
Programming in Alice Chapter 2.
An Introduction to Alice (Short Version)
Functions Sec 51 Web Design.
Learn about functions in Alice
Teaching Characters to Walk: Learning Methods, Part 1
Functions and Expressions
Functions Sec 8-11 Web Design.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Parameters and World-level methods
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.
Checking for Collisions: Using Functions in Alice
An Introduction to Alice
Using Functions
Using Functions in Alice
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
How Tall Are You? Introducing Functions
Getting Started With Alice
Functions Alice.
Directions 1. On the Format menu, click Slide Background.
Tutorial for Arrays and Lists
Professor Susan Rodger
Headshots in Alice Duke University Professor Susan H. Rodger
Using Placeholders to Simplify your Methods: Learning Methods, Part 2
Professor Susan Rodger
Making Objects Move in Unison: Using Lists
Functions.
Functions Alice.
Functions Alice.
Functions Alice.
Presentation transcript:

Creating your Function Note to Instructor: Slides may be used either in a traditional lecture format or with an Active Learning approach. If you are using an active learning approach, suggestions will appear in this "Notes" area on appropriate slides.

What will we learn today? We will learn Functions Write your own function

Functions We use functions to ask questions about conditions/objects or to compute a value Unlike methods, functions don’t change the state of the world Alice provides a list of built-in functions that are useful in methods

Functions that don’t exist in Alice We can write our own functions Our functions may receive values sent in (input), perform computation on values and return (send back) Input value Return output Return types..Numbers, Strings and Booleans Fun

Example-Rolling a Ball Forward Simulate rolling a ball forward Think about how the ball can be made to roll along the ground Guess #1: turn instruction It simply rotates the ball in place!

Example-Rolling a Ball Forward Guess#2: to roll, the ball must turn and move in the same direction and at the same time Testing of this code is disappointing The ball ends up at the same place it started (Turn action prevents the ball from moving forward) Do together move ball forward 1 meter turn ball forward 1 revolution Why?? Because the ball is moving relative to itself and not relative to the ground

The Solution-Rolling a Ball Forward The solution is to use “asSeenBy=ground” in the move statement Do together move ball forward 1 meter asSeenBy=ground turn ball forward 1 revolution

How Many Revolutions? How many revolutions the ball needs to turn in covering a given distance in a forward direction? 1 revolution will not be realistic Challenging!! The number of revolutions is proportional to ball’s diameter (a small ball needs more turns than a big one to cover the same distance) A Big ball covers same distance in one revolution as the small ball covers in 4 revolutions

Writing a New Function Write a function for the toyball object to compute the number of revolutions needed Select the objects “toyball” in object tree In function tab, click on the “create new function” button Function box appears Enter name of function “numberOfRevolutions” and select type “number”

Writing a New Function A click on the “Ok” button creates an editor panel Create a parameter “distance” for our function Click on the “create new parameter” button at the right side of the screen A “create a new parameter” window will appear

The Return Statement Each function should have a return statement because all functions return information The return statement Cannot be removed The number of revolutions depends on distance traveled by the (circumstance) of the ball in a single revolution Drag the ‘distance’ tile from the functions header and place it in the return statement Edit the return statement as follows Number of revolutions = distance / (diameter *  ) The Return statement cannot be removed A parameter will be used to send in the distance the ball is to roll The diameter is the built-in function “toyball’s width” The symbol  (pi) is the constant 3.14

Calling the Function Now, the ball has a function called “numberOfRevolutions” This function will be used in our world Bick an arbitrary distance of 7 meters for both move forward function and turn function We should do testing to functions with small numbers (-2 to 0)

Let’s Work with Alice A Boy and a Hamster in Circus Act Create a new world as shown in the picture below, position the two objects at the top of the rolling ball Write a program for a circus act, where the boy and hamster move with the ball, staying on top of it as the ball rolls Create a method for the boy to move with the rolling ball while moving his legs back and forth gently, and putting his arms up halfway to help him balance as he moves along with the ball For an advanced work, make the 3 objects do a complete revolution while the boy and the hamster staying on top of the ball