1

So I am trying to create a randomized "cloudy" background with processing that changes over time. This is done by randomly generating a brightness for a group of pixels. Unfortunately, I can only get it to render one time and then not again. Code is below

float increment = 0.02;

void setup() {
  size(800,200);
  noLoop();
}

void draw() {
  background(0);

  // Optional: adjust noise detail here
  // noiseDetail(8,0.65f);

  loadPixels();

  float xoff = 0.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 = 0.0;   // For every xoff, start yoff at 0
    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();
}
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107

1 Answers1

1

First off, you're calling the noLoop() function, which prevents Processing from calling the draw() function 60 times per second.

But even after you get rid of that, you'll still see the same thing every frame. That's because you're passing the exact same parameters into the noise() function every frame.

So, the short answer to your question is that you need to change the parameters you pass into the noise() function over time. How you do that depends on exactly what you want to do. You could just shift the whole thing in a certain direction, or you could modify the internal offsets. There are a ton of different things you could do, but the basic answer is that you need to pass in different values each frame.

The quickest way to demonstrate what I'm talking about is to move this line out of the draw() function and to the top of the sketch:

float xoff = 0.0;

Now the offset will be preserved between frames, and you'll see the whole thing moving up. You'll have to play with it to get the exact effect you're going for.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107