예제 #1
0
def simulate(omgevingsmatrix, start, stop, updatesize=1):
    '''
    berkend en visuwaliseert path doormiddel van het A* algorithme
    :param omgevingsmatrix: matrix van de omgeving
    :param start: coordinaten van startpunt [x,y]
    :param stop:  coordinaten van eindpunt [x,y]
    :return:
    '''

    calculation_matrix = set.creat_matrix(
        len(omgevingsmatrix[0]), len(omgevingsmatrix)
    )  # maak matrix aan voor het opslaan van de gegevens
    step_matrix = set.creat_matrix(len(omgevingsmatrix[0]), len(
        omgevingsmatrix))  # maak matrix aan voor het opslaan van de gegeven

    pygame.init()

    # berekenen van de germenigingsvuldigingsfactor voor de breedte en hoogte van het scherm
    screen_info = pygame.display.Info()
    ver_widt = int(math.floor(screen_info.current_w / len(omgevingsmatrix[0])))
    ver_height = int(math.floor(screen_info.current_h / len(omgevingsmatrix)))

    if ver_widt < ver_height: ver_factor = ver_widt
    else: ver_factor = ver_height

    DISPLAY = pygame.display.set_mode((len(omgevingsmatrix[0]) * ver_factor,
                                       len(omgevingsmatrix) * ver_factor),
                                      FULLSCREEN | DOUBLEBUF, 32)
    pygame.event.set_allowed([QUIT, K_ESCAPE, K_TAB])

    pygame.display.set_caption("simulate A* algorithm")
    DISPLAY.fill((255, 255, 255))
    frameteller = 0
    found = False

    while True:
        try:
            #print frameteller
            keys = pygame.key.get_pressed()
            if keys[K_ESCAPE]:
                pygame.display.set_mode((len(omgevingsmatrix[0]) * ver_factor,
                                         len(omgevingsmatrix) * ver_factor))
            if keys[K_TAB]:
                pygame.display.set_mode((len(omgevingsmatrix[0]) * ver_factor,
                                         len(omgevingsmatrix) * ver_factor),
                                        FULLSCREEN | DOUBLEBUF, 32)
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()

            for x in range(0, updatesize, 1):
                if found == False:
                    frameteller = frameteller + 1
                    omgevingsmatrix, calculation_matrix, step_matrix = calculate(
                        omgevingsmatrix, calculation_matrix, step_matrix,
                        start, stop)
                    if calculation_matrix[stop[1]][stop[0]] is not 0:
                        found = True
                        pygame.display.set_mode(
                            (len(omgevingsmatrix[0]) * ver_factor,
                             len(omgevingsmatrix) * ver_factor))
                        update_screen(DISPLAY, ver_factor, omgevingsmatrix,
                                      calculation_matrix, step_matrix, start,
                                      stop)
                        printmatrix(calculation_matrix)
                        tkMessageBox._show(
                            "Found", "Endpoint found after " +
                            str(frameteller) + " iteration")
        except:
            pygame.display.set_mode((len(omgevingsmatrix[0]) * ver_factor,
                                     len(omgevingsmatrix) * ver_factor))
            tkMessageBox.showerror("Not possible to simulate")
            pygame.quit()

        update_screen(DISPLAY, ver_factor, omgevingsmatrix, calculation_matrix,
                      step_matrix, start, stop)
        pygame.display.update()
예제 #2
0
from path import set
import tkFileDialog
from datetime import datetime

filename = tkFileDialog.asksaveasfilename()

print str(filename) + '\n'

matrix = set.creat_matrix(100, 100)
filedata = ['jelle vissers', 'testmatrix', 100, 100]

# bestand openen voor schrijven
matrix_file = open(filename, 'w')

matrix_file.write("Created by  : " + filedata[0] + str('\n'))
matrix_file.write("Discription : " + filedata[1] + str('\n'))
matrix_file.write("Maked on    : " + str(datetime.now()) + str('\n'))
matrix_file.write("Version     : " + "0.1 \n")
matrix_file.write("Width       : " + str(filedata[2]) + str('\n'))
matrix_file.write("Height      : " + str(filedata[3]) + str('\n'))
matrix_file.write("\n\n")

for y in matrix:
    for x in y:
        matrix_file.write(str(x) + ",")
    matrix_file.write("\n")

matrix_file.close()