Jump to content

Coordinates system in Drawn Grid

- - - - -

  • Please log in to reply
No replies to this topic

#1
icystef

icystef

    Newbie

  • Members
  • Pip
  • 4 posts
Hello , i am encountering a new problem :s In fact i don't have an idea on how to create a coordinates system on a grid drown in tkinter with create_line() . In fact i'm not even sure if it was a good idea creating my game board with create_line() cause my coordinates arent really exact.

Part of the code :


def dessinerCercle(canv,x,y,rad,color):                                      #creer un cercle

    canv.create_oval(x-rad,y-rad,x+rad,y+rad,width=0,fill=color)

    

def creerTable(): 

    global x1, y1, x2, y2

    v=0

    h=0

    while (v < 9) :                                                        # verticales

        can1.create_line(x1,y1,x2,y2, width = 5 , fill='black')

        x1 = x1 + 70

        x2 = x2 + 70

        v = v + 1       

    while (h < 9) :                                                        #horizontales

        if( h == 0) :

            x1, y1, x2, y2 = 700, 565, -700, 565

        can1.create_line(x1,y1,x2,y2, width = 5 , fill='black')

        y1 = y1 - 70

        y2 = y2 - 70

        h = h + 1

    circ1=dessinerCercle(can1,250,250,25,'white')                  # initialisation des 4 premiers pions          

    circ2=dessinerCercle(can1,320,320,25,'white')

    circ3=dessinerCercle(can1,250,320,25,'black')

    circ4=dessinerCercle(can1,320,250,25,'black')    


As you can see i've also drown 4 circles at certain coordinates of the table created in can1. But i feel like all that wasn't done well there isn't really a coordnate system it's more 'manually placed' and i will have much problems for game mechanics . For example i want to create the function that gives you the possibility to move any of the circles in a field but how to define the exact 'coordinates' of the field in which i want to place the selected circle ? I hope you understand what i mean :D

Thanks in advance .

Stef




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users