Thread: DrawLine loop

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    DrawLine loop


    c. (10 points) Instead of using *s, use line segments for the plot. You must use a loop, not just draw the lines using separate drawLine() calls. No asterisks will be displayed. To draw a line, you need two points. You will have to remember the the first point's place in order to draw the line between the first and second point. Then you have to draw a line from the second to the third point.

    This is sort of a fence post problem. Set up the first point with coordinates oldX and oldY before the loop. In the loop generate newX and newY for the second point. Draw the line. Give oldX and oldY the values of newX and newY. Continue looping.

    This is what I have to do for my homework.
    This is the code I already have and it's not working.

    I'm not sure how to make it so the line loops replacing the previous coordinates.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    You forgot to post the code. Please remember to use code tags when you post the code.

    From you description, it sounds like you can do it like this:
    Code:
    oldX = newX;
    oldY = newY;
    You do have an origX and origY variable?
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348

IMN logo majestic logo threadwatch logo seochat tools logo