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

Generate from a pre-defined output image #85

Open
SKFrozenCloud opened this issue Jun 20, 2023 · 4 comments
Open

Generate from a pre-defined output image #85

SKFrozenCloud opened this issue Jun 20, 2023 · 4 comments

Comments

@SKFrozenCloud
Copy link

SKFrozenCloud commented Jun 20, 2023

Hi,

I'm trying to implement a way to give the algorithm a pre-defined output image containing fixed (already put in place) tiles (in overlap mode).

I do not understand the code very well but I have some ideas.

So on this line the output image is created:

bitmap[x + y * MX] = colors[patterns[observed[x - dx + (y - dy) * MX]][dx + dy * N]];

Is it possible to fill the observed array with our pre-defined image (before running the algorithm)?
What does the array observed do?
Another option would be to put it in inside the init or observer function.

EDIT:

My use-case is specifying an output image where the border is filled with "water" so that you can guarantee that the algorithm always generates "islands". Same goes with "rooms".

@mxgmn
Copy link
Owner

mxgmn commented Jun 22, 2023

Hi! To constrain the output, you need to:

  1. Ban all unwanted options.
  2. Call Propagate() to propagate the bans.

For an example, see how I constrain ground pixels here.

@mxgmn mxgmn closed this as completed Jun 22, 2023
@SKFrozenCloud
Copy link
Author

Could you just explain the snippet of code you linked so that I can write my own?

@mxgmn
Copy link
Owner

mxgmn commented Jun 23, 2023

Sure!

if (ground)
{
    for (int x = 0; x < MX; x++)
    {
        for (int t = 0; t < T - 1; t++) Ban(x + (MY - 1) * MX, t);
        for (int y = 0; y < MY - 1; y++) Ban(x + y * MX, T - 1);
    }
    Propagate();
}

This code executes in examples where we need to fix the ground level. That is, in examples like Skyline, Flowers and Platformer, where we see the picture from the side and not from the top. If we omit this code, the ground level could appear anywhere in the output (like in the middle of an image), or there could even be multiple ground levels. Try changing to ground="False" in samples.xml and see what happens.

Ground pattern is the last pattern in the input, so its index equals T-1.

  1. In the first interior for in the code, we ban all non-ground (that is, t != T-1) patterns from the ground level.
  2. In the second for, we ban the ground pattern from non-ground (that is, y != MY-1) levels.

And then we propagate the bans.

In your example, to generate islands, you need to ban all non-water patterns from the border of the image, and then propagate.

I guess I'll reopen the issue because this is a common question.

@mxgmn mxgmn reopened this Jun 23, 2023
@SKFrozenCloud
Copy link
Author

Thanks, now I understand.

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

No branches or pull requests

2 participants