procedures

'CS Rocks'

**LOGO procedures**
toc

**Objectives:** Use procedures to make other procedures**.** Make use of variables to make different shapes with the same procedure   you may use a previously defined procedure to make a new procedure. this is called code reuse and gives tremendous advantage to programmers. Example: TO SQR REPEAT 4 [FD 100 RT 90] END
 * Use procedures to make other procedures.**

TO SQR4 SETPC 5 SETW 5 REPEAT 4 [RT 90 SQR] END TO SQRV :size repeat 4 [ fd :size rt 90] END
 * Make use of variables to make different shapes with the same procedure**

In the above procedure, :size is a variable that can be given a value to make a square of any size.

__Task Set 4 (**due: Aug 16**)__ 1. make different circles and rectangles using stamping commands 2. display "LOGO is fun" on your graphic screen. change its font, and size 3. make a procedure called 'circ'. make another procedure called 'circ5' using circ that draws 5 intersecting circles 4. make a procedure called 'circv' that has a variable to draw circles of different sizes. 5. make procedures to complete the patterns on the handout. 6. save your workspace, record 'done' on the TaskCheck table.

**Fun stuff to try**
To surround.turtle cs setpc red make “n 150 repeat 130 [ stampoval :n :n make “n :n-1 wait 10 ] End **Unit 5**

**Objectives:**
**Recursion** is the process of calling a procedure within itself. In the example given below, growsquare is a procedure. This procedure is called again before end. This means you are asking the turtle to start over again from the beginning of the procedure. Turtle will stop only if the value in the variable becomes greater than 100.
 * 1) Learn a different programming construct
 * 2) Understand how animation works

TO square :side REPEAT 4 [FD :side RT 90] END

 TO growsquare :side  if :side >100 stop  square :side  growsquare :side + 5  END

 **Animation** - causing dynamic movement. <span style="font-family: 'Comic Sans MS',cursive;"> Draw, wait, erase, move, draw again >
 * 1) <span style="font-family: 'Comic Sans MS',cursive;">rt 90 HT REPEAT 25 [PD FD 20 WAIT 50 PE BK 20 FD 10] pd fd 20 ST
 * 2) <span style="font-family: 'Comic Sans MS',cursive;">cs ht repeat 25 [pd stampoval 10 10 wait 50 pe stampoval 10 10 fd 20] ST
 * 3) cs HT repeat 25[pd (stampoval 10 10 "true) wait 70 pe (stampoval 10 10 "true) fd 20] st

Task Set 5 (**due: August 20**)

 * 1) change the spacing between squares in growsquare procedure
 * 2) make a bigger pattern by changing stop value in growsquare
 * 3) animate the line in a vertical direction
 * 4) slow down animation
 * 5) make the animated dot bigger
 * 6) make the dot move diagonally and faster
 * 7) write a procedure to make two animated dots of different colors, one goes left to right and the other from right to left
 * 8) save your procedures under todays date, enter done on checklist

<span style="font-family: 'Comic Sans MS',cursive;">**Fun stuff to try**
<span style="font-family: 'Comic Sans MS',cursive;"> TO MASTERPIECE <span style="font-family: 'Comic Sans MS',cursive;"> PLAY [O4 8E 8D] <span style="font-family: 'Comic Sans MS',cursive;"> PLAY [O3 [C E G G4] G3 C4 [G B D F4] !] <span style="font-family: 'Comic Sans MS',cursive;"> PLAY [L8 [G B D F E4] F4 E4 D4 !] <span style="font-family: 'Comic Sans MS',cursive;"> PLAY [[G B D F C4] D4 E4 F4 !] <span style="font-family: 'Comic Sans MS',cursive;"> PLAY [L4 [G B D F4] 8G4 8G4 G4 [F A C C4] !] <span style="font-family: 'Comic Sans MS',cursive;"> PLAY [[C E G G4.] 8F4 E4] <span style="font-family: 'Comic Sans MS',cursive;"> PLAY [R] <span style="font-family: 'Comic Sans MS',cursive;"> END <span style="display: block; font-family: 'Comic Sans MS',cursive;">**Unit 6**

<span style="font-family: 'Comic Sans MS',cursive;">**Objectives:**

 * 1) Learn interactive controls
 * 2) move turtle with the cursor
 * 3) bouncing ball, color collision detection

capture a keypress and control the turtle. In this procedure, RC stands for read character. 'K' is a variable. TO MOVECONTROL MAKE "K RC IF :K = "W FD 100 IF :K = "Z BK 100 IF :K = "Q [PR [OVER] WAIT 30 CS STOP] MOVECONTROL END

up arrow = 193 down arrow = 194 left arrow = 195 right arrow = 196 space bar = 32

MAKE "K RC IF :K = CHAR 193 FD 50

Task Set 6 (**due: August 24**)
make modifications to the procedures that you worked on. add more control keys change colors change bouncing ball path change ball to a line that moves horizontally end to end

<span style="display: block; font-family: 'Comic Sans MS',cursive;">