In [2]:
from noise import snoise2
import matplotlib.pyplot as plt
%matplotlib inline

In [3]:
def generate_map_slice(seed, idx, idy, y, map_size=256, num=.1):
    """
    Generate one y-slice of a block
    To string generation over many game loops
    NOTE: stored in row major format
    """
    octaves = 8
    freq = 16.0 * octaves
    row_line = []
    for x_cell in range(map_size):
        val = snoise2((idx * map_size + x_cell) / freq,
                            (idy * map_size + y) / freq, 
                            octaves, base=seed,                                      
                            repeatx = 65536,
                            repeaty = 65536)
        #print(val)
        if abs(val) < num:
            out=0
        else:
            out=255
        row_line.append(out)
    return row_line

def generate_map(seed, idx=0, idy=0, map_size=256, num=.1):
    block = []
    for y in range(map_size):
        x_line = generate_map_slice(seed, idx, idy, y, map_size, num)
        block.append(x_line)
    return block

In [8]:
import numpy as np
my_range = np.arange(0,0.15,0.005)
for i in my_range:
    block = generate_map(0, 0, 0, 1024, i)
    plt.figure()
    plt.imshow(block)


/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py:424: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

In [ ]:
plt.imshow(block)

In [15]:
def generate_map_slice2(seed, idx, idy, y, map_size=256, num=.1):
    """
    Generate one y-slice of a block
    To string generation over many game loops
    NOTE: stored in row major format
    """
    octaves = 6
    freq = 16.0 * octaves
    row_line = []
    for x_cell in range(map_size):
        val = snoise2((idx * map_size + x_cell) / freq,
                            (idy * map_size + y) / freq, 
                            octaves, base=seed,                                      
                            repeatx = 65536,
                            repeaty = 65536)
        #print(val)
        if abs(val) > num:
            out=0
        else:
            out=255
        row_line.append(out)
    return row_line

def generate_map2(seed, idx=0, idy=0, map_size=256, num=.1):
    block = []
    for y in range(map_size):
        x_line = generate_map_slice2(seed, idx, idy, y, map_size, num)
        block.append(x_line)
    return block

In [16]:
import numpy as np
my_range = np.arange(0,.3,0.005)
for i in my_range:
    block = generate_map2(0, 0, 0, 1024, i)
    plt.figure()
    plt.imshow(block)


/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py:424: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

In [ ]:


In [ ]: