propane 3.8.0-java → 3.9.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,170 +0,0 @@
1
- package monkstone.noise;
2
- import java.util.Random;
3
- import monkstone.fastmath.DegLutTables;
4
- import processing.core.PConstants;
5
-
6
- public class ValueNoise implements Noise {
7
-
8
- //////////////////////////////////////////////////////////////
9
- // PROCESSING NOISE, rewritten by cfloutier to change the way cosinus is computed
10
- // [toxi 040903]
11
- // octaves and amplitude amount per octave are now user controlled
12
- // via the noiseDetail() function.
13
- // [toxi 030902]
14
- // cleaned up code and now using bagel's cosine table to speed up
15
- // [toxi 030901]
16
- // implementation by the german demo group farbrausch
17
- // as used in their demo "art": http://www.farb-rausch.de/fr010src.zip
18
- static final int PERLIN_YWRAPB = 4;
19
- static final int PERLIN_YWRAP = 1 << PERLIN_YWRAPB;
20
- static final int PERLIN_ZWRAPB = 8;
21
- static final int PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB;
22
- static final int PERLIN_SIZE = 4095;
23
-
24
- int perlin_octaves = 4; // default to medium smooth
25
- float perlin_amp_falloff = 0.5f; // 50% reduction/octave
26
- int perlin_PI;
27
- static final int PERLIN_TWOPI = 65536;
28
-
29
- //float[] perlin_cosTable;
30
- float[] perlin;
31
-
32
- Random perlinRandom;
33
-
34
- @Override
35
- public float noise(float x) {
36
- return noise(x, 0f, 0f);
37
- }
38
-
39
- @Override
40
- public float noise(float x, float y) {
41
- return noise(x, y, 0f);
42
- }
43
-
44
- private float noise_fsc(float i) {
45
- float cosvalue = DegLutTables.cos(i * PConstants.PI);
46
- return 0.5f * (1.0f - cosvalue);
47
- }
48
-
49
- /**
50
- *
51
- * @param x
52
- * @param y
53
- * @param z
54
- * @return
55
- */
56
- @Override
57
- public float noise(float x, float y, float z) {
58
- if (perlin == null) {
59
- if (perlinRandom == null) {
60
- perlinRandom = new Random();
61
- }
62
- perlin = new float[PERLIN_SIZE + 1];
63
- for (int i = 0; i < PERLIN_SIZE + 1; i++) {
64
- perlin[i] = perlinRandom.nextFloat();
65
- }
66
- }
67
-
68
- if (x < 0) {
69
- x = -x;
70
- }
71
- if (y < 0) {
72
- y = -y;
73
- }
74
- if (z < 0) {
75
- z = -z;
76
- }
77
-
78
- int xi = (int) x, yi = (int) y, zi = (int) z;
79
- float xf = x - xi;
80
- float yf = y - yi;
81
- float zf = z - zi;
82
- float rxf, ryf;
83
-
84
- float r = 0;
85
- float ampl = 0.5f;
86
-
87
- float n1, n2, n3;
88
-
89
- for (int i = 0; i < perlin_octaves; i++) {
90
- int of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB);
91
-
92
- rxf = noise_fsc(xf);
93
- ryf = noise_fsc(yf);
94
-
95
- n1 = perlin[of & PERLIN_SIZE];
96
- n1 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n1);
97
- n2 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
98
- n2 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n2);
99
- n1 += ryf * (n2 - n1);
100
-
101
- of += PERLIN_ZWRAP;
102
- n2 = perlin[of & PERLIN_SIZE];
103
- n2 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n2);
104
- n3 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE];
105
- n3 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n3);
106
- n2 += ryf * (n3 - n2);
107
-
108
- n1 += noise_fsc(zf) * (n2 - n1);
109
-
110
- r += n1 * ampl;
111
- ampl *= perlin_amp_falloff;
112
- xi <<= 1;
113
- xf *= 2;
114
- yi <<= 1;
115
- yf *= 2;
116
- zi <<= 1;
117
- zf *= 2;
118
-
119
- if (xf >= 1.0f) {
120
- xi++;
121
- xf--;
122
- }
123
- if (yf >= 1.0f) {
124
- yi++;
125
- yf--;
126
- }
127
- if (zf >= 1.0f) {
128
- zi++;
129
- zf--;
130
- }
131
- }
132
- return r;
133
- }
134
-
135
- @Override
136
- public void noiseMode(NoiseMode mode) {
137
-
138
- }
139
-
140
- @Override
141
- public void noiseDetail(int lod) {
142
- if (lod > 0) {
143
- perlin_octaves = lod;
144
- }
145
- }
146
-
147
- @Override
148
- public void noiseDetail(int lod, float falloff) {
149
- if (lod > 0) {
150
- perlin_octaves = lod;
151
- }
152
- if (falloff > 0) {
153
- perlin_amp_falloff = falloff;
154
- }
155
- }
156
-
157
- @Override
158
- public void noiseSeed(long seed) {
159
- if (perlinRandom == null) {
160
- perlinRandom = new Random();
161
- }
162
- perlinRandom.setSeed(seed);
163
- perlin = null;
164
- }
165
-
166
- @Override
167
- public float noise(float x, float y, float z, float w) {
168
- throw new UnsupportedOperationException("Not supported yet.");
169
- }
170
- }