View Single Post
Old Nov 2nd, 2007, 10:20 AM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: python link picture.

You make a "grid", but don't show it. There are many way of accomplishing this. I think the easiest way to do this is, every time someone places a piece, just snap it to the closest co-ordinates, that is a multiple of the size of each piece.

E.G.
width = 20  # This is the width of each piece
height = 20 # This is the height of each piece

x = 44 # This is the x co-ordinate of where the piece was placed
y = 71 # This is the y co-ordinate of where the piece was placed

def new_round(value, multiple):
    # Some dirty math to round "value" to the closest multiple of "multiple"
    return int(round(value / float(multiple)) * multiple)

newx = new_round(x, width)  # Round x to the closest width
newy = new_round(y, height) # Round y to the closest height

By the way, just curious. How are you displaying the images? Pygame? WxPython?

Last edited by Sane; Nov 2nd, 2007 at 10:37 AM.
Sane is offline   Reply With Quote