Sunday, 9 March 2014

logo procedures

 WHAT IS PROCEDURES:


  1. Procedures are separate "mini" programs that perform a specific task. For example a procedure TO CIRCLE will draw a circle on the screen starting at the turtle's current position. It can be used any more than once to draw the circle.
  2. Procedures are written in the procedure screen that is accessed from the Pages menu or the shortcut <Ctrl>F
  3. Procedures have the following form
      TO <name> <variables>
         --instructions
           .
           .
      END

    An Example:
       TO TRIANGLE
         REPEAT 3 [FD 100 RT 120]
       END
  4. The procedure is used by typing the name at the command screen. The results of the procedure are displayed on the graphics screen.



Example #1:

 Drawing Regular Figures

  TO PENTAGON
     REPEAT 5 [FD 30 RT 72]
     HT
  END
  Write a procedure to draw a square and show that it works by drawing it on the graphics screen.
  Write another program to draw a hexagon and show that it works by drawing it on the graphics screen.
  Write another procedure that approximates a circle and show that it works by drawing it on the graphics screen.


Example #2:

 Draw a square with lines that divide its area into four equal squares


  1. On the procedure page type in the TO Square procedure:
      TO SQUARE
         REPEAT 4 [FD 50 RT 90]
      END
  2. Copy and Draw with the following procedure SQUARE 4:
      TO SQUARE 4
         SQUARE
         BK 50
         RT 90
         FD 50
         LT 90
         FD 50
         LT 90
         FD 100
         RT 90
         FD 50
         RT 90
         FD 50
         RT 90
         FD 100
         RT 90
         FD 50
         RT 90
         FD 90
      END
  3. Copy and Draw the squares with the following procedure:
      TO SQUARE 42
         SQUARE
         RT 90
         SQUARE
         RT 90
         SQUARE
         RT 90
         SQUARE
      END
  4. Copy and Draw the squares with the following procedure:
      TO SQUARE 43
         REPEAT 4 [SQUARE RT 90]       Loop to Repeat the Square 4 times followed by RT 90 Deg
      END
  5. Notice that you have produced the same drawing with three different procedures. What procedure do you prefer? Why?



Example #3: Triangle --> Hexagons --> Snow Flakes


  1. First write a procedure to draw a triangle.
      TO TRIANGLE
         ST
         REPEAT 3 [FD 20 RT 120]
         HT
      END
  2. Next use that Triangle procedure in another procedure to draw a hexagon.
      TO HEX
         REPEAT 6 [TRIANGLE RT 60]
      END
  3. Use the HEX procedure to in the snowflake procedure.
      TO SNOWFLAKE
         REPEAT 6 [HEX FD 40 HEX BK 40 RT 60 HEX]
      END
  4. Write a similar example Curve --> Trillium --> More Trilliums

No comments:

Post a Comment