Does noiseSeed work on JavaScript mode?

edited February 2016 in JavaScript Mode

I'm doing a sketch that generate patterns using noise and trigonometric equations. I change the noiseSeed when mouse is pressed, on Java mode each noiseSeed generates a different pattern.

On JavaScript mode, though, if I keep the same trigonometric equation, it will always generate the same pattern, independently of the noiseSeed.

I first thought that JavaScript doesn't allow changing noiseSeed while the sketch is running, but even setting the noiseSeed to a constant or not setting it and letting it be chosen randomly, it always generates the same pattern.

noiseSeed is documented on the Processing JS reference so I thought the pattern would change, even if noise doesn't look the same way on Java and JavaScript modes. Does anyone have an idea of why it isn't working?

Here a code example:

int hue_;
int seed;

void setup()
{
  size(600, 600);
  colorMode(HSB);

  newPattern();  
}

void draw()
{  
  showPattern(); 
}


void mousePressed()
{
  newPattern();
}

void newPattern()  
{
  hue_ = (int) (random(255));  
  seed = (int) (random(10000));  
  noiseSeed(seed);
  println(seed);
}

void showPattern()
{
  loadPixels();
    float dx = 0;
    for(int x = 0; x < width; x += 1)
    {
      float dy = 0;
      for(int y = 0; y < height; y += 1)
      {
        float bright = noise(cos(dx), cos(dy));
        bright = map(bright, 0, 1, 0, 255);
        pixels[x + y*width] = color(hue_, 127, bright);
        dy += 0.02;
      }
      dx += 0.02;
    }
  updatePixels();
}

Answers

Sign In or Register to comment.