Defining a Function with Parameters: In this lesson we'll learn how to define a function with parameters. The goal is to define a function named "traceTriangle" that has three parameters: x, y, and sideLength, where x and y represent the coordinates of the bottom left corner of an equilateral triangle. To do so, first rename the "do something" function code block (pre-placed in the Workspace) to "traceTriangle." Then click on the small "gear" icon in the upper left corner of the function code block. A small popup window should appear like that shown on the left below. In the window, drag the "input name: x" stub to the right and insert it into the "inputs" block. Do this three times so it looks like the image shown on the right below.
Then click on the second and third "x" values in the "inputs" block and change them to y and sideLength, respectively (leave the first one as x). Finally, click the gear icon again to close the popup window. Your function definition code block should now look like this: Continue as directed in the Problem Statement.
|
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 newly defined traceTriangle function block (instructions above), add the code to it that turns off the trace, uses the drivexyTo command to move the robot to the point (x,y), turns on the trace, uses another drivexyTo command to draw the bottom side of the triangle, and then uses turnLeft and driveDistance commands to draw the other two sides of the triangle. We have pre-placed in the Workspace the drivexyTo command that draws the bottom side, so you can simply drag it into the function definition when needed. Once the function is defined, add code to the Workspace that calls it twice to draw a triangle of side length 10 and left corner at (8, 8) and a triangle of side 14 and left corner at (18, 15). |
|
|
|||||||||||
|
|||||||||||