We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › noise() and noiseSeed() question
Page Index Toggle Pages: 1
noise() and noiseSeed() question (Read 630 times)
noise() and noiseSeed() question
Sep 3rd, 2008, 10:10pm
 
Hello,

So from what I understand, a noise function is a seeded random function. That is why running

for (int i = 0; i <= 100; i ++) {
 float y = noise(1.0);
 line (0, y * 100, 100, 100);
}

will produce the same y value each time the for loop runs, thereby drawing the same line repeatedly over itself, whereas

for (int i = 0; i <= 100; i ++) {  
 float y = random(1.0);          
 line (0, y * 100, 100, 100);    
}

will have a different y value each time the for loop runs, and will result in many different lines being drawn on top of each other.

I understand that adding noiseSeed() to the first program will ensure that the value of y is the same every time the program is run. What I don't understand then is what does the value of the noise() function's parameter specify?

Is it the value between 0.0 and 1.0 that corresponds to the parameter's location within the sequence of numbers generated?

Does running the function without noiseSeed() cause a sequence of numbers to be generated from an arbitrary number selected by the noise() function each time the program is run?
Re: noise() and noiseSeed() question
Reply #1 - Sep 3rd, 2008, 11:24pm
 
Good question!
Take the second example of the noise() reference page.
If you put the mouse cursor on each top corner, one then the other, you can see each corner generates a given shape, always the same while the program run (ie. if you go back to the same corner, you get the same shape).
But if you run the sketch a second time, the corners have a different shape from the first run. I suppose that's because Processing internally does a noiseSeed(<time>) or something similar.
So if you want the same (random) results on each sketch run, you have to use a defined noiseSeed value.
Re: noise() and noiseSeed() question
Reply #2 - Sep 5th, 2008, 2:26am
 
Ah cool thank you that definitely helped. I've been trying to visualize the noise() function and here's how I understand it thus far:

The noise() function is a seeded random function that returns values between 0.0 and 1.0. If this function were graphed, then the parameter in noise() would be the x position on the graph, and the value returned would be the corresponding y position. Increasing the value of x is like moving down the x axis and therefore the value returned becomes the y value at the new x position.

Am I on the right track or am I going in the wrong direction? I'm also having trouble understanding how a two-parameter noise function works. I can't figure out how the first parameter and the second parameter interact to produce a single value.
Re: noise() and noiseSeed() question
Reply #3 - Sep 5th, 2008, 5:53am
 
think of 2d noise like a foggy, granular mist on a flat 2d plane, if you look closely you'll see some parts black, and some white, with a lot of grey filling in between, these variations are values from 0 to 1.  The 2 noise() parameters of x,y are simply plotting a position on this flat plane, which returns a value between 0 and 1.  By plotting your way in one direction (x or y) you'll get a series of these 'random' values as you move in that direction through the mist.  Depending on how fast the increments of the movement is, you'll get slower or faster changing values, or visually speaking, 'scaling' the mist up to a very grainy texture, or down to a very soft and cloudy texture.
sorry if this unclear or patronising, sometimes its hard to describe something simple Wink
Re: noise() and noiseSeed() question
Reply #4 - Sep 9th, 2008, 3:34am
 
Hello,

No not at all, thank you very much; I appreciate the detailed explanations. Visualizing the noise as a grid of values between 0.0 and 1.0 really helped break through the impasse I was at. One thing I still don't understand, although it's more just curiosity, is why, in a program like this:

size(500, 500);
float xnoise = 0.0;
float ynoise = 0.0;
float inc = 0.075;

for (int y = 0; y < height; y++) {
 for (int x = 0; x < width; x ++) {
   float gray = noise(xnoise, ynoise) * 255;
   stroke(gray);
   point(x, y);
   xnoise += inc;
 }
 xnoise = 0;
 ynoise = ynoise + inc;
}

does the noise function() produce a repetitive pattern in the x direction?
Re: noise() and noiseSeed() question
Reply #5 - Sep 9th, 2008, 11:32am
 
Reference: "Steps of 0.005-0.03 work best for most applications"
You use a step of 0.075, apparently a bit big, so you probably hit a limitation of the algorithm.
Or a feature: after all, it is good to make tiled patterns!
Re: noise() and noiseSeed() question
Reply #6 - Sep 9th, 2008, 7:23pm
 
Thank you!
Page Index Toggle Pages: 1