Exemplo n.º 1
0
def test_noise_errors():
    with pytest.raises(ValueError):
        tcod.noise.Noise(0)
    with pytest.raises(ValueError):
        tcod.noise.Noise(1, implementation=-1)
    noise = tcod.noise.Noise(2)
    with pytest.raises(ValueError):
        noise.sample_mgrid(np.mgrid[:2, :2, :2])
    with pytest.raises(ValueError):
        noise.sample_ogrid(np.ogrid[:2, :2, :2])
Exemplo n.º 2
0
def test_noise_class(implementation):
    noise = tcod.noise.Noise(2, tcod.NOISE_SIMPLEX, implementation)
    # cover attributes
    assert noise.dimensions == 2
    noise.algorithm = noise.algorithm
    noise.implementation = noise.implementation
    noise.octaves = noise.octaves
    noise.hurst
    noise.lacunarity

    noise.get_point(0, 0)
    noise.sample_mgrid(np.mgrid[:2, :3])
    noise.sample_ogrid(np.ogrid[:2, :3])
Exemplo n.º 3
0
 def generate(self):
     noise = tcod.noise.Noise(dimensions=2,
                              algorithm=tcod.NOISE_SIMPLEX,
                              implementation=tcod.noise.TURBULENCE,
                              hurst=0.9,
                              lacunarity=2.0,
                              octaves=4,
                              seed=None)
     ogrid = [
         np.arange(100, dtype=np.int32),
         np.arange(200, dtype=np.int32)
     ]
     samples = noise.sample_ogrid(ogrid)
     samples = samples * 10
     newmap = []
     objects = []
     y = 0
     for row in samples:
         x = 0
         newrow = []
         for col in row:
             t = classes.Floor(x, y)
             if int(col) == 2:
                 tree = farm.Tree(x, y)
                 tree.state = farm.Plant.PlantStates.RIPE
                 tree.init()
                 objects.append(tree)
             elif int(col) == 9:
                 t = classes.Grass(x, y)
             newrow.append(t)
             x += 1
         y += 1
         newmap.append(newrow)
     return (newmap, objects)
Exemplo n.º 4
0
def create_noise():
    noise = tcod.noise.Noise(
        dimensions=2,
        algorithm=tcod.NOISE_PERLIN,
        implementation=tcod.noise.SIMPLE,
        hurst=0.5,
        lacunarity=2.0,
        octaves=4,
        seed=None,
    )

    ogrid = [np.arange(64, dtype=np.float32), np.arange(64, dtype=np.float32)]
    print(ogrid)

    ogrid[0] *= 0.25
    ogrid[1] *= 0.25

    samples = noise.sample_ogrid(ogrid)
    print(samples)
    return samples
Exemplo n.º 5
0
def test_noise_copy():
    rand = tcod.random.Random(tcod.random.MERSENNE_TWISTER, 42)
    noise = tcod.noise.Noise(2, seed=rand)
    noise2 = pickle.loads(pickle.dumps(noise))
    assert (noise.sample_ogrid(np.ogrid[:3, :1]) == noise2.sample_ogrid(
        np.ogrid[:3, :1])).all()
Exemplo n.º 6
0
def test_noise_pickle(implementation):
    rand = tcod.random.Random(tcod.random.MERSENNE_TWISTER, 42)
    noise = tcod.noise.Noise(2, implementation, seed=rand)
    noise2 = copy.copy(noise)
    assert (noise.sample_ogrid(np.ogrid[:3, :1]) == noise2.sample_ogrid(
        np.ogrid[:3, :1])).all()
Exemplo n.º 7
0
def test_noise_samples():
    noise = tcod.noise.Noise(2, tcod.NOISE_SIMPLEX, tcod.noise.SIMPLE)
    np.testing.assert_equal(
        noise.sample_mgrid(np.mgrid[:32, :24]),
        noise.sample_ogrid(np.ogrid[:32, :24]),
    )