Ejemplo n.º 1
0
def calculate_amount_for_pix(water_map, amount_map, pix):
    if water_map[pix[0], pix[1], 2] > 0:
        return amount_map[pix[0]][pix[1]]
    water_amount = 1
    water_map[pix[0], pix[1], 1] = 1
    for dir_no in directions.keys():
        if 0 <= pix[0] + directions[(dir_no + 4) % 8][0] < mapdimensions[0] and \
           0 <= pix[1] + directions[(dir_no + 4) % 8][1] < mapdimensions[1] and \
           water_map[
               pix[0] + directions[(dir_no + 4) % 8][0],
               pix[1] + directions[(dir_no + 4) % 8][1],
               0
           ] / 30 == dir_no:
            if water_map[
                pix[0] + directions[(dir_no + 4) % 8][0],
                pix[1] + directions[(dir_no + 4) % 8][1],
                2
            ] <= 0 and water_map[
                pix[0] + directions[(dir_no + 4) % 8][0],
                pix[1] + directions[(dir_no + 4) % 8][1],
                1
            ] == 1:
                print("Circle detected!")
                #water_amount = int(round(pow(water_amount + 30, 0.6) * slope / 3.0 - 51.3))
                amount_map[pix[0]][pix[1]] = water_amount
                if water_amount > 255:
                    water_map[pix[0], pix[1], 2] = 255
                else:
                    water_map[pix[0], pix[1], 2] = water_amount
                return water_amount
            water_amount += calculate_amount_for_pix(
                water_map,
                amount_map,
                (pix[0] + directions[(dir_no + 4) % 8][0], pix[1] + directions[(dir_no + 4) % 8][1])
            )
    #water_amount = int(round(pow(water_amount + 30, 0.6) * slope / 3.0 - 51.3))
    amount_map[pix[0]][pix[1]] = water_amount
    if water_amount > 255:
        water_map[pix[0], pix[1], 2] = 255
    else:
        water_map[pix[0], pix[1], 2] = water_amount
    return water_amount
Ejemplo n.º 2
0
def update_max_map(height_map, water_map, pix, max_height):
    jobs = [(height_map, water_map, (pix[0], pix[1]), max_height)]
    while len(jobs) > 0:
        height_map, water_map, pix, job_max_height = jobs.pop(0)
        a = directions.keys()
        for i in a:
            v = directions[i]
            max_height = job_max_height
            if 0 <= pix[0] + v[0] < mapdimensions[0] and 0 <= pix[1] + v[1] < mapdimensions[1]:
                if i != water_map[pix[0], pix[1], 0]:
                    if v[2]:
                        max_height += slope
                    else:
                        max_height += slopediag
                if height_map[pix[0] + v[0], pix[1] + v[1], 1] > max_height:
                    height_map[pix[0] + v[0], pix[1] + v[1], 1] = min(
                        max_height,
                        height_map[pix[0] + v[0], pix[1] + v[1], 1])
                    jobs.append((height_map, water_map, (pix[0] + v[0], pix[1] + v[1]), max_height))
        jobs.sort(key=get_min_height, reverse=True)
Ejemplo n.º 3
0
def update_min_map(height_map, water_map, pix, min_height):
    jobs = [(height_map, water_map, (pix[0], pix[1]), min_height)]
    while len(jobs) > 0:
        height_map, water_map, pix, job_min_height = jobs.pop(0)
        a = directions.keys()
        for i in a:
            v = directions[i]
            min_height = job_min_height
            if 0 <= pix[0] + v[0] < mapdimensions[0] and 0 <= pix[1] + v[1] < mapdimensions[1]:
                v_source = directions[water_map[pix[0]+v[0], pix[1]+v[1], 0]]
                if 0 != v[0]+v_source[0] or 0 != v[1]+v_source[1]:
                    if v[2]:
                        min_height -= slope
                    else:
                        min_height -= slopediag
                if height_map[pix[0] + v[0], pix[1] + v[1], 0] < min_height:
                    height_map[pix[0] + v[0], pix[1] + v[1], 0] = max(
                        min_height,
                        height_map[pix[0] + v[0], pix[1] + v[1], 0]
                    )
                    jobs.append((height_map, water_map, (pix[0] + v[0], pix[1] + v[1]), min_height))
        jobs.sort(key=get_min_height)