Determining the period of perlin noise

I would like to create a grid and am unsure how to go about producing the result I want.
I noticed that when creating a terrain using perlin noise, at some point if you keep travelling through the map you’ll notice that the perlin pattern repeats, and so the map repeats.

Currently I am generating the map by first using a double loop to generate the noise figures, then I apply the noise values in a second double for loop to allocate the values to grid positions.

Other than the period of noise I also have another problem. I would like make the map completely travel-able, problem is the way I’m currently coding it.

As you can see per the illustration the issue is that the tiles are changing colors when the perspective/player moves. This isnt a problem so long as I only want to do simple things with the background. For example the color will tell me if I can walk on it. But the color should also allocate a type to the particular tile so that other more interesting things can be recorded, ie a history of its state so that for example soil capacity over time can be recorded.

Apologies if this is badly worded, its still pretty confusing in my mind.

So I had two solutions, one was to make the grid the size of the perlin noise period, and then restrict what I according to the size of the grid chosen by the user. This seems simple enough, providing that I can figure out perlin’s period.

2nd alternative, record the movements of the perspective/player, in each cell as a history, then it should be possible to track back and find its initial value, although this seems probably too convoluted to be practical.

Any help would be greatly appreciated.

as always code on github.

to view grid, click file and choose grid. use arrows to move around.

the grid when zoomed out. I have circled repetitions.

2 Likes

You can avoid the repetition by decreasing the values (0.005 - 0.03 work best).

Also, if i didn‘t see that wrong, you‘re using the perspective to change the color of the tile… so if you don‘t want the color to change, you can‘t use values that would change, only fixed things, like position of the tile, not position of the viewer(perspective).

Though that‘s all i can help, cause it‘s way too much Code to look through :sweat_smile:

1 Like

Yes I noticed that reducing the values helps to reduce repetition or rather it stretches the map. The issue with this is that in fact the repition is still there but the resolution of the map is also much higher. You can confirm this by playing around with some of the sliders which have been mapped to do this and other things.

If i saw that right, you‘re using 2D Perlin noise. Try using a 3rd parameter (maybe x+y).

Also, in this example, it doesn‘t repeat itself at all :

void setup() {
   size(305,305);
}

void draw() {
   background(255);
   
   noSmooth();
   
   float a = mouseY;
   
   for (int x = 0; x < 300; x++) {
      for (int y = 0; y < 300; y++) {
         stroke(noise((x-150)/a, (y-150)/a)*255 < mouseX ? 0 : 255);
         point(x, y);
      }
   }
}
1 Like

3d has already been added, all you do to enable it is change the terrain3d variable to true in the variables tab. Thanks I shall take a look at your example.

1 Like

As a last resort, if nothing works, you could try implementing your own 4D perlinnoise (since Processing doesn‘t have one…) and use a 4th parameter (although that‘s going to decrease performance). It‘s surprisingly simple to implement :sweat_smile:

void setup() {
   size(660,660);
}

void draw() {
   background(255);
   
   noSmooth();
   
   float a = mouseY;
   
   for (int x = 0; x < 300; x++) {
      for (int y = 0; y < 300; y++) {
         stroke(noise((x-150)/a, (y-150)/a)*255 < mouseX ? 0 : 255);
         point(x, y);
      }
   }
}

on larger scales it does, amended the code.

Whilst that does solve the repetition problem, that doesn’t solve the problem I’m looking for. I’m looking for a way to keep track of information in the grid, so that a player who for examples leaves an item in a lake, or in the grass, can walk away explore the rest of the map come back and then pick up his item. Currently using the create a grid, then colour it using perlin noise method, the square to be coloured changes color every time the player moves and therefore technically becomes another location. Because of this it seems like I would have to create yet a third grid which revolves around the camera/player movement to accurately fix this issue.

@paulgoux, having to add a third grid is usually the case for 2D games with those types of mechanics. What I suggest doing, which I believe will be simple enough, is adding an ‘item’ or ‘structure’ grid “under” the colored grid. The structure grid would move in the opposite direction one unit per unit that the player walked, and still keep track of the same ‘square’ that the item is on(that being, what color and what position remain the same without having to check what color/position it was placed on). The squares for both grids would be on top of eachother, and since the coordinates for a regular grid do not have the repetition the perlin noise does, you could keep the same wordly position of each item relative to player’s starting point(or 0,0) so that the perlin repetition does not effect the position.

Sorry if that’s confusing. I’m more of a thinker than an explainer :woozy_face:

2 Likes