Example that will be studied to help with Problem #1 on the Homework: The EVEN and the ODD turtles.
1. ca - clear all is abbreviated ca for clear all - - Any turtles created with cro or crt are destroyed and removed from the turtle GRID world. Any drawings that have been created are erased. Drawing would have been created with turtles moving about with their PD Pens Down, or pd tails dragging. 360 2. cro - cro 8 create ordered turtles and since ---------- = 45 degrees, 8 the heading or directions of the 8 turtles would be: 0 and 45 and 90 and 135 and 180 and 225 and 270 and 315 cr 36 create ordered turtles with each turtle facing 10 degrees more than the first turtle. Headings would be 0, 10, 20, 30, ... , 340, 350 degrees for the 36 turtles. 3. crt n crt 10 creates 10 turtles, but they have random headings. crt 8 creates 8 turtles, located at (0,0) the same as cro would do, but they have totally random headings. You discover the random headings or directions the turtles are facing when you do the command fd n, such as: ca crt 16 ask turtles [ fd 8 ] would show you that the turtles were facing every which way, and NOT facing a very symmetric 0, 22.5, 45, 67.5, 90, ... etc. --- Do you understand the difference between CRO and CRT now? 4. turtles - two vip facts about any turtle at any moment: position and heading -------- ------- turtles have a position (or location)... 2D = 2 dimensional space = 2D space The default position of any turtle created with cro or crt command is (0, 0), which is the very center of the GRID of patches, the very center of the turtles 2D world. turtles have a heading, or a direction that they are facing and will move in when asked to go forward with the fd command. 5. pu = pen up - pu or pen up or turtle tail up is the DEFAULT. Any turtle created by cro or crt will be DEFAULT have its pen up. pd = pen down - turtle will leave a trail or draw a line when it moves when its pen is down. 6. fd n - tells the turtle to move forward n steps or a length of n grid units. - - fd 5 moves the turtle forward 5 steps. fd 14 moves the turtle forward 14 steps or grid units. If a turtle was facing due NORTH on the grid and at center square, i.e. its position was (0,0), and we told it to move forward 5 units, with fd 5 command, where would it be? (0, 5) would be the location of the turtle. If a turtle was facing to the left, i.e. to due west on the grid, and at (0, 0) or the default start location for all turtles, and we said: fd 14 the turtles location would now be (-14, 0) bk n examples bk 3 tell to turtle to move or walk backwards or back bk 14 - - - - bk 5 3 or 14 or 5 or 12 steps. bk 12 7. rt n turn right n degrees rt = RighT examples rt 45 rt 90 rt 10 lt n turn left n degrees lt = LefT examples lt 120 lt 180 lt 14 lt 5 Note: The following two commands would result in exactly the same heading for any turtle, i.e. are two ways of a turtle obeying an about face command: rt 180 and lt 180 It just depends on whether you want the turtles to turn clockwise or to turn counterclockwise. In any case, every computer would do this SO FAST, you would not be able to tell which way the turtle turned! 8. repeat n [ what statements you want repeated n times ] repeat 4 [ fd 10 rt 90 ] draws a square with side length 10 units, if the PD pen is down with pd. You don't see the square that the turtle traced if the pu pen was up with pu instead of pd. So don't forget to put the pen down with PD when you want to DRAW some graphics with the turtles! 9. Solution to the equilateral triangle problem from class #2, Thursday, January 14th. TO triangle pd repeat 3 [ fd 10 rt 120 ] END