Page 4: Boolean Expression Experiments

Unit 2, Lab 3, Page 4

On this page, you will match Boolean expressions with the pictures they help create.

  1. Talk with Your Partner Read this script carefully, discuss it with your partner, and make sure you understand why it produces this picture on the stage:
    clear
pen up
forever {
go to (random position)
if (x position < y position) {
set pen color to purple
} else {
set pen color to orange
}
make a point
}  Imagine a 45-degree line sloping upward toward the right, through the center of the stage. The area up and to the left of this line is purple; the area below and to the right is orange.

  2. Changing the Boolean expression in the if block changes the picture. Discuss why the expression (x position > 0) and (distance to apple > 100) generates this picture:

    There's an apple in the center. The entire left half of the stage is orange; so is a circle around the apple. What's left is purple.

  3. Match the Boolean expressions with the pictures. There are more expressions than pictures.

  1. x position < -100
  2. x position < 100
  3. x position + y position < 100
  4. y position > -100
  5. y position < (-100 - x position)
  6. y position < -100
  7. distance to apple > 100
  8. x position > -100
  9. y position > (100 - x position)
  10. (x position * y position) > 0
  11. (x position + y position) > -100
  12. (x position * y position) < 0
  13. y position > ((x position ^ 2) / 100)
  14. direction to apple > 135
  15. y position < 100
  16. y position > 100
  1. Stage divided in fourths by its x and y axes. Top left and bottom right are orange, top right and bottom left are purple.
  2. Narrow vertical purple bar at left side of stage, rest of stage orange.
  3. Apple at center of stage, orange circle around it, and purple everywhere else on stage.
  4. Narrow vertical orange bar at left side of stage, rest of stage purple.
  5. Stage divided in fourths by its x and y axes. Top left and bottom right are purple, top right and bottom left are orange.
  6. Narrow horizontal orange bar at top of stage, rest of stage purple.
  7. Apple at center of stage. The area around the apple on the left side between south (downward) and northwest (up and to the left) is orange.  The area between south and northwest but on the right is purple.
  8. Narrow horizontal orange bar at bottom of stage, rest of stage purple.
  9. The inside of a parabola that is touching the center of the stage and opening upward is purple. The area below the parabola is orange.
  10. Imagine a 45-degree line sloping downward left to right.  The line hits the left edge of the stage, not quite at the top corner; it hits the bottom edge of the stage about 2/3 of the way from the left.  The area below and to the left of this line is purple; the area above and to the right is orange.
  11. Narrow horizontal purple bar at top of stage, rest of stage orange.
  1. Compare answers with another pair and resolve any disagreements.

  2. On paper, sketch the pictures for the expressions you didn’t match with pictures in the previous problem (without using Snap!).

  3. Click here to load this file. Then save it to your Snap! account.

  4. Invent Boolean expressions you can plug into the dot-picture script to generate these pictures:

    1. The stage is mostly purple, except for a tall orange rectangle at the right edge, going not quite to the top (so there's purple above it).

    2. The stage is mostly orange, except for a wide purple rectangle in the top left corner, extending about 2/3 of the way to the right.

    3. Imagine a 45-degree line sloping upward left to right. The line hits the left edge of the stage almost at the bottom and hits the top edge about 2/3 of the way from left to right. The area above and to the left of this line is purple; the area below and to the right is orange.