Tips & Techniques 6 Random Numbers and Random Motion

9
Tips & Techniques 6 Random Numbers and Random Motion Alice

description

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 - PowerPoint PPT Presentation

Transcript of Tips & Techniques 6 Random Numbers and Random Motion

Page 1: Tips & Techniques 6 Random Numbers and Random Motion

Tips & Techniques 6Random Numbers

and Random Motion

Alice

Page 2: Tips & Techniques 6 Random Numbers and Random Motion

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

Page 3: Tips & Techniques 6 Random Numbers and Random Motion

Built-in functions

Alice provides World-level built-in functions for generating random numbers.

Page 4: Tips & Techniques 6 Random Numbers and Random Motion

Demo

Ch06Lec3PenguinRandomMoves

Concepts illustrated in this example The random number function returns a floating point value between 0 and 1.

A different range of values can be obtained by using the minimum and maximum parameters.

The integer only option allows selection of either floating point or whole numbers.

Page 5: Tips & Techniques 6 Random Numbers and Random Motion

Random 3D MotionIn the previous example, the penguin moves in only one direction.

In some animations, we want an object to move to a random location in 3D. We call this random 3D motion.

For example, the goldfish in this world is to swim in a random motion, where the fish can move in any direction .

Page 6: Tips & Techniques 6 Random Numbers and Random Motion

Six possible directions

Of course, six move directions are possible forward, backward, left, right, up, down

In this example, 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:

Page 7: Tips & Techniques 6 Random Numbers and Random Motion

Storyboard

Only three move instructions are needed: up (will move down if the random number is negative)

left (will move right if random 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.

randomMotion

Parameters: min, max

Do together fish moves up a random number distance fish moves left a random number distance fish moves forward a random number distance

Page 8: Tips & Techniques 6 Random Numbers and Random Motion

Demo

Ch06Lec3GoldfishRandom3DMotionConcepts illustrated in this example

A random movement in 3D space is accomplished by three simultaneous move instructions. In this example, the minimum distance of the move forward instruction is 0 (the goldfish always moves forward). To call the randomMotion method, min and max values are sent as arguments to the parameters

Page 9: Tips & Techniques 6 Random Numbers and Random Motion

Assignment

Read Tips & Techniques 6, Random Numbers and Random Motion