diff --git a/examples/1D_image.py b/examples/1D_image.py index ae1d6c1..befaa15 100644 --- a/examples/1D_image.py +++ b/examples/1D_image.py @@ -5,8 +5,8 @@ pn = PerlinNoise(num_octaves=7, persistence=0.1) data = [] -t = [i for i in xrange(length)] -for i in xrange(length): +t = [i for i in range(length)] +for i in range(length): data.append(normalize(pn.fractal(x=i, hgrid=length))) fig = plt.figure() diff --git a/examples/fbm_image.py b/examples/fbm_image.py index 96ef6c2..34c9723 100644 --- a/examples/fbm_image.py +++ b/examples/fbm_image.py @@ -6,13 +6,13 @@ sn = SimplexNoise(num_octaves=7, persistence=0.1, dimensions=2) data = [] -for i in xrange(size): +for i in range(size): data.append([]) - for j in xrange(size): + for j in range(size): noise = normalize(sn.fractal(i, j, hgrid=size)) data[i].append(noise * 255.0) # Cast to numpy array so we can save data = np.array(data).astype(np.uint8) img = Image.fromarray(data, mode='L') -img.save('./fbm_example.png') \ No newline at end of file +img.save('./fbm_example.png') diff --git a/examples/noise_image.py b/examples/noise_image.py index 42af2c0..d23f7eb 100644 --- a/examples/noise_image.py +++ b/examples/noise_image.py @@ -7,13 +7,13 @@ sn = SimplexNoise(num_octaves=7, persistence=0.1, dimensions=2, noise_scale=noise_scale) data = [] -for i in xrange(size): +for i in range(size): data.append([]) - for j in xrange(size): + for j in range(size): noise = normalize(sn.noise(i, j)) data[i].append(noise * 255.0) # Cast to numpy array so we can save data = np.array(data).astype(np.uint8) img = Image.fromarray(data, mode='L') -img.save('./noise_example.png') \ No newline at end of file +img.save('./noise_example.png') diff --git a/simplexnoise/noise.py b/simplexnoise/noise.py index 11dc89d..43a4ecd 100644 --- a/simplexnoise/noise.py +++ b/simplexnoise/noise.py @@ -1,7 +1,7 @@ from __future__ import division import math import random -from geometry import Point +from .geometry import Point # Constants to avoid magic numbers DEFAULT_NOISE_SCALE = -1 # Check noise_scale against this @@ -41,17 +41,17 @@ def __init__(self, num_octaves, persistence, noise_scale=DEFAULT_NOISE_SCALE): else: self.noise_scale = noise_scale - self.octaves = [PerlinNoiseOctave() for i in xrange(self.num_octaves)] - self.frequencies = [1.0 / pow(2, i) for i in xrange(self.num_octaves)] + self.octaves = [PerlinNoiseOctave() for i in range(self.num_octaves)] + self.frequencies = [1.0 / pow(2, i) for i in range(self.num_octaves)] self.amplitudes = [pow(persistence, len(self.octaves) - i) - for i in xrange(self.num_octaves)] + for i in range(self.num_octaves)] def noise(self, x): noise = [ self.octaves[i].noise( xin=x * self.frequencies[i], noise_scale=self.noise_scale - ) * self.amplitudes[i] for i in xrange(self.num_octaves)] + ) * self.amplitudes[i] for i in range(self.num_octaves)] return sum(noise) @@ -61,7 +61,7 @@ def fractal(self, x, hgrid, lacunarity=DEFAULT_LACUNARITY, gain=DEFAULT_GAIN): frequency = 1.0 / hgrid amplitude = gain - for i in xrange(self.num_octaves): + for i in range(self.num_octaves): noise.append( self.octaves[i].noise( xin=x * frequency, @@ -78,9 +78,9 @@ def fractal(self, x, hgrid, lacunarity=DEFAULT_LACUNARITY, gain=DEFAULT_GAIN): class PerlinNoiseOctave(object): def __init__(self, num_shuffles=DEFAULT_SHUFFLES): - self.p_supply = [i for i in xrange(0, 256)] + self.p_supply = [i for i in range(0, 256)] - for i in xrange(num_shuffles): + for i in range(num_shuffles): random.shuffle(self.p_supply) self.perm = self.p_supply * 2 @@ -121,12 +121,12 @@ def __init__(self, num_octaves, persistence, dimensions, noise_scale=DEFAULT_NOI if DIMENSIONS_2D == dimensions: self.octaves = [SimplexNoiseOctave2D() - for i in xrange(self.num_octaves)] + for i in range(self.num_octaves)] self.noise_scale = DEFAULT_2D_NOISE_SCALE elif DIMENSIONS_3D == dimensions: self.octaves = [SimplexNoiseOctave3D() - for i in xrange(self.num_octaves)] + for i in range(self.num_octaves)] self.noise_scale = DEFAULT_2D_NOISE_SCALE else: @@ -137,9 +137,9 @@ def __init__(self, num_octaves, persistence, dimensions, noise_scale=DEFAULT_NOI if DEFAULT_NOISE_SCALE != noise_scale: self.noise_scale = noise_scale - self.frequencies = [pow(2, i) for i in xrange(self.num_octaves)] + self.frequencies = [pow(2, i) for i in range(self.num_octaves)] self.amplitudes = [pow(persistence, len(self.octaves) - i) - for i in xrange(self.num_octaves)] + for i in range(self.num_octaves)] def noise(self, x=0, y=0, z=0): noise = [ @@ -148,7 +148,7 @@ def noise(self, x=0, y=0, z=0): yin=y / self.frequencies[i], zin=z / self.frequencies[i], noise_scale=self.noise_scale - ) * self.amplitudes[i] for i in xrange(self.num_octaves)] + ) * self.amplitudes[i] for i in range(self.num_octaves)] return sum(noise) @@ -158,7 +158,7 @@ def fractal(self, x=0, y=0, z=0, hgrid=0, lacunarity=DEFAULT_LACUNARITY, gain=DE frequency = 1.0 / hgrid amplitude = gain - for i in xrange(self.num_octaves): + for i in range(self.num_octaves): noise.append( self.octaves[i].noise( xin=x * frequency, @@ -182,7 +182,7 @@ class SimplexNoiseOctave2D(object): unskew_factor = (3.0 - math.sqrt(3.0)) / 6.0 def __init__(self, num_shuffles=DEFAULT_SHUFFLES): - self.p_supply = [i for i in xrange(0, 256)] + self.p_supply = [i for i in range(0, 256)] self.grads = [ Point(1, 1, 0), @@ -191,7 +191,7 @@ def __init__(self, num_shuffles=DEFAULT_SHUFFLES): Point(-1, -1, 0) ] - for i in xrange(num_shuffles): + for i in range(num_shuffles): random.shuffle(self.p_supply) self.perm = self.p_supply * 2 @@ -277,7 +277,7 @@ def hashed_gradient_indices(self, points_ij): def calc_noise_contributions(self, grad_index_hash, points_xy): """ Calculates the contribution from each corner (in 2D there are three!) """ contribs = [] - for i in xrange(len(grad_index_hash)): + for i in range(len(grad_index_hash)): x = points_xy[i].x y = points_xy[i].y grad = self.grads[grad_index_hash[i]] @@ -299,7 +299,7 @@ class SimplexNoiseOctave3D(object): unskew_factor = 1.0 / 6.0 def __init__(self, num_shuffles=DEFAULT_SHUFFLES): - self.p_supply = [i for i in xrange(0, 256)] + self.p_supply = [i for i in range(0, 256)] self.grads = [ Point(1, 1, 0), Point(-1, 1, 0), Point(1, -1, 0), Point(-1, -1, 0), @@ -307,7 +307,7 @@ def __init__(self, num_shuffles=DEFAULT_SHUFFLES): Point(0, 1, 1), Point(0, -1, 1), Point(0, 1, -1), Point(0, -1, -1), ] - for i in xrange(num_shuffles): + for i in range(num_shuffles): random.shuffle(self.p_supply) self.perm = self.p_supply * 2 @@ -412,7 +412,7 @@ def hashed_gradient_indices(self, points_ijk): def calc_noise_contributions(self, grad_index_hash, points_xyz): """ Calculates the contribution from each corner (in 2D there are three!) """ contribs = [] - for i in xrange(len(grad_index_hash)): + for i in range(len(grad_index_hash)): x = points_xyz[i].x y = points_xyz[i].y z = points_xyz[i].z