Barobo
PortalSign In
HomeShopTutorialsFree CurriculumHour of Code
RoboBlockly for Learning Math and Coding

CSP Unit 3 Lesson 8.15

Piano
Linkbot Image Mindstorm Image
0x36302418126y36302418126
Grid:
Tics Lines:
Width px
Hash Lines:
Width px
Labels:
Font px
Trace Lines:
Robot 1:
Width px
Robot 2:
Width px
Robot 3:
Width px
Robot 4:
Width px
Labels: x-axis y-axis Show Grid
Grid: 12x12 inches 24x24 inches 36x36 inches
72x72 inches 96x96 inches 192x192 inches
Quad: 4 Quadrants 1 Quadrant 1&4 Quadrants
Units: US Customary Metric
Background: Background Image

Robot 1

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (0 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 2

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (6 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 3

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (12 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 4

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (18 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in
CSP Unit 3 Lesson 8.15
/* Code generated by RoboBlockly v2.5 */
/* Problem Statement: 
    Using your code from Lesson 8.14, 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). Reset
    and Run the program multiple times to see the variety of
    results. Don't forget to save your work in an xml file
    named "YourName_Lesson8.15"!
    */
#include <chplot.h>
CPlot plot;

// Describe this function...
void drawFish(double fish_x, double fish_y, double red, double green, double blue) {
  // Draw a gold fish at the point  (fish_x,fish_y)
  plot.noStrokeColor();
  plot.fillColor(rgb2hex(red, green, blue));
  // Body of fish
  plot.ellipse(fish_x, fish_y, 8, 3, 0);
  // Tail of fish
  plot.triangle(fish_x - 5, fish_y + 2, fish_x - 5, fish_y - 2, fish_x - 3, fish_y);
}

// Describe this function...
void drawStar(double star_x, double star_y) {
  // Draw an orange star at the point (star_x, star_y)
  plot.noStrokeColor();
  plot.fillColor("#ff6600");
  plot.star(star_x, star_y, 4, 0);
}

// Describe this function...
void drawGrass(double grass_x, double grass_y, double grassWidth) {
  // Draw some grass at the point (grass_x, grass_y)
  plot.strokeColor("#33ff33");
  plot.strokeWidth(grassWidth);
  plot.arc(grass_x, grass_y, 1, 270, 90);
  plot.arc(grass_x, grass_y + 2, 1, 90, 270);
  plot.arc(grass_x, grass_y + 4, 1, 270, 90);
  plot.arc(grass_x, grass_y + 6, 1, 90, 270);
}

// Program that draws an underwater scene
// Set underwater background
//plot.backgroundImage("underwater.png");
// Turn on grid for convenience while working on code
// (When done, set grid to "off" for final display)
plot.grid(PLOT_OFF);
// Draw 2 fish, 3 stars, and 3 blades of  grass
drawFish(randint(6, 30), randint(6, 30), "C9", "00", "00");
drawFish(randint(6, 30), randint(6, 30), "77", "00", "A1");
drawStar(27, 10);
drawStar(18, 5);
drawStar(9, 6);
drawGrass(5, 5, 2);
drawGrass(8, 7, 1);
drawGrass(10, 3, 3);

plot.label(PLOT_AXIS_XY, "");
plot.grid(PLOT_OFF);
plot.tics(PLOT_AXIS_XY, PLOT_OFF);
plot.axis(PLOT_AXIS_XY, PLOT_OFF);
plot.axisRange(PLOT_AXIS_XY, 0, 36);
plot.ticsRange(PLOT_AXIS_XY, 6);
plot.sizeRatio(1);
plot.plotting();
Load Blocks
Hardware
LArduino
Workspace Show Ch Save File
Problem Statement:

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"!


		
Rubbish bin
Time