Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tips & Techniques 6 Random Numbers and Random Motion Alice.

Similar presentations


Presentation on theme: "Tips & Techniques 6 Random Numbers and Random Motion Alice."— Presentation transcript:

1 Tips & Techniques 6 Random Numbers and Random Motion Alice

2 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

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

4 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.

5 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.

6 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.

7 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.

8 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:

9 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

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

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


Download ppt "Tips & Techniques 6 Random Numbers and Random Motion Alice."

Similar presentations


Ads by Google