Skip to content

Commit 08fc05d

Browse files
committed
Define NoiseMode and noiseMode(mode)
1 parent a07ecd6 commit 08fc05d

File tree

9 files changed

+71
-75
lines changed

9 files changed

+71
-75
lines changed

.mvn/extensions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<extension>
44
<groupId>io.takari.polyglot</groupId>
55
<artifactId>polyglot-ruby</artifactId>
6-
<version>0.4.5</version>
6+
<version>0.4.6</version>
77
</extension>
88
</extensions>

lib/propane/app.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ module Render
1616
java_import 'monkstone.vecmath.ShapeRender'
1717
end
1818

19+
PROCESSING = Java::MonkstoneNoise::NoiseMode::PERLIN
20+
SIMPLEX = Java::MonkstoneNoise::NoiseMode::SIMPLEX
21+
1922
# This class is the base class the user should inherit from when making
2023
# their own sketch.
2124
#

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!--
33
44
5-
DO NOT MODIFIY - GENERATED CODE
5+
DO NOT MODIFY - GENERATED CODE
66
77
88
-->

src/main/java/monkstone/noise/Noise.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,40 +42,6 @@ default float noise(float x, float y) {
4242

4343
/**
4444
* <p>
45-
* Returns the Perlin noise value at specified coordinates.Perlin noise is
46-
a random sequence generator producing a more natural ordered, harmonic
47-
succession of numbers compared to the standard <b>random()</b> function. It was invented by Ken Perlin in the 1980s and been used since in
48-
graphical applications to produce procedural textures, natural motion,
49-
shapes, terrains etc. The main difference to the
50-
<b>random()</b> function is that Perlin noise is defined in an infinite
51-
* n-dimensional space where each pair of coordinates corresponds to a fixed
52-
* semi-random value (fixed only for the lifespan of the program). The
53-
* resulting value will always be between 0.0 and 1.0. Processing can
54-
* compute 1D, 2D and 3D noise, depending on the number of coordinates
55-
* given. The noise value can be animated by moving through the noise space
56-
* as demonstrated in the example above. The 2nd and 3rd dimension can also
57-
* be interpreted as time.The actual noise is structured similar to an audio
58-
* signal, in respect to the function's use of frequencies. Similar to the
59-
* concept of harmonics in physics, perlin noise is computed over several
60-
* octaves which are added together for the final result. Another way to
61-
* adjust the character of the resulting sequence is the scale of the input
62-
* coordinates. As the function works within an infinite space the value of
63-
* the coordinates doesn't matter as such, only the distance between
64-
* successive coordinates does (eg. when using <b>noise()</b> within a
65-
* loop). As a general rule the smaller the difference between coordinates,
66-
* the smoother the resulting noise sequence will be. Steps of 0.005-0.03
67-
* work best for most applications, but this will differ depending on use.
68-
* <p>
69-
* @param x x-coordinate in noise space
70-
* @param y y-coordinate in noise space
71-
* @param z z-coordinate in noise space
72-
* @param w w-coordinate typically time
73-
* @return
74-
*/
75-
float noise(float x, float y, float z);
76-
77-
/**
78-
* <p>
7945
* Returns the Perlin noise value at specified coordinates. Perlin noise is
8046
* a random sequence generator producing a more natural ordered, harmonic
8147
* succession of numbers compared to the standard <b>random()</b> function.
@@ -106,8 +72,12 @@ default float noise(float x, float y) {
10672
* @param z z-coordinate in noise space
10773
* @return
10874
*/
75+
float noise(float x, float y, float z);
76+
10977
float noise(float x, float y, float z, float w);
11078

79+
void noiseMode(NoiseMode mode);
80+
11181
/**
11282
* Adjusts the character and level of detail produced by the Perlin noise
11383
* function.Similar to harmonics in physics, noise is computed over several

src/main/java/monkstone/noise/NoiseGenerator.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,39 @@
99
*
1010
* @author Martin Prout
1111
*/
12-
public class NoiseGenerator implements Noise{
13-
14-
private final Noise implementation;
15-
16-
public NoiseGenerator(){
12+
public class NoiseGenerator implements Noise {
13+
14+
private Noise implementation;
15+
private NoiseMode mode;
16+
17+
public NoiseGenerator() {
1718
this.implementation = new ValueNoise();
18-
19+
this.mode = NoiseMode.PERLIN;
20+
}
21+
22+
public void noiseMode(NoiseMode mode) {
23+
if (this.mode != mode && this.mode != NoiseMode.PERLIN) {
24+
this.implementation = new ValueNoise();
25+
this.mode = NoiseMode.PERLIN;
26+
}
27+
if (this.mode != mode && this.mode != NoiseMode.SIMPLEX) {
28+
this.implementation = new SimplexNoise();
29+
this.mode = NoiseMode.SIMPLEX;
30+
}
31+
}
32+
33+
public NoiseMode noiseMode(){
34+
return this.mode;
1935
}
20-
21-
public NoiseGenerator(Noise implementation){
22-
this.implementation = implementation;
23-
}
24-
36+
2537
@Override
2638
public float noise(float x, float y, float z) {
2739
return implementation.noise(x, y, z);
2840
}
29-
30-
@Override
41+
42+
@Override
3143
public float noise(float x, float y, float z, float w) {
44+
if (mode == NoiseMode.PERLIN) { return 0.5f;}
3245
return implementation.noise(x, y, z, w);
3346
}
3447

@@ -46,5 +59,5 @@ public void noiseDetail(int lod, float falloff) {
4659
public void noiseSeed(long seed) {
4760
implementation.noiseSeed(seed);
4861
}
49-
62+
5063
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package monkstone.noise;
7+
8+
/**
9+
*
10+
* @author tux
11+
*/
12+
public enum NoiseMode {
13+
SIMPLEX,
14+
PERLIN;
15+
}

src/main/java/monkstone/noise/SimplexNoise.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@ public void noiseSeed(long seed) {
443443

444444
}
445445

446+
@Override
447+
public void noiseMode(NoiseMode mode) {
448+
449+
}
450+
446451
// Inner class to speed upp gradient computations
447452
// (In Java, array access is a lot slower than member access)
448453
private static class Grad {

src/main/java/monkstone/noise/ValueNoise.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ public float noise(float x, float y, float z) {
132132
return r;
133133
}
134134

135-
135+
@Override
136+
public void noiseMode(NoiseMode mode) {
137+
138+
}
136139

137140
@Override
138141
public void noiseDetail(int lod) {
@@ -162,7 +165,6 @@ public void noiseSeed(long seed) {
162165

163166
@Override
164167
public float noise(float x, float y, float z, float w) {
165-
String message = "Use Simplex Noise for 4D noise";
166-
throw new UnsupportedOperationException(message);
168+
throw new UnsupportedOperationException("Not supported yet.");
167169
}
168170
}

src/main/java/processing/core/PApplet.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
// loadXML() error handling
4141
import javax.xml.parsers.ParserConfigurationException;
42-
import monkstone.fastmath.DegLutTables;
42+
import monkstone.noise.NoiseMode;
4343
import monkstone.noise.Noise;
4444
import org.xml.sax.SAXException;
4545

@@ -4912,9 +4912,8 @@ public final void randomSeed(long seed) {
49124912
internalRandom.setSeed(seed);
49134913
}
49144914

4915-
public void simplexNoise(boolean simplex){
4916-
Noise implement = (simplex) ? new SimplexNoise() : new ValueNoise();
4917-
noiseGenerator = new NoiseGenerator(implement);
4915+
public void noiseMode(NoiseMode mode){
4916+
noiseGenerator.noiseMode(mode);
49184917
}
49194918

49204919
/**
@@ -4932,12 +4931,13 @@ public float noise(float x, float y) {
49324931
/**
49334932
* ( begin auto-generated from noise.xml )
49344933
*
4935-
* Returns the Perlin noise value at specified coordinates.Perlin noise is
4936-
a random sequence generator producing a more natural ordered, harmonic
4937-
succession of numbers compared to the standard <b>random()</b> function. It was invented by Ken Perlin in the 1980s and been used since in
4938-
graphical applications to produce procedural textures, natural motion,
4939-
shapes, terrains etc. The main difference to the
4940-
<b>random()</b> function is that Perlin noise is defined in an infinite
4934+
* Returns the Perlin noise value at specified coordinates. Perlin noise is
4935+
* a random sequence generator producing a more natural ordered, harmonic
4936+
* succession of numbers compared to the standard <b>random()</b> function.
4937+
* It was invented by Ken Perlin in the 1980s and been used since in
4938+
* graphical applications to produce procedural textures, natural motion,
4939+
* shapes, terrains etc. The main difference to the
4940+
* <b>random()</b> function is that Perlin noise is defined in an infinite
49414941
* n-dimensional space where each pair of coordinates corresponds to a fixed
49424942
* semi-random value (fixed only for the lifespan of the program). The
49434943
* resulting value will always be between 0.0 and 1.0. Processing can
@@ -4958,7 +4958,6 @@ public float noise(float x, float y) {
49584958
*
49594959
* ( end auto-generated )
49604960
*
4961-
* @return
49624961
* @webref math:random
49634962
* @param x x-coordinate in noise space
49644963
* @param y y-coordinate in noise space
@@ -4971,17 +4970,6 @@ public float noise(float x, float y, float z) {
49714970
return noiseGenerator.noise(x, y, z);
49724971
}
49734972

4974-
/**
4975-
*
4976-
* @param x
4977-
* @param y
4978-
* @param z
4979-
* @param w
4980-
* @return
4981-
*/
4982-
public float noise(float x, float y, float z, float w) {
4983-
return noiseGenerator.noise(x, y, z, w);
4984-
}
49854973

49864974

49874975
// [toxi 040903]

0 commit comments

Comments
 (0)