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 › limit the movement of noise()
Page Index Toggle Pages: 1
limit the movement of noise() ? (Read 176 times)
limit the movement of noise() ?
Feb 13th, 2009, 4:55pm
 
Hi everyone,

I'm trying to limit the movement of noise() so my object cannot exceed some X and Y value.
I want it to move randomly and that's why i use noise().

Code:

float xoff = 0.0, yoff = 0.0, noiseScale1=0.4, noiseScale2=0.4;
float n1, n2;

void setup() {
size(200, 200);
background(0);
smooth();
fill(255);

noiseDetail(3);
}

void draw() {
background(0);
xoff += 0.01;
yoff = ((millis()/1000.0));
n1 = noise(xoff*noiseScale1) * height;
n2 = noise(yoff*noiseScale2) * height;

println("original N1 "+n1);
println("original N2 "+n2);
println();

if (n1 <= -50) {n1 += 5;}
if (n1 >= 50) {n1 -= 5;}
if (n2 <= -50) {n2 += 5;}
if (n2 >= 50) {n2 -= 5;}

println("new N1 "+n1);
println("new N2 "+n2);
println();

ellipse(n1, n2, 10, 10);
}


The problem is n1 and n2 doesn't redefine their value based on the operation from "if" operator.
Why does the original n1 and n2 doesn't change?

Thanks and have a nice day!
Jonathan
Re: limit the movement of noise() ?
Reply #1 - Feb 13th, 2009, 5:19pm
 
Your values cannot be negative.
noise() returns a value between 0.0 and 1.0.
If you want a resulting number between a and b, either use map() or the simple formula: n = a + (b - a) * n;
Re: limit the movement of noise() ?
Reply #2 - Feb 13th, 2009, 6:21pm
 
thx Philho for the fast answer!!
Page Index Toggle Pages: 1