Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with a grid procedure
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Danjen




PostPosted: Fri Nov 24, 2006 12:14 pm   Post subject: Help with a grid procedure

I'm trying to make a customizable grid program, that lets the user input the X, Y, X size, Y size, # of lines and color, but something keeps screwing up for some odd reason and the lines won't align properly. Basically, the first for statement works okay, but then I can't determine a formula for the second for statement. Sad

code:

proc drawGrid (x, y, xsize, ysize, xrep, yrep, col : int)

    for i : 1 .. xrep
        Draw.Line (x + (i - 1) * xsize, y - (i - 1) * ysize, x + (i - 1) * xsize + (xsize * xrep), y - (i - 1) * ysize + (ysize * yrep), col)
        put "(", x + (i - 1) * xsize, ",", y - (i - 1) * ysize, ") (", x + (i - 1) * xsize + (xsize * xrep), ",", y - (i - 1) * ysize + (ysize * yrep), ")"
    end for

    for i : 1 .. yrep
        Draw.Line (x + (i - 1) * xsize, y, x + (i - 1) * xsize + (yrep * xsize), 20, 7)
    end for

end drawGrid

drawGrid (100, 100, 45, 20, 5, 4, 7)
Sponsor
Sponsor
Sponsor
sponsor
Windsurfer




PostPosted: Sat Nov 25, 2006 6:54 pm   Post subject: (No subject)

Your problem comes from having no real "grid" but rather you just have a method of drawing diagonal lines... what you need to do is make a function that draws dots on the screen in your grid fashion... then you can figure out how to draw them. Then you will always be able to have any grid line up.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: