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 & HelpOther Libraries › problem with SimplexNoise and PerlinNoise
Page Index Toggle Pages: 1
problem with SimplexNoise and PerlinNoise (Read 640 times)
problem with SimplexNoise and PerlinNoise
Aug 30th, 2008, 9:10pm
 
I'm having a problem running the following code. Both the simplex noise and the perlin noise throw out a Null Pointer Exception. Using Processing 148 on a intel mac os.
Anybody have any suggestions? Is this a bug?


import toxi.math.noise.*;

SimplexNoise sn;
PerlinNoise pn;
int x=0;
float NS=0.01;

void setup(){
 size(200,200);
 background(255);
 color c;
 for(int i = 0; i< width; i++){
   for(int j = 0; j< height; j++){
     //c = int(noise(i*.05,j*.05)*255);
     //c = int(sn.noise(x*NS,frameCount*NS,0)*255);
     c = int(pn.noise(x*NS,frameCount*NS,0)*255);
     stroke(c);
     point(i,j);
   }
 }
}
Re: problem with SimplexNoise and PerlinNoise
Reply #1 - Aug 31st, 2008, 12:25am
 
Okay, sorry to hear you're having problems, but there're a few things to say about this:

First off, the NullPointer exception is thrown because you don't actually create an instance of the PerlinNoise class. In the above code you only declare variables for each type, but in order to use them correctly you should have looked at the Javadocs first ;)

Also, SimplexNoise is currently implemented as static class, so declaring a variable for it is meaningless since you'd use it like this:

Code:
float val=(float)SimplexNoise.noise(x,y,z); 


For SimplexNoise, please also note that currently only the 3D version works as expected and the 2D and 4D variants have weird artifacts. This is a known issue and I'll look into it when I can...

SimplexNoise currently also still returns results as double only, so you need to cast it back into a float. And, if you'd have read the javadocs you would have seen that SimplexNoise values come in the -1...+1 range, so turning it into a grayscale pixel value needs a tiny bit more work than just multiplying with 255 (see the fixed code below)

PerlinNoise is currently the exact same implementation as in Processing and is only there for non-Processing projects (this is because all my libraries have no dependency on Processing). But for completeness here, you'll have to create an instance of the class first before using it. So you'd have to replace the line with:

Code:
PerlinNoise pn=new PerlinNoise(); 


Last but not least, judging by the reference to the "frameCount" variable in your code I assume you wanted to see this animated. However, then your code is missing the draw() function necessary...

Code:
import toxi.math.noise.*;

//SimplexNoise sn; // removed, since obsolete
PerlinNoise pn=new PerlinNoise();

int x=0;
float NS=0.01;

void setup() {
size(200,200);
background(255);
}

void draw() {
color c=0;
for(int i = 0; i< width; i++){
for(int j = 0; j< height; j++){
// built-in perlin noise
//c = int(noise(i*.05,j*.05)*255);
// simplex noise with scaling adjusted
c = int((float)SimplexNoise.noise(i*NS,frameCount*NS,j*NS)*127+128);
// perlin noise as lib
// (currently the same as built-in, but will be replaced with different algorithm soon)
//c = int(pn.noise(i*NS,frameCount*NS,j*NS)*255);
stroke(c);
point(i,j);
}
}
}


Hope that helps!
Re: problem with SimplexNoise and PerlinNoise
Reply #2 - Aug 31st, 2008, 2:07am
 
Thanks for the reply. Sorry about the code. I kind of quoted it before cleaning it up. I got your example to work in the draw() loop, but I am still having problems getting it to work in the setup(), as illustrated below:

This works:

Quote:
import toxi.math.noise.*;

float NS=0.03;

void setup() {
  size(200,200);
  background(255);
}

void draw() {
  for(int i = 0; i< width; i++){
    for(int j = 0; j< height; j++){
      // simplex noise with scaling adjusted
      color c = int((float)SimplexNoise.noise(i*NS,j*NS,0)*127+128);
      stroke(c);
      point(i,j);
    }
  }
}



but this doesn't:

Quote:
import toxi.math.noise.*;

float NS=0.01;

void setup(){
  size(200,200);
  background(255);
  for(int i = 0; i< width; i++){
    for(int j = 0; j< height; j++){
      // simplex noise with scaling adjusted
      color c = int((float)SimplexNoise.noise(i*NS,j*NS,0)*127+128);
      stroke(c);
      point(i,j);
    }
  }
}





I suspect this is more related to my lack of understanding of how static classes work within processing, but any help would be much appreciated.

Thanks.
Re: problem with SimplexNoise and PerlinNoise
Reply #3 - Aug 31st, 2008, 10:13pm
 
I don't know which error you're getting for that 2nd version, but it runs fine over here (maybe it has to do with that extra space in the word "no ise" in this line below, which you might have overlooked)

Code:
color c = int((float)SimplexNoise.no ise(i*NS,j*NS,0)*127+128); 

Re: problem with SimplexNoise and PerlinNoise
Reply #4 - Sep 1st, 2008, 7:30pm
 
I think I just figured it out...

I had called my sketch "SimplexNoise.pde" which caused a naming conflict, and the error message confused me.

Thanks for your help, though.

Re: problem with SimplexNoise and PerlinNoise
Reply #5 - Sep 8th, 2008, 12:48am
 
New problem... Seems like I see some kind of repetition in the grid points for noise areas offset from the center. Can you confirm this is not something I am doing wrong?



import toxi.math.noise.*;

float NS=0.1;

float gridOffset = 100;

void setup(){
 size(400,400);
 for(int i = 0; i< width; i++){
   for(int j = 0; j< height; j++){
     float c1 = (float)SimplexNoise.noise(i*NS+gridOffset,j*NS+gridOffset,0);
     color c = int((c1)*127.0+128.0);
     stroke(c);
     point(i,j);
   }
 }
}


Re: problem with SimplexNoise and PerlinNoise
Reply #6 - Sep 9th, 2008, 1:48am
 
Hi Thomas, thanks for letting me know also about these repeat-artefacts. I'd hoped so far the 3D version of the noise was bugfree (never tested it much so far), but upon closer (and much overdue) re-inspection of the code I figured I made a few mistakes (classic copy & paste errors) in the current version and have now hopefully fixed them all so that SimplexNoise is now fully working for 2D, 3D and 4D...

I've just released a new build of the geomutils package which you can download directly from here:
http://toxiclibs.googlecode.com/files/geomutils-0011.zip

Project home:
http://code.google.com/p/toxiclibs/

There's also a new little SimplexNoise demo in the examples folder to test it from 1D-4D...

Thanks again & hope that helps!
Re: problem with SimplexNoise and PerlinNoise
Reply #7 - Sep 9th, 2008, 2:12am
 
That fixed it. Thanks.
Page Index Toggle Pages: 1