Skip to content

Commit

Permalink
Added frequency variable to perlin noise controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
john01dav committed Dec 20, 2015
1 parent 47c774d commit 161a4a5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void init(int mapSize){
}

@Override
public double getHeightMultiplier(int x, int y){
public double getHeightMultiplier(int x, int y, int frequency){
double multiplier = 0;

for(IslandNode islandNode : islandNodes){
Expand All @@ -63,7 +63,7 @@ public double getHeightMultiplier(int x, int y){
}

@Override
public double getHeightAdder(int x, int y){
public double getHeightAdder(int x, int y, int frequency){
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ public class DefaultPerlinNoiseHeightController implements PerlinNoiseHeightCont
public void init(int mapSize){}

@Override
public double getHeightMultiplier(int x, int y){
public double getHeightMultiplier(int x, int y, int frequency){
return 1;
}

@Override
public double getHeightAdder(int x, int y){
public double getHeightAdder(int x, int y, int frequency){
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void init(int mapSize){
}

@Override
public double getHeightMultiplier(int x, int y){
public double getHeightMultiplier(int x, int y, int frequency){
if(x < 0 || x >= mapSize || y < 0 || y >= mapSize || distanceToEdge(x, y) < paddingSize){
return 0;
}else{
Expand All @@ -26,7 +26,7 @@ public double getHeightMultiplier(int x, int y){
}

@Override
public double getHeightAdder(int x, int y){
public double getHeightAdder(int x, int y, int frequency){
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public interface PerlinNoiseHeightController{

void init(int mapSize);
double getHeightMultiplier(int x, int y);
double getHeightAdder(int x, int y);
double getHeightMultiplier(int x, int y, int frequency);
double getHeightAdder(int x, int y, int frequency);

}
42 changes: 21 additions & 21 deletions src/src/john01dav/jnoise/templates/perlin/PerlinNoiseTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ private double getOctaveAt(double x, double y, int frequency, int randomNumberFu

int doubleFrequency = frequency * 2;

double v1 = noise(intX - frequency, intY - frequency, randomNumberFunctionID);
double v2 = noise(intX, intY - frequency, randomNumberFunctionID);
double v3 = noise(intX + frequency, intY - frequency, randomNumberFunctionID);
double v4 = noise(intX + doubleFrequency, intY - frequency, randomNumberFunctionID);

double v5 = noise(intX - frequency, intY, randomNumberFunctionID);
double v6 = noise(intX, intY, randomNumberFunctionID);
double v7 = noise(intX + frequency, intY, randomNumberFunctionID);
double v8 = noise(intX + doubleFrequency, intY, randomNumberFunctionID);

double v9 = noise(intX - frequency, intY + frequency, randomNumberFunctionID);
double v10 = noise(intX, intY + frequency, randomNumberFunctionID);
double v11 = noise(intX + frequency, intY + frequency, randomNumberFunctionID);
double v12 = noise(intX + doubleFrequency, intY + frequency, randomNumberFunctionID);

double v13 = noise(intX - frequency, intY + doubleFrequency, randomNumberFunctionID);
double v14 = noise(intX, intY + doubleFrequency, randomNumberFunctionID);
double v15 = noise(intX + frequency, intY + doubleFrequency, randomNumberFunctionID);
double v16 = noise(intX + doubleFrequency, intY + doubleFrequency, randomNumberFunctionID);
double v1 = noise(intX - frequency, intY - frequency, randomNumberFunctionID, frequency);
double v2 = noise(intX, intY - frequency, randomNumberFunctionID, frequency);
double v3 = noise(intX + frequency, intY - frequency, randomNumberFunctionID, frequency);
double v4 = noise(intX + doubleFrequency, intY - frequency, randomNumberFunctionID, frequency);

double v5 = noise(intX - frequency, intY, randomNumberFunctionID, frequency);
double v6 = noise(intX, intY, randomNumberFunctionID, frequency);
double v7 = noise(intX + frequency, intY, randomNumberFunctionID, frequency);
double v8 = noise(intX + doubleFrequency, intY, randomNumberFunctionID, frequency);

double v9 = noise(intX - frequency, intY + frequency, randomNumberFunctionID, frequency);
double v10 = noise(intX, intY + frequency, randomNumberFunctionID, frequency);
double v11 = noise(intX + frequency, intY + frequency, randomNumberFunctionID, frequency);
double v12 = noise(intX + doubleFrequency, intY + frequency, randomNumberFunctionID, frequency);

double v13 = noise(intX - frequency, intY + doubleFrequency, randomNumberFunctionID, frequency);
double v14 = noise(intX, intY + doubleFrequency, randomNumberFunctionID, frequency);
double v15 = noise(intX + frequency, intY + doubleFrequency, randomNumberFunctionID, frequency);
double v16 = noise(intX + doubleFrequency, intY + doubleFrequency, randomNumberFunctionID, frequency);

double i1 = interpolate(v1, v2, v3, v4, fractionalX);
double i2 = interpolate(v5, v6, v7, v8, fractionalX);
Expand All @@ -110,8 +110,8 @@ private double interpolate(double v0, double v1, double v2, double v3, double x)
return p * Math.pow(x, 3) + q * Math.pow(x, 2) + r * x + v1;
}

private double noise(int x, int y, int randomNumberFunctionID){
return (noiseFunctions[randomNumberFunctionID].noise(x, y) + heightController.getHeightAdder(x, y)) * heightController.getHeightMultiplier(x, y);
private double noise(int x, int y, int randomNumberFunctionID, int frequency){
return (noiseFunctions[randomNumberFunctionID].noise(x, y) + heightController.getHeightAdder(x, y, frequency)) * heightController.getHeightMultiplier(x, y, frequency);
}

}

0 comments on commit 161a4a5

Please sign in to comment.