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 & HelpPrograms › noisefields
Page Index Toggle Pages: 1
noisefields (Read 5116 times)
noisefields
Nov 16th, 2007, 11:59pm
 
Hi,

can anyone explain noisefields or show with some code.
how can they programed easily.
i have seen those noisefields several times, here are examples:
http://flickr.com/photos/lennyjpg/sets/72157600209693811/
http://flickr.com/photos/solaas/sets/72157600350977412/
but never seen code for them.
thx
ra
Re: noisefields
Reply #1 - Nov 27th, 2007, 11:08am
 
import processing.opengl.*;

p p[];

void setup(){
 size(screen.width,screen.height,OPENGL);
 smooth();

 p=new p[37*100];
 for(int i=0; i<p.length; i++)p[i]=new p(i/5000.0,500,500);
}

void draw(){
 fill(0,3);
 noStroke();
 rect(0,0,width,height);//fade background

 stroke(255);
 for(int i=0; i<p.length; i++) p[i].update();//render particles
}

class p {
 float id,x,y,xp,yp,s,d;

 public p(float _id,float _x,float _y) {
   id=_id;
   x=xp=_x;
   y=yp=_y;
   s=random(2,7);
 }

 void update(){

   id+=0.01;
   d=(noise(id,x/mouseY,y/mouseY)-0.5)*mouseX;

   x+=cos(radians(d))*s;
   y+=sin(radians(d))*s;

   if(x<-10) x=xp=width+10;//offscreen rewind
   if(x>width+100)x=xp=-10;
   if(y<-10) y=yp=height+10;
   if(y>height+10)y=yp=-10;

   line(xp,yp,x,y);
   xp=x;
   yp=y;
 }
}

Re: noisefields
Reply #2 - Nov 27th, 2007, 6:45pm
 
@lenny: Nice one!!!
Re: noisefields
Reply #3 - Nov 27th, 2007, 7:03pm
 
thanks kos :)
Re: noisefields
Reply #4 - Nov 28th, 2007, 10:53am
 
lenny that was a nice trick to get motion blur effect.
i still wonder why it does not work when AA is on ?!
atleast in some videocards it doesnt.
Re: noisefields
Reply #5 - Nov 28th, 2007, 11:41am
 
thanks crmx.
yes, that's a problem.

i have an old powerbook that won't do it.
even if i don't call background in every frame it clears everything....

but on pc with nvidia it works nice.
it's strange....i don't know why...
Re: noisefields
Reply #6 - Dec 1st, 2007, 11:17pm
 
Trying to understand your sketch better, and perlin noise too, I ended up with this.

Code:

p p[];
float globalZ=0;

void setup(){
size(screen.width,screen.height-140);
smooth();

p=new p[2000];
for(int i=0; i<p.length; i++) p[i]=new p(i/5000.0, 500, 500);
}

void draw(){
fill(0,10);
rect(0,0,width,height);//fade background

noStroke();
drawMap();

stroke(255);
for(int i=0; i<p.length; i++) p[i].update();//render particles

globalZ+= map(mouseX, 0,width, 0.001,0.03);
}





void drawMap(){
int step=8;
float val;

for(int i=0;i<width;i+=step){
for(int j=0;j<height;j+=step){
if (mouseY==0) val = 255; // doar la inceput
else val = noise(i/(float)mouseY,j/(float)mouseY, globalZ);

val = map(val,0,1, -50,300);

// if (val<128) val=0;
// else val=255;

fill(val);
rect(i,j,1,1);
}
}
}









void mousePressed(){
println("----------");
int rnd = round(random(2000));
p[rnd].x=mouseX;
p[rnd].y=mouseY;

}




class p {
float id,x,y,xp,yp,s,d;

public p(float _id,float _x,float _y) {
id=_id; // prima valoare a "adincimi", Z pentru noise
x=xp=_x;
y=yp=_y;
s=random(2,7); //speed
}


void update(){

id+=map(mouseX, 0,width, 0.001,0.05);
d=noise(x/(float)mouseY,y/(float)mouseY,globalZ) *360; // globalZ instead of id for continuity

x+=cos(radians(d))*s;
y+=sin(radians(d))*s;

if(x<0) x=xp=width;//offscreen rewind
if(x>width)x=xp=0;
if(y<0) y=yp=height;
if(y>height)y=yp=0;

line(xp,yp,x,y);
xp=x;
yp=y;
}
}


Re: noisefields
Reply #7 - Dec 1st, 2007, 11:22pm
 
mouseX and mouseY modify some perlin parameters
Re: noisefields
Reply #8 - Dec 2nd, 2007, 11:34am
 
the scetch is very simple, it's all about understanding perlinnoise. it's very important how many values you pass it and usually it's quite small ranges that give these organic results...
you could also interpolate between different seeds.
Re: noisefields
Reply #9 - Dec 30th, 2008, 12:55am
 
Quick question,

I've been looking this over trying to improve my understanding of perlin noise and I found one thing peculiar.
If you remove the ".0" from the constructor's "i/5000.0" the result is completely different, much less scattered. Why is the ".0" (which doesn't seem to be effecting the print-out of the id variable), have such an impact?


Code:


for(int i=0; i<p.length; i++)p[i]=new p(i/5000.0,500,500);



Thanks you lennyjpg for being generous and showing your code. It is much appreciated.

Re: noisefields
Reply #10 - Dec 30th, 2008, 1:00am
 
i/5000 = divide i by integer 5000, giving an integer result (probably 0 if i is small).
i/5000.0 = divide i by float (double in Java) 5000.0, giving a float (double) number.
Page Index Toggle Pages: 1