Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement water #5

Open
josauder opened this issue Aug 4, 2015 · 2 comments
Open

Implement water #5

josauder opened this issue Aug 4, 2015 · 2 comments
Assignees

Comments

@josauder
Copy link
Owner

josauder commented Aug 4, 2015

No description provided.

@josauder josauder self-assigned this Aug 4, 2015
@josauder
Copy link
Owner Author

Needs to be in roadmap submodule as flooded areas have to set the population density to 0.

roadmap/config_functions before or after roadmap/config_functions/setup_heightmap would be a good place.

Before caring about a GUI we need:
A function flood which floods the heightmap when water is added at a certain height. It could look something like this:





def flood(heightmap, pos, h):
    """
    pos is a pair of indices on heightmap (position where it gets flooded)
    h is the corresponding height
    """
    flooded=np.zeros(heightmap.shape)

    stencil=np.array([
    [-1,0],
    [1,0],
    [0,1],
    [0,-1]
    ])

    front=[pos]
    while len(front)>0:
        new_front=[]
        for x in front:
            if heightmap[x]<h:
                flooded[x]=True
                new_front.extend(
                [new for new in x+stencil if not flooded[new] and not np.any(x<0) and not x[0]>heightmap.shape[0] and not x[1]>heightmap.shape[1]]
                )
        front=new_front

    return flooded

This is called every time the user wants to flood. When supplying a water image, this method has to be called until every flooded pixel was returned by flood() at least once.

@josauder
Copy link
Owner Author

We then need a function that finds bodies of land. If there is only one body of land (we have an ocean or something) then there is exactly one body of land. If we have e.g. a river seperating our land masses, then we need bridges. A draft for this function can be found in roadmap/config_functions/seperate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant