We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
You're right! I've run this tile map prototype below:
http://studio.processingtogether.com/sp/pad/export/ro.9Ql2E8JBC54LJ/latest
And moved to its most left-top corner. And realized it's the same map even when I refresh the page. 3:-O
You better issue a bug request below: 8-X
https://github.com/processing-js/processing-js/issues
Thank you for your answer GoToLoop :)
If it's a bug I guess I have to contend with less variation on JavaScript mode for now.
I'll add variation by adding random numbers to the noise parameters instead of changing the noise seed.
Thanks for the link, I've reported it there.
https://github.com/processing-js/processing-js/issues/131
Thanks for linking to the answer ^^
In case anyone also needs to randomly change noiseSeed while running the sketch, or just want it to pick a random seed each time the it is loaded as expected, that's possible using
noiseSeed();
without a paramater.