MCPcopy Create free account
hub / github.com/arrayfire/forge / PerlinNoise

Method PerlinNoise

examples/cpu/histogram.cpp:140–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140PerlinNoise::PerlinNoise()
141{
142 std::srand((unsigned)(std::time(0)));
143
144 for(unsigned i=0; i < IMGW; i++)
145 {
146 for(unsigned j=0; j < IMGH; j++)
147 {
148 base[i][j] = std::rand()/(float)(RAND_MAX);
149 perlin[i][j] = 0;
150 }
151 }
152
153 float persistence = 0.5f;
154 float amp = 1.0f;
155 float tamp = 0.0f;
156
157 for (int octave=6; octave>=0; --octave)
158 {
159 int period = 1 << octave;
160 float freq = 1.0f / period;
161
162 for(unsigned i=0; i < IMGW; i++)
163 {
164 int si0 = (i/period) * period;
165 int si1 = (si0 + period) % IMGW;
166 float hblend = (i - si0) * freq;
167
168 for(unsigned j=0; j < IMGH; j++)
169 {
170 int sj0 = (j/period) * period;
171 int sj1 = (sj0 + period) % IMGH;
172 float vblend = (j - sj0) * freq;
173
174 float top = interp(base[si0][sj0], base[si1][sj0], hblend);
175 float bot = interp(base[si0][sj1], base[si1][sj1], hblend);
176
177 perlin[i][j] += (amp * interp(top, bot, vblend));
178 }
179 }
180 tamp += amp;
181 amp *= persistence;
182 }
183
184 for(unsigned i=0; i < IMGW; i++)
185 for(unsigned j=0; j < IMGH; j++)
186 perlin[i][j] /= tamp;
187}
188
189float PerlinNoise::noise(float u, float v)
190{

Callers

nothing calls this directly

Calls 1

interpFunction · 0.85

Tested by

no test coverage detected