How to "smooth" noise results

I know that noise returns a value between 0,1.

I’m looking for a way to “smooth” the noise. Maybe instead of returning
.5, .6, .3 etc.

it would return
.5, .5, .6, .6, .3, .3

basically I want to hold the noise value for a few iterations before getting a new noise value.
Is something like that possible? I’ve looked into mapping, but that doesn’t seem to smooth it, just increase the size.

I’m visualizing it like zooming in on the noise somehow.

Hi,

Look at :

to control the noise() output.

Here is an example with code :

int nbVertex = 20;
int sizeY = 300;

void setup(){
  size(500,500);
  
  noFill();
}

void draw(){
  background(0);
  
  //Noise Detail
  int lod = (int)map(mouseY, 0, height, 0, 50);
  float falloff = map(mouseX, 0, width, 0, 0.5);
  noiseDetail(lod, falloff);
  
  //Text
  text("lod = "+lod+"\nfalloff = "+falloff, 50, 50);
  
  //Drawing axis
  translate(0, height/2);
  stroke(255, 80);
  line(0, 0, width,0);
  line(width/2, -height/2, width/2, height/2);
  
  //Drawing the curve
  float xOffset = 0;
  strokeWeight(4);
  stroke(255);
  beginShape();
  for(int i=0;i<nbVertex;i++){
    curveVertex(i*(width/nbVertex), map(noise(xOffset), 0,1, -sizeY/2, sizeY/2));
    xOffset += 0.5;
  }
  endShape();
  
}

2 Likes

This looks promising. One issue though is that I am using noise in several different places, and I only want to set the noiseDetail() for one of them. I’m assuming you can only set noiseDetail once per sketch?

No there’s no limitations, you can use :

noiseDetail(5, 0.0);
println(noise(0)); //0.77517116
noiseDetail(5, 0.2);
println(noise(0)); //0.4999504 different values

You can also accomplish this with a stepping counter. Create an object with two settings: the number of steps you want to repeat (e.g. 3) and the value you want to increment by every cycle (e.g. 0.005). Now you can call it again and again, and it will give you 0.005, 0.005, 0.005, 0.01, 0.01, 0.01, 0.015, 0.015, 0.015… and you can use that as input to noise().

// 2019-05 Processing 3.4
// https://discourse.processing.org/t/how-to-smooth-noise-results/11307/5

StepCounter nc;

void setup(){
  frameRate(2);
  nc = new StepCounter(3, 0.005);
}

void draw(){
  float val = nc.value();
  println(val, ":", noise(val));
}

class StepCounter {
  int maxSteps = 0;
  int stepCount = 0;
  float stepValue = 0;
  float value = 0;
  StepCounter(int maxSteps, float stepValue){
    this.maxSteps = maxSteps;
    this.stepValue = stepValue;
    this.stepCount = 0;
  }
  float value(){
    stepCount = (stepCount+1) % maxSteps;
    if(stepCount==0){
      value += stepValue;
    }
    return value;
  }
}
1 Like