Tips & Techniques 6 Random Numbers and Random Motion Alice.

Slides:



Advertisements
Similar presentations
AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
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.
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 and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Parameters Section 8-8 Web Design. Objectives The student will: Understand what a parameter is Understand how to use a parameter in Alice Understand how.
Repetition Structures
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
While: Indefinite Loops Sec 8-14 Web Design. Objectives The student will: Understand what an Indefinite Loop is Understand how create an indefinite loop.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Introducing While loops (and random numbers too) Alice.
CS320n –Visual Programming Indefinite Loops (Slides 7-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Alice in Action with Java Chapter 5 Random Numbers.
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Execution Control with If/Else and Boolean Functions Example: Single Condition Alice.
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.
Integers: Comparing and Ordering EQ How do we compare and order rational numbers?
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Objectives: (1) To write a number in scientific notation. (2) To perform calculations with numbers written in scientific notation.
Execution Control with If/Else and Boolean Functions
Execution Control with If/Else and Boolean Questions Part 1 Alice.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Arrays and Array Visualization Alice. What is an array? An array is a collection of objects or information that is organized in a specific order. The.
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.
Random numbers in Alice 3. Create world, add character (“Red” in this example) Dragged walk tile to right onto Run method. Click on “??? “ part of Tile.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Comparing and ordering rational numbers
Writing Our Own Functions Alice. Functionality A function receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Functions Alice.
Variables and Inheritance Part 1
Programming: Simple Control Structures Part 2 – Repetition Alice.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Methods and Data Programming with Alice and Java First Edition.
Lesson 1: Comparing and Ordering Integers. Number Line  Points to the right of the zero (the origin) represent positive numbers. Points to the left of.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
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.
Examples 2 is less than 5 because … 2 lies to the left of 5 -1 is greater than -3 because … -1 lies to the right of is less than 1 because.
Programming: Simple Control Structures
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.
Repetition: Definite Loops Sec 53 Web Design. Objectives The Student will: Understand loops and why they are used Understand definitive loops Know how.
Programming: Simple Control Structures Sec 46 Web Design.
Parameters Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
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.
Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),
Integers Integers are positive whole numbers, their opposites (negatives), and zero.
Functions Sec 51 Web Design.
Programming: Simple Control Structures
Programming: Simple Control Structures
While: Indefinite Loops
Objective Compare and order fractions and decimals.
Functions Sec 8-11 Web Design.
Programming: Simple Control Structures
Class-level Methods Alice.
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Simple Control Structures
Presentation transcript:

Tips & Techniques 6 Random Numbers and Random Motion Alice

Random Numbers Random numbers are used in certain kinds of computer programs Examples: security for web applications encryption for satellite transmissions gaming programs scientific simulations In this session, we will look at examples of how to use random numbers in animations

Built-in questions Alice provides built-in questions for generating random numbers.

Example To have the penguin slide forward a random distance, we can write: The random number question returns a fractional value between 0 and 1.

Demo: A range of values You can specify a different range of values by specifying a minimum and maximum value. In this example, the random number will be a fractional value greater than 0 and less than 5.

Demo: Integers (whole numbers) To generate a random integer value (having no decimal point or digits to the right of a decimal point), select integerOnly from the more… options and make it true.

Random Motion In some animations, we want an object to move to a random location. We call this random motion. For example, the goldfish in this world is to swim in a random motion.

Six possible directions Of course, six move directions are possible forward, backward, left, right, up, down We can eliminate backward because goldfish do not swim backward. To simplify the code, we can take advantage of negative numbers. For example, this instruction actually moves the goldfish right:

Storyboard Only three move instructions are needed: up (will move down if number is negative) left (will move right if number is negative) forward (no backward motion) Two parameters (min, max) will be used to restrict the motion of the fish to a nearby location-- to look like swimming. fish.randomMotion: Parameters: min, max Do together fish move up a random number distance fish move left a random number distance fish move forward a random number distance

randomMotion The minimum distance of the move forward instruction is 0 (the goldfish always moves forward).

Demo To call the randomMotion method, the min and max values must be specified.