Perlin noise problem with higher numbers

Hello i try to increase one of pos of 2D perlin noise generator and its going wrong.
Its draws lines not “clouds” as before with lower number…

Is the some MAXIMUM number of perlin noise posX and posY ?

Here is the code:

float increment = 0.005;

void setup() {
  size(640, 360);
}

void draw() {

  loadPixels();
  noiseSeed(0);

  float xoff = 0; // Start xoff at 0

  // For every x,y coordinate in a 2D space, calculate a noise value and produce a brightness value
  for (int x = 0; x < width; x++) {
    xoff += increment;   // Increment xoff 
    float yoff = 1000000;   // !!!! HERE IS THE VALUE WICH I CHANGE TO HIGHER... BUT... ITS NOT WORKING WELL... TRY IT YOUR SELF
    for (int y = 0; y < height; y++) {
      yoff += increment; // Increment yoff

      // Calculate noise and scale by 255
      float bright = noise(xoff, yoff) * 255;

      // Try using this line instead
      //float bright = random(0,255);

      // Set each pixel onscreen to a grayscale value
      pixels[x+y*width] = color(bright);
    }
  }

  updatePixels();
}

img

I suspect the problem is caused by using a very large offset with a very small increment so in your example we have

y    yoff
0   1000000.000
1   1000000.005
2   1000000.010
3   1000000.015
...

so the relative distance between

noise(xoff, 1000000.000);
noise(xoff, 1000000.005

is too small to be distinguished.

Of course I could be wrong!

2 Likes

Its not working again… its not in the number or point :frowning:

Can anybode else help me ? Iam going to make chunk random generator for my game.

Changing the value of yoff to 131070 gives the result below for me. Is it the same for you?

ps. playing around with the height of the document, it seems the ‘random point to line’ trasnfer occurs around the same y position

can not help with the problem, but can help you to play faster:

float inc = 0.005;
float xoff=0,yoff = 0; 
float yoffSet = 100000;       // !!!! HERE IS THE VALUE WICH I CHANGE TO HIGHER... BUT... ITS NOT WORKING WELL... TRY IT YOUR SELF
float speed = 1000;

void setup() {
  size(640, 360);
  println("mousewheel plus plus\n click Canvas and\n use key [i] and [y] and turn mousewheel\n key [s] multiplies action of them");
}

void draw() {
  loadPixels();
  noiseSeed(0);
  xoff = 0;                               // Start xoff at 0
  for (int x = 0; x < width; x++) {
    xoff += inc;                          // Increment xoff 
    yoff = yoffSet;                       // Start yoff at yoffSet
    for (int y = 0; y < height; y++) {
      yoff += inc;                        // Increment yoff
      pixels[x+y*width] = color(noise(xoff, yoff) * 255);
    }
  }
  updatePixels();
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();                         //println(e);
  if ( keyPressed && key == 'i' ) { 
    inc += e/speed ;
    inc = constrain(inc,0,10);
    println(" key i: inc "+inc);
  }
  if ( keyPressed && key == 'y' ) { 
    yoffSet += e*speed ;
    println(" key y: yoffSet "+yoffSet);
  }
  if ( keyPressed && key == 's' ) { 
    speed += e*100.0;
    println(" key s: speed "+speed);
  }
}

1 Like

Yes, i have very same picture

Works with lower numbers, but with highers you can see in the noise some repeating… :confused: i want it for game, like in Minecraft chunk generator, how it works here ?

Alright, took another crack at this. If you add noLoop() to the setup, set float yoff to a lower number (such as 5000), and add the following code below float bright:

println("x = " + x + "   xoff = " + xoff);
println("y = " + y + "   yoff = " + yoff);

When you run the sketch you’ll notice that the increment works for yoff, but xoff won’t get higher than 3.2000258. Perhaps the error isn’t caused by noise, but rather by how the values are saved. Did you happen to look into this already?

EDIT: Forgot to mention that if you keep yoff at 10 000 it won’t change value, just like xoff, which might explain the outcome becomes ‘lined’ (since it’s noise(3.2000258, 10000.0); at each iteration)

2 Likes

Yeah, its becouse computing numbers in ALU any sequence after the long decimal point is ignored.

This is because of the accuracy of binary numbers with a decimal point. :slight_smile:

The solution is to add a larger value to the xoff and yoff values, and then divide it to became real value and because it is more successful if you find the appropriate value to add.

Thx for everybody :heart:

There is the table with variable of tested conversion constatnts:

And here, finally is the code:

float increment = 0.03; // 0.005 - 0.03
int conversion = 500;

void setup() {
  size(640, 360);
}

void draw() {
  loadPixels();
  noiseSeed(0);
  float xoff = 0;
  for (int x = 0; x < width; x++) {
    xoff += conversion;
    float yoff = 2147483647; // Test it with maximum which can accept !!! For sure :)
    for (int y = 0; y < height; y++) {
      yoff += conversion;
      float bright = noise(xoff*increment/conversion, yoff*increment/conversion) * 255;
      pixels[x+y*width] = color(bright);
    }
  }
  updatePixels();
}
2 Likes