Is perlin noise suposed to repeat itself?

I just made a little program messing arround with pixels, and it occurred to me to use 2D perlin noise to set the color of each pixel in the screen, and in doing this I noticed that there are clearly repeating patterns, when I thought that perlin noise did't do that. Is there anything that I'm missing in the code or is it just that perlin noise does actually repeat and I didn't know it?

float zOff = 0;

void setup() {
  colorMode(HSB);
  size(700, 500);
}

void draw() {
  loadPixels();
  float yOff = 0;
  for (int y = 0; y < height; y ++) {
    float xOff = 0;
    for (int x = 0; x < width; x ++) {
      int index = y * width + x;
      pixels[index] = color(map(noise(xOff, yOff, zOff), 0, 1, -50, 300), 255, 255);
      xOff += 0.15;
    }
    yOff += 0.15;
  }
  updatePixels();
  zOff += 0.01;
}

Answers

  • You are repeating xoff and yoff so, yes, noise will repeat.

    Read the reference. It is not random.

  • xOff does repeat, but always with a different value in yOff (it is set to 0 only before the for loop) so the pair of numbers in noise(xOff, yOff) never repeats.

  • Answer ✓

    ok, i can see that now i've formatted the code

    there is some periodicity, but it goes away if you reduce your increments. the javadoc says:

    "Steps of 0.005-0.03 work best for most applications, but this will differ depending on use."

    whereas yours are .15. i'd also use a different value for x and y, just in case.

  • (off topic) Oh! How did you do that??? I'm new to the forum and I just pressed the button that says code and supposed it would format itself. Also, thanks for the answers.

  • Answer ✓

    Common Questions - README: How to format code and text:

    https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    (the button generally works, but only if you use it AFTER highlighting the code. if you hit it before then you get an in-line formatter, like this which doesn't handle multiple lines)

    it's always good practice to read a forum's FAQ and / or guidelines before posting. i post the formatting instructions about 5 times a day.

Sign In or Register to comment.