100 likes | 287 Views
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
E N D
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 functions • Alice provides World-level built-in functions for generating random numbers.
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 minimumand maximum parameters. • The integer only option allows selection of either floating point or whole numbers.
Random 3D Motion • In 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 .
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:
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
Demo • Ch06Lec3GoldfishRandom3DMotion • Concepts 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
Assignment • Read Tips & Techniques 6, Random Numbers and Random Motion