Turtle Graphics, how does it work?

This is a discussion on Turtle Graphics, how does it work? within the C++ Programming forums, part of the General Programming Boards category; The Problem: Code: ( Turtle Graphics ) The Logo language, which is popular among elementary school children, made the concept ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    91

    Turtle Graphics, how does it work?

    The Problem:

    Code:
     ( Turtle Graphics ) The Logo language, which is popular among elementary school children, made the concept of 
    turtle graphics famous. Imagine a mechanical turtle that walks around the room under the control of a C++ program.
     The turtle holds a pen in one of two positions, up or down. While the pen is down, the turtle traces out shapes as it 
    moves; while the pen is up, the turtle moves about freely without writing anything. In this problem, you will simulate
     the operation of the turtle and create a computerized sketchpad as well.
    
    Use a 20-by-20 array floor that is initialized to zeros. Read commands from an array that contains them. Keep track
     of the current position of the turtle at all times and whether the pen is currently up or down. Assume that the turtle
     always starts at position (0, 0) of the floor with its pen up. The set of turtle commands your program must process 
    are shown in Fig. 7.33.
    
    
    Figure 7.33. Turtle graphics commands.
    
    1
     Pen up
     
    2
     Pen down
     
    3
     Turn right
     
    4
     Turn left
     
    5,10
     Move forward 10 spaces (or a number other than 10)
     
    6
     Print the 20-by-20 array
     
    9
     End of data (sentinel)
     
    
    
    
    
    Suppose that the turtle is somewhere near the center of the floor. The following "program" would draw and print a 
    12-by-12 square and end with the pen in the up position:
    
    2
    5,12
    3
    5,12
    3
    5,12
    3
    5,12
    1
    6
    9
    
    
    
    As the turtle moves with the pen down, set the appropriate elements of array floor to 1's. When the 6 command 
    (print) is given, wherever there is a 1 in the array, display an asterisk or some other character you choose. 
    Wherever there is a zero, display a blank. Write a program to implement the turtle graphics capabilities discussed 
    here. Write several turtle graphics programs to draw interesting shapes. Add other commands to increase the 
    power of your turtle graphics language.
    I have no idea how it will work. Is it like snake, but instead you have to draw? Or you just have to type the coordinate like in a graph? I just cant visualize it
    Last edited by freddyvorhees; 10-03-2008 at 08:15 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Um.

    It's a turtle, you see, holding a pen. You give commands to the turtle and the turtle obeys them. The commands are basically start drawing, stop drawing, turn, and walk. And ... well, that's it.

    Your job is keep track of (1) where the turtle is (2) which direction it's facing (3) what's been drawn on the floor.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    91
    So while using it you cant see what you are drawing until you press 6?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well -- using your system as designed for this assignment, yes. (If I recall the original correctly, you could see what was going on the whole time there, but that's not really relevant to the discussion.)

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    91
    Whats the "pen up"-"pen down" for if you just have to enter the coordinates?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Because nowhere do you enter any coordinates. The only coordinate-type thing is "how far to walk" (if the command is 5).

  7. #7
    Registered User
    Join Date
    Jul 2008
    Posts
    91
    Nice. Thank you very much

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    91
    One more question. You can't undo what you've drawn right?

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That would probably fall under the heading of
    Add other commands to increase the power of your turtle graphics language.

  10. #10
    Registered User
    Join Date
    Aug 2009
    Posts
    1
    Thanks for the suggestion, I wish it had worked.


    taux demande pret personnel en ligne credit simulation Faire un pret immobilier en ligne avec un bon credittaux demande pret personnel en ligne credit simulation

  11. #11
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    By the way, what is this program useful for?

    I don't get it why in almost graphics, scripting, GUI or game engine there is turtle graphics.
    Just GET it OFF out my mind!!

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by redsunlee View Post
    Thanks for the suggestion, I wish it had worked.

    So do I. But good job hiding the links to French credit something-or-others! Well done!
    Quote Originally Posted by audinue View Post
    By the way, what is this program useful for?

    I don't get it why in almost graphics, scripting, GUI or game engine there is turtle graphics.
    Turtle graphics is used to teach people things. It's used to teach 10-year-olds about Cartesian coordinates and the like, and 20-year-olds about how to follow directions.

  13. #13
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    How do they teach cartesian coordinates from fourth quadrant??

    How the hell it can teach people to follow directions??

    Code:
    currdir = turtle.dir

    Code:
    queue.push(turtle.dir)
    ???
    Just GET it OFF out my mind!!

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by audinue View Post
    How do they teach cartesian coordinates from fourth quadrant??
    I don't know what you mean here.
    Quote Originally Posted by audinue View Post
    How the hell it can teach people to follow directions??
    The point of the learning exercise, for the 20-year-olds, is to figure out how to make the system work -- i.e., given a list, or file, or etc., with instructions in it, they need to write a system to parse the instructions and (yes) follow directions. That was, after all, the assignment that was posted in this thread.

  15. #15
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Quote Originally Posted by tabstop View Post
    I don't know what you mean here.
    I think cartesian coordinates may start with (0, 0). To move left and top by 1 px it's (1, 1).

    While in array it's (1, -1).
    Just GET it OFF out my mind!!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Handling mouse in graphics mode in Turbo C/DOS
    By sureshkumarct in forum C Programming
    Replies: 2
    Last Post: 12-24-2006, 08:36 AM
  2. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  3. information on vector graphics
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-28-2003, 12:54 PM
  4. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 10:05 AM
  5. visual c graphics
    By aristotle1 in forum C Programming
    Replies: 1
    Last Post: 11-16-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21