Noise Buffering

Hey there!

I am in a necessity to know how to create a buffer of perlin noise so that I can access that same stable noise data in different scenarios, and across different runs of the same program. In another thread someone said something about noise buffering and I will like to know what prior implementations have been done to achieve this. Thanks.

1 Like

I’d suggest creating a sketch that is just for making a csv of noise data. And then load that csv in the sketch you want to use it in.

Here’s a basic example:

Table t;

void setup() {
  t = new Table();
  t.addColumn("noise");
  
  for (int i = 0; i < 100; i++) {
    TableRow r = t.addRow();
    r.setFloat("noise", noise(i));
  }
  
  saveTable(t, "perlin-noise.csv");
  exit();
}
float[] bufferNoise;

void setup() {
  bufferNoise = loadNoise();
  println(bufferNoise);
}

float[] loadNoise() {
  Table t = loadTable("perlin-noise.csv", "header");
  float[] a = new float[t.getRowCount()];
  for (int i = 0; i < t.getRowCount(); i++) {
    TableRow r = t.getRow(i);
    a[i] = r.getFloat("noise");
  }
  return a;
}

Don’t forget to copy the csv from the first sketch into the second sketch’s data folder.

Using this method will make your sketch take up more memory and setup will run slower especially if you load a huge file but shouldn’t effect your program speed after setup.

There’s less flexibility because you can’t really save an infinite amount of noise in a buffer but you could make it a perfect loop by doing something like:

float noiseScale = 1;
int max = 100;
for (int i = 0; i < max; i++) {
  TableRow r = t.addRow();
  float theta = map(i, 0, max, 0, TWO_PI);
  r.setFloat("noise", noise(noiseScale * cos(theta), noiseScale * sin(theta)));
}
1 Like

To me it sounds, like noiseSeed() would actually do exactly what you need.

3 Likes

Definitely a much simpler solution. I was having problems with noise seed starting at the same number but then diverging (from the same seed in other runs) the farther you got from zero. This was a year or two ago. Anyways I can’t reproduce the problem now so either something change or more likely I was doing something stupid.

If you are trying to use the same (seeded) noise between Processing / p5.js / processing.py sketches with consistent results, you can also use CommonRandom. This gives cross-mode stable output from any given seed.

1 Like

It does! Thanks a bunch!