Пример #1
0
    def run(self):
        noiseMap = numpy.zeros((self.width, self.height))

        # pure python version
        sn = SimplexNoise(period=self.width)
        persistance = 0.5
        octaves = [1, 2, 4, 8, 16]
        for octave in octaves:
            freq = 16.0 * octave
            for y in range(self.height):
                for x in range(self.width):
                    fn = sn.noise2(x / freq, y / freq)
                    noiseMap[x, y] += fn * persistance
            persistance *= 2

#        octaves = 5
#        freq = 16.0 * octaves
#        for y in xrange(self.height):
#            for x in xrange(self.width):
#                fn = snoise2(x / freq, y / freq, octaves=octaves, persistence=0.5, lacunarity=2.0, repeatx=self.width, repeaty=self.height, base=0.0)
#                noiseMap[x,y] = fn

#print noiseMap
#noiseMap = numpy.gradient(noiseMap).shape((self.width, self.height))
#print noiseMap
        self.heightmap = noiseMap
Пример #2
0
    def run( self ):
        noiseMap = numpy.zeros((self.width, self.height))
        
        # pure python version
        sn = SimplexNoise(period = self.width)
        persistance = 0.5
        octaves = [1, 2, 4, 8, 16]
        for octave in octaves:
            freq = 16.0 * octave
            for y in range(self.height):
                for x in range(self.width):
                    fn = sn.noise2( x/freq, y/freq )
                    noiseMap[x,y] += fn * persistance
            persistance *= 2

#        octaves = 5
#        freq = 16.0 * octaves
#        for y in xrange(self.height):
#            for x in xrange(self.width):
#                fn = snoise2(x / freq, y / freq, octaves=octaves, persistence=0.5, lacunarity=2.0, repeatx=self.width, repeaty=self.height, base=0.0)
#                noiseMap[x,y] = fn
        
        #print noiseMap
        #noiseMap = numpy.gradient(noiseMap).shape((self.width, self.height))
        #print noiseMap
        self.heightmap = noiseMap
Пример #3
0
class Perlin(NoiseGenerator):
    def __init__(self, period: int = 256, octaves: int = 0):
        self.simplex_noise = SimplexNoise(period=period)
        self.octaves = octaves

    def get_noise(self, x: int, y: int):
        noise_value = self.__build_noise(x, y) + 1

        return int(noise_value * 100 / 2)

    def __build_noise(self, x: int, y: int):
        noise_value = self.simplex_noise.noise2(x, y)

        for octave in range(self.octaves):
            exp = pow(2, octave)
            noise_value += self.simplex_noise.noise2(x * exp,
                                                     y * exp / 2) / exp
        return noise_value
Пример #4
0
 def run( self ):
     noiseMap = numpy.zeros((self.width, self.height))
     
     sn = SimplexNoise()
     
     octaves = 1
     for octaves in xrange (1,17):
         sn.randomize()
         print octaves
         freq = 128.0 * octaves
         for y in xrange(self.width):
             for x in xrange(self.height):
                 fn = sn.noise2( x/freq, y/freq )
                 noiseMap[x,y] += fn
         #break
     #print noiseMap
     self.heightmap = compressHeightmap(noiseMap)
Пример #5
0
    def run(self):
        noiseMap = numpy.zeros((self.width, self.height))

        sn = SimplexNoise()

        octaves = 1
        for octaves in xrange(1, 17):
            sn.randomize()
            print octaves
            freq = 128.0 * octaves
            for y in xrange(self.width):
                for x in xrange(self.height):
                    fn = sn.noise2(x / freq, y / freq)
                    noiseMap[x, y] += fn
            #break
        #print noiseMap
        self.heightmap = compressHeightmap(noiseMap)