Using a Function with Multiple Parameters: We noted in Lesson 8.3b that the way the traceSquare function was defined required the robot to be facing in the positive x direction when the function was called. In this activity we rewrite the traceSquare function with multiple parameters in order to relax this requirement. The result is that we can use the drivexyTo function to move the robot directly to a point on the grid and include this in the traceSquare function. The key is to define the fuction with three parameters instead of just one: x and y parameters to specifiy the bottom left corner of the square, plus the usual sideLength parameter. The function moves the robot to the (x, y) point and then takes the x value and adds the value of sideLength to it in order to calculate the x position of the bottom right corner and move the robot it it. After that come the usual turnLeft and driveDistance commands to complete the square.
|
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 the pre-placed code that defines the new version of the traceSquare function, call the function three times to draw a 12x12 square with bottom left corner at the point (10.10), a 10x10 square with bottom left corner at the point (12, 12), and a 8x8 square with bottom left corner at the point (14, 14). (See the hint if you get stuck.) |
|
|
|||||||||||
|
|||||||||||