How to Establish Boundary Conditions for the Stylus in MicroWorld EX

By Camille McCue

MicroWorld EX’s stylus must be prevented from drawing outside the boundaries. You will write a When This Do That rule (a rule that is always running) so it can continuously check whatever its rule says to check. Here, it checks whether the turtle runs into the frame. Follow these steps to set up horizontal boundary conditions and a similar procedure for vertical boundaries:

  1. First, you need to find the x-coordinates of the left boundary between the gray drawing area and the red frame. To do so, drag the stylus turtle to where these two areas intersect on the left side of the workspace.

  2. Open the stylus backpack by right-clicking (Windows) or Ctrl-clicking (Mac) the stylus turtle and choosing Open Backpack.

  3. On the State tab, find the Xcor value.

    image0.jpg

    In the example, the Xcor value is –260, but your value may be slightly different.

  4. Switch to the Rules tab of the stylus turtle backpack.

  5. On the Rules tab, find the When This . . . Do That section, and then in the blank space below that, right-click (Windows) or Ctrl-click (Mac), and select Add from the pop-up menu.

    image1.jpg

    The User-Defined Event dialog box opens.

  6. Type xcor < -260 (or whatever value you found in Step 3) in the When field, and type bk 5 in the What field. Click OK.

    image2.jpg

    These two commands — xcor < -260 and bk5 — mean that if the user clicks the L button and the x-coordinate of the stylus is less than –260, the stylus moves backward 5 pixels. Because the L button command — seth 270 fd 5 — moves the stylus forward 5 pixels, this has the net effect of not moving the stylus at all — and it does not move left into the red frame.

  7. Click OK to close the dialog box.

  8. Repeat Steps 1–4 for the right boundary between the gray drawing area and the red frame. Be sure to check the Xcor value at this boundary.

  9. In the User-Defined Event dialog box, type xcor > 260 (or whatever xcor value you have) in the When field, and bk 5 in the What field. Click OK.

    The Rules tab of the stylus turtle backpack now looks something like the example

    image3.jpg

    If you need to edit a When This . . . Do That command, click the command to select it. Then right-click (Windows) or Ctrl-click (Mac) and select Edit from the pop-up menu. Then make your changes in the dialog box.