1 / 11

Tips & Techniques 6 Random Numbers and Random Motion

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

loden
Download Presentation

Tips & Techniques 6 Random Numbers and Random Motion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tips & Techniques 6Random Numbersand 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 minimumand 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.

More Related