Bar_gold.gif 401 bytes

Logo Lab #7c: Special Effects in Logo

Bar_gold.gif 401 bytes

I. Special Effects in Logo

  1. Text Boxes

    1. Where PRINT Statements Output is placed.
    2. Open by double clicking on the Text box button on the side.
    3. The PRINT statement is used to send output to the text box.
         Example: Open a text box by clicking on the button and then pointing to spot that the text box is wanted.
             At the command line type the following:

      PRINT [A New Way to do This]
      MAKE "A 0
      REPEAT 5 [PRINT :A MAKE "A :A + 1]


      Notice the output is printed in the text box.

  2. Buttons

    1. Buttons can be used to run a procedure or do a command.

    2. Place buttons on the screen with the following process:
      1. Buttons are placed on the screen by clicking on the button icon at the left of the screen.
      2. Then move the mouse to the spot where the button is to be displayed. Notice the pointer is a finger.
      3. Hold the left mouse button down and "drag" a box to the size that you want the button to be.
      4. As soon as you let up on the left mouse button a dialog box will appear. Type the command or procedure name that you want executed in the box and click on Okay to apply the button to the screen.

            Example: Setup a button to clear the graphics screen (The CG command)
        1. Click on the screen where you want the button.
        2. Move the mouse to the spot on the screen where you want the button.
        3. Hold the left mouse button down and "drag" the mouse to form a box the size you want the button to be.
        4. Release the mouse button and a dialog box will appear. Type the command CG
        5. Then click on Okay to activate the button.

            Setup another button for the CT command.
              

            Setup another button that calls a procedure.
        1. On the procedure page type the following:
             TO SQUARE
                 REPEAT 4 [FD 100 RT 90]
             END
        2. Create a button and in the dialog box type the SQUARE command.
        3. Try out the buttons to draw squares.

    3. Music

      1. The Music function will create and play musical notes.
      2. The Music function is opened by clicking on the music icon.
      3. The notes of What a Mighty God are entered and clicking on the button will play the tune.


        The output screen is shown below:


      4. Make a musical card:
        1. The card should have at least one musical element.
        2. The card should have a Text box with the text appropriate to the card.
        3. The card should have graphics that illustrate the theme of the card.
        4. The card could use animation described below.

    4. Animation using SetShape

      1. Animation can be done in several ways. The simplest way is to use the setshape command.
      2. Try the following
        • Point the turtle toward the top, left corner of the page.
        • Open the turtle's dialog box (use the ).
        • As the instruction, type: setshape "bird1 fd setshape "bird2 fd 2
        • Click on Many Times to run the instruction again and again.
        • Click OK to close the dialog box.
        • Click on the turtle, and see how it changes to a flying bird.
        • Click on the bird-turtle again to make it stop.
      3. Use setshape with a List of Shapes

        You have seen that setshape is used with the name of a shape (as in setshape "bird1). Setshape can also be used with a list of shape names. In that case, the turtle will "cycle" through the list of shapes each time it runs a fd, bk, or glide command. Try these commands in the Command Center:

            setshape [bird1 bird2]
            repeat 20 [fd 2 wait 2]
            repeat 20 [fd 10 wait 2]
            glide 100 5

    5. Simulation of racing using setshapes

      1. Create two turtles using the NEWTURTLE command to define car1 and car2.
      2. Set the shapes of the turtles using SETSHAPE.
      3. Move the turtles on the starting line.
      4. Use the TURTLESOWN command to define a variable Speed.
      5. Loop to set the speed of each car at a random value from 1 to 50.

        TO TURTLE
              RESTART
              NEWTURTLE "car1
              SETSHAPE "CAR RT 90
              ST
              NEWTURTLE "car2
              SETSHAPE "JEEP FD 50 RT 90
              ST
              TURTLESOWN "SPEED
              Repeat 500 [
                     car1, setspeed random 50
                     car2, setspeed random 50
                     EVERYONE [LAUNCH [FD SPEED ] ]
                               ]
        END

        TO RESTART
              remove "Speed
              remove "car1
              remove "car2
        END




      II. Recursion

      1. Example of recursion
        1. Type in the following Procedure

          TO SPIRAL.POLY :N :L
               ST
               FD :L RT (360 / :N)
               SPIRAL.POLY :N (:L + 3)
          END

        2. Use the procedure above with the following:

               SPIRAL.POLY 3 50
          What do you observe on the screen?

        3. How do you stop the process? <Ctrl><Break> or Edit Stop All

        4. How can the procedure be stopped?
               use an IF statement

               IF :L > 120 [STOP]
          1. Place this statement after the ST statement and rerun the procedure.
          2. Notice the difference.
          3. Change the IF statement to make the process run longer.




          Recursion is a process calling itself. You must always have a way to terminate the calling. Usually this is an IF statement.


      2. Hand in one copy of the output of the program and a listing of your procedures.




      III. Using the Random Number Generator

      1. Write a procedure number to print on the screen a random number between 1 and 100.
        1. Here is an example:

               TO NUMBER
                   MAKE "X RANDOM 100
                   PRINT :X
               END

        2. Open a text box to accept the output of this procedure.


      2. Modify this procedure to print out repeated random numbers. The user would enter the number of random numbers to produce and the computer would print out the list. Use a REPEAT loop.

      3. Again modify this procedure to count the number of random numbers 0 to 50 and the number of random numbers from 51 to 100.

             Remember: for counting set    MAKE "C 0
               then in the loop   MAKE "C :C + 1 will add to the count.
               PRINT :C will print the count on the screen.

      4. Use the procedure FLIP to simulate the flipping of coins N times:

             TO FLIP :N
                  MAKE "H 0
                  MAKE "CT 0
                  REPEAT :N [MAKE "X RANDOM 100
                        PRINT :X
                        MAKE "CT :CT + 1
                        IF :X > 50 [MAKE "H :H + 1] ]
                  PRINT [TAILS]
                  PRINT :CT - :H
                  PRINT [HEADS ]
                  PRINT :H
             END

        1. Open a text box to print the output of the procedure.

        2. Run the procedure with different number of flips and complete the following table:

          Number of FlipsNumber of HeadsNumber of Tails
          100
            
          1000
            
          10000
            
          Others
            




      Bar_gold.gif 401 bytes

                 Return to Projects Index

          This page is Copyright 2002 by J. Barry DeRoos. All Rights Reserved.
          This page may be distributed and used freely, provided that the copyright notices remain intact.
          Last Modified: Nov 19, 2002.

      Bar_gold.gif 401 bytes