In this lesson we will learn how to use random numbers to create a variety of underwater scenes. The random integer code stub looks like this (found in the Math tab menu): It generates a random integer from 1 to 100. We can use this anyplace the code uses an integer value. In this lesson we will use it in the function calls for the x and y positions of the fish, so that the fish will be drawn in random locations in the scene. To start, load your saved file from Lesson 8.14a or 8.14b. (Click on the "File" button" at the top left of the RoboBlockly window.)
|
Grid Size: S M L | Simple View: | MinView: |
|
Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
72x72 inches | 96x96 inches | 192x192 inches | ||
1x1 inches | 2x2 inches | Fraction: | ||
xy-Range: | ||||
|
||||
|
||||
Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
Units: | US Customary | Metric | Ruler: |
Labels: |
|
|
|
Font
px
|
|
Tics Lines: |
|
Width
px
|
Hash Lines: |
|
Width
px
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
|
Using your code from Lesson 8.14a (or 8.14b), use the random integer code stub in the function calls to drawFish in order to specify random values for the x and y location of the fish. Note that the grid for the underwater scene has dimensions of 36x36, i.e., the values of x and y can run from 0 to 36. So make sure to change the random integer code stub so that the it runs from 0 to 36 (or, even better, from 6 to 30, so that the drawn fish don't get cut off at the edges). Run and Reset the program multiple times to see the variety of results. Don't forget to save your work to the cloud in an xml file named "YourName_Lesson8.15"! |
|
|
|||||||||||
|
|||||||||||