Working with If Else

From Al, 6/22/16:
From Observation Notes Analysis: U2L1: "The sample circle-drawing scripts don't include a PEN DOWN… it should be changed in the curriculum."
Remember to Do Pair Programming Swaps
  1. You used Follow That Mouse Script in Unit 1 Lab 2 Programming a Sprite to Follow a Motion and you used repeat-until-(touching-Sprite)-(point-towards-Sprite) in Unit 1 Lab 3 Sprite interaction . Remember that right/control-click to duplicate a script can sometimes save you time.
    Click on one of the images below to load these scripts. Experiment with each script to figure out how it works.

    You will use what you learn about these scripts to solve the puzzles in problem 2.


    Forever, go to mouse x mouse y and if X position is less than 0 set pen color red else green forever(point-towards(mouse-pointer)-say(direction)-if(direction-less-than-90)(set-pen-color(red))else(set-pen-color(green)) If Direction less than 90 set Pen Size to 5 Else set Pen Size to 1 Forever If Direction greater than 180 and direction less than 270 S et Color Red Else Green Move 1 Turn 1 forever ((if-direction=30or60-set-pen-size-10-set-color-blue-else-size-1-color-red)-move-1-turn-1)
  2. Four puzzles: For each picture, create a script (or modify one you already have) that keeps the sprite moving in a circle drawing that picture.
  3. Puzzle 1: circle with northwest circumference red and the rest green, sprite circling clockwise Puzzle 2: Circle with southeast circumference thin and the rest thick, sprite circling clockwise Puzzle 3: Circle with southwest corner thick and the rest thin, sprite circling clockwise Puzzle 4: Circle with the southeast corner thin and the rest thick, sprite circling clockwise

  4. Create a script that lets you write on the stage in two colors, using your mouse:
    using the mouse to write 'mouse' on the stage

Conditional statements: Blocks like if else and repeat until allow your programs to perform different actions or computations depending on a condition that you specify.

repeat-until-(touching-Sprite)-(point-towards-Sprite) if ((x position) less than (0)) (set pen color to (red)) else (set pen color to (green))

Predicates: Blocks such as touching? or less than that report only trueor false are called predicates. In snap, predicates are hexagonal in shape, not oval like other reporters. The values trueand false themselves are predicates called Booleans.

Gamal: Hey, Betsy! Alphie! Delia and I did the puzzles in problem 2 using if else the way I think we were supposed to, but we also found a way to do them with repeat until and even a way without using any conditionals at all.
Betty: How did you do it without conditionals?
Delia: Like this.
Gamal begins to rebuild a script for the first puzzle: partial solution using only repeat 90
Delia: This makes the red part. You do pretty much the same thing for the green part.
Alphie and Betty: Cool!
Gamal: But we couldn't find any way to do problem 3 without if else. Do you think there is a way?
 
  1. Finish Gamal and Delia's script so that it draws the correct picture and keeps the sprite moving forever around that circle redrawing the picture.
  2. Compare a method using if else with your method that uses no conditionals. What are the advantages/disadvantages of each method?
  3. Solve at least one of the puzzles from problem 2 using repeat until.
  4. Answer Gamal's last question. Do you think there is a way to do problem 3 without if else? Share Your Work
    Explain how or why not.
  5. Try to get a behavior roughly like this.
    sprite moving in circle, alternating yellow and black like a tiger, but when it completes the circle switching which color paints which region
  6. Uncheck the "draggable" box above the scripting area before you try this. draggable check box
  7. Improve the script from problem 3 so that the sprite always follows the mouse, but draws only when the mouse button is down, so that you can draw disconnected shapes:
    bicolor printed hello