-
Notifications
You must be signed in to change notification settings - Fork 2
/
perlin.py
34 lines (27 loc) · 812 Bytes
/
perlin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from base_noise import noise_gradients
class Perlin(object):
def __init__(
self,
frequency=1.0,
lacunarity=1.0,
octaves=6,
persistance=0.5,
seed=0,
):
self.frequency = frequency
self.lacunarity = lacunarity
self.octaves = octaves
self.persistance = persistance
self.seed = seed
def value(self, x, y, z):
value, signal, persist = 0.0, 0.0, 1.0
x *= self.frequency
y *= self.frequency
z *= self.frequency
for i in xrange(self.octaves):
value += noise_gradients(x, y, z, self.seed + i) * persist
x *= self.lacunarity
y *= self.lacunarity
z *= self.lacunarity
persist *= self.persistance
return value