Iv been trying to understand noise for a very long time and I think I finally found someplace that can explain it to me. I have looked at the complex algorithms for too long, so I decided to go off the bare, English explanation of how noise is formed.
http://flafla2.github.io/2014/08/09/perlinnoise.html
https://www.youtube.com/watch?v=MJ3bvCkHJtE
These are the two sources that I used.
My problem is that the noise seems to be just an interpolation between whatever two points I give(when both points are under one) and when the points are above one, the numbers quickly grow into the trillions.
My input are things like, (.95, 02) or (10.38,39.04)
Iv tried to implement a very basic version, so it would be easy to understand. Here is my code:
package perlinNoise;
public class Perlin {
int grads[][] = {{1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
public double perlin (double x, double y) {
int unitX = (int)x & 255; // decide unit square
int unitY = (int)y & 255; // decide unit square
double relX = x-Math.floor(x); // relative x position
double relY = y-Math.floor(y); // relative y position
// bad pseudorandom gradient
int[] gradTL = grads[(unitX+unitY)%8];
int[] gradTR = grads[((unitX+1)+unitY)%8];
int[] gradBL = grads[(unitX+(unitY+1))%8];
int[] gradBR = grads[((unitX+1)+(unitY+1))%8];
// distance from edges to point, relative x and y inside the unit square
double[] vecTL = {relX,relY};
double[] vecTR = {1-relX,relY};
double[] vecBL = {relX,1-relY};
double[] vecBR = {1-relX,1-relY};
double tl = dot(gradTL,vecTL);
double tr = dot(gradTR,vecTR);
double bl = dot(gradBL,vecBL);
double br = dot(gradBR,vecBR);
double u = fade(relX);
double v = fade(relY);
double x1 = lerp(tl,tr, u);
double y1 = lerp(bl,br, u);
return lerp(x1,y1, v);
}
public double dot(int[] grad, double[] dist) {
return (grad[0]*dist[0] + grad[1]*dist[1]);
}
public double lerp(double start, double end, double rate){
return start+rate*(end-start);
}
public double fade(double t) {
return t*t*t*(t*(t*6-15)+10);
}
}
If anyone with more experience could offer some advice, it would be greatly appreciated.