コード例 #1
0
ファイル: mMap.py プロジェクト: theMonarK/Snake2p
def creerCroix(a):
    assert type(a) is int
    xmin = a/3
    xmax = a-a/3
    ymin, ymax = xmin, xmax
    carte = []
    for i in range(a):
        carte.append([])
        for j in range(a):
            if (i<xmin and ( j<ymin or j>=ymax)) or (i>=xmax and ( j<ymin or j>=ymax)):
                carte[i].append(mCase.creer("rien"))
            else :
                carte[i].append(mCase.creer("vide"))
    
    return creerEncadrement(carte)
コード例 #2
0
ファイル: mMap.py プロジェクト: theMonarK/Snake2p
def creerRectangulaire(hauteur, largeur):
    assert type(hauteur) is int
    assert type(largeur) is int
    carte = []
    for i in range(largeur):
        carte.append([])
        for j in range(hauteur):
            carte[i].append(mCase.creer("vide"))
    return creerEncadrement(carte)
コード例 #3
0
ファイル: mMap.py プロジェクト: theMonarK/Snake2p
def creerEncadrement(carte):
    cartef = []
    for i in range(len(carte)+2):
        cartef.append([])
        for j in range(len(carte[0])+2):
            if i==0 or i==len(carte)+1 or j==0 or j==len(carte[0])+1:
                cartef[i].append(mCase.creer("rien"))
            else:
                cartef[i].append(carte[i-1][j-1])
    return cartef
コード例 #4
0
ファイル: mMap.py プロジェクト: theMonarK/Snake2p
def creerTriangulaire(x1, y1, x2, y2, x3, y3):
    assert type(x1) is int
    assert type(y1) is int
    assert type(x2) is int
    assert type(y2) is int
    assert type(x3) is int
    assert type(y3) is int
    # decalage de l'origine du repere et passage en flotants
    ox = min(x1,x2,x3)
    oy = min(y1,y2,y3)
    x1, x2, x3 = float(x1-ox),float(x2-ox),float(x3-ox)
    y1, y2, y3 = float(y1-oy),float(y2-oy),float(y3-oy)
    # tri des points selon leurs absisses
    l=[[x1,y1]]
    if x2 >= x1:
        l.append([x2,y2])
    else:
        l.insert(0,[x2,y2])
    if x3 >= x2:
        l.append([x3,y3])
    else:
        if x3 >= x1:
            l.insert(1,[x3,y3])
        else :
            l.insert(0,[x3,y3])
    x11,x22,x33 = l[0][0],l[1][0],l[2][0]#enregistrement des points triés
    y11,y22,y33 = l[0][1],l[1][1],l[2][1]
    #equations des droites :
    if (x11-x33) == 0:#droite passant par les points 11 et 33
        a11 = 10000
        b11 = x11
    else:
        a11 = (y11-y33)/(x11-x33)
        b11 = y11 - a11*x11
    if (x22-x11) == 0: #droite passant par les points 11 et 22
        a22 = 10000
        b22 = x22
    else:
        a22 = (y22-y11)/(x22-x11)
        b22 = y22 - a22*x22
    if (x33-x22) == 0: #droite passant par les points 22 et 33
        a33 = 10000
        b33 = x33
    else:
        a33 = (y33-y22)/(x33-x22)
        b33 = y33 - a33*x33
    #trois cas de triangles possibles
    #cas du triangle trop plat...
    deltaY = max(y11, y22, y33)-min(y11, y22, y33)
    deltaX = max(x11, x22, x33)-min(x11, x22, x33)
    if deltaY <=2 or deltaX<= 2 :
        return creerRectangulaire(int(max(x11,x22,x33))+3,int(max(y11,y22,y33))+3)
    else:
        #creation d'une carte rectangulaire de rien
        carte = []
        for i in range(int(max(x11,x22,x33))+1):
            carte.append([])
            for j in range(int(max(y11,y22,y33))+1):
                carte[i].append(mCase.creer("rien"))

        #cas int(y2) < int(y1(x2)
        if int(y22) < int(a11*x22+b22-1):
            for i in range(len(carte)):
                y = int(a11*i+b11)
                while y >= int(max(a22*i+b22,a33*i+b33)):
                    carte[i][y] = mCase.setCase("vide")
                    y = y-1
            cartefinie = carte
                
        #cas int(y2) > int(y1(x2)
        elif int(y22) > int(a11*x22+b22+1):
            for i in range(len(carte)):
                y = int(a11*i+b11)
                while y <= int(min(a22*i+b22,a33*i+b33)):
                    carte[i][y] = mCase.setCase("vide")
                    y = y+1
            cartefinie = carte
        #cas du triangle trop plat... (prévention des erreurs)
        else :
            cartefinie = creerRectangulaire(int(max(x11,x22,x33)),int(max(y11,y22,y33)))
    return creerEncadrement(cartefinie)