コード例 #1
1
ファイル: utils.py プロジェクト: jingweiz/deep-planning
def sweep_perlin(shape, **params):
    """ Generate a 2 dimensional matrix with perlin noise normalized between -1 and 1 
    Available parameters

    octaves -- specifies the number of passes, defaults to 1 (simple noise).
    
    persistence -- specifies the amplitude of each successive octave relative
    to the one below it. Defaults to 0.5 (each higher octave's amplitude
    is halved). Note the amplitude of the first pass is always 1.0.
    
    lacunarity -- specifies the frequency of each successive octave relative
    to the one below it, similar to persistence. Defaults to 2.0.
    
    repeatx, repeaty -- specifies the interval along each axis when 
    the noise values repeat. This can be used as the tile size for creating 
    tileable textures
    
    base -- specifies a fixed offset for the noise coordinates. Useful for
    generating different noise textures with the same repeat interval
    """
    print repr(params)
    target = numpy.zeros(shape)
    print "weight matrix " + str(target.shape)
    for i in range(shape[0]):
        for j in range(shape[1]):
            target[i, j] = noise.pnoise2(i / shape[0], j / shape[1], **params)

    # target -= target.min()
    # target /= target.max()
    # target = target*2-1

    return target
コード例 #2
0
ファイル: generate_noise.py プロジェクト: dvcolgan/turnlandia
def terrain_type_for_square(col, row):
    terrain_type = 'plains'

    frequency = 1.0/5
    forest_value = noise.pnoise2(col*frequency, row*frequency, 20)
    if forest_value < -0.05:
        terrain_type = 'forest'

    frequency_x = 1.0/30
    frequency_y = 1.0/40
    mountain_value = noise.pnoise2(col*frequency, row*frequency, 1)
    if mountain_value > 0.2:
        terrain_type = 'mountains'

    frequency_x = 1.0/60
    frequency_y = 1.0/45
    river_value = noise.pnoise2(col*frequency_x, row*frequency_y, 10, -0.3)
    if river_value < 0.04 and river_value > -0.04:
        terrain_type = 'water'

    frequency = 1.0/30
    lake_value = noise.pnoise2(col*frequency, row*frequency, 6)
    if lake_value < -0.2:
        terrain_type = 'water'

    return terrain_type
コード例 #3
0
ファイル: models.py プロジェクト: dvcolgan/turnlandia
    def terrain_type_for_square(self, col, row):
        terrain_type = PLAINS

        frequency = 1.0/5
        forest_value = noise.pnoise2(col*frequency, row*frequency, 20)
        if forest_value < -0.05:
            terrain_type = FOREST

        frequency_x = 1.0/30
        frequency_y = 1.0/40
        mountain_value = noise.pnoise2(col*frequency, row*frequency, 1)
        if mountain_value > 0.2:
            terrain_type = MOUNTAINS

        frequency_x = 1.0/60
        frequency_y = 1.0/45
        river_value = noise.pnoise2(col*frequency_x, row*frequency_y, 10, -0.3)
        if river_value < 0.04 and river_value > -0.04:
            terrain_type = WATER

        frequency = 1.0/30
        lake_value = noise.pnoise2(col*frequency, row*frequency, 6)
        if lake_value < -0.2:
            terrain_type = WATER

        return terrain_type
コード例 #4
0
ファイル: 3dbackground.py プロジェクト: Zman94/Side-Projects
    def terrainLoop(self):
        global flying
        xoff, yoff = 0,0
        for y in range(rows):
            terrainz.append(list())
            for x in range(cols):
                terrainz[y].append(noise.pnoise2(xoff,yoff))

        while True:
            flying-=.15
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()

            self.screen.fill((0,0,0))

            yoff = flying
            for y in range(rows):
                xoff = 0
                for x in range(cols):
                    terrainz[y][x]=35*noise.pnoise2(xoff,yoff)
                    xoff+=.15
                yoff+=.15

            for y in range(rows-1):
                x = 0
                points = list()
                for x in range(cols-1):
                    tempV = np.dot(rotation_matrix([1,0,0],1.8*math.pi/3), [x*scl-centerX,-(y*scl-centerY),terrainz[y][x]])
                    tempV[0]*=(1.5-(tempV[2]/600))
                    tempV[1]*=(2-(tempV[2]/600))
                    points.append([int(tempV[0]+centerX+translateX),int(tempV[1]+centerY)+translateY/2])

                    tempV = np.dot(rotation_matrix([1,0,0],1.8*math.pi/3), [x*scl-centerX,-((y+1)*scl-centerY),terrainz[y+1][x]])
                    tempV[0]*=(1.5-(tempV[2]/600))
                    tempV[1]*=(2-(tempV[2]/600))
                    points.append([int(tempV[0]+centerX+translateX),int(tempV[1]+centerY)+translateY/2])

                    tempV = np.dot(rotation_matrix([1,0,0],1.8*math.pi/3), [(x+1)*scl-centerX,-(y*scl-centerY),terrainz[y][x+1]])
                    tempV[0]*=(1.5-(tempV[2]/600))
                    tempV[1]*=(2-(tempV[2]/600))
                    points.append([int(tempV[0]+centerX+translateX),int(tempV[1]+centerY)+translateY/2])
                    pygame.draw.lines(self.screen,(255,255,255),True,points,1)
                    points = list()
                # pygame.draw.rect(self.screen,(255,255,255),[0,y*scl,self.width,1],1)
                # pygame.draw.line(self.screen,(255,255,255),rotateX([0,y*scl],self.centerX,self.centerY,.25),rotateX([self.width,y*scl],self.centerX,self.centerY,.25))

            pygame.display.flip()
コード例 #5
0
ファイル: gen.py プロジェクト: stevesan/dero
def test_polygonate_perlin():
    L = 400
    G = Grid2(L, L, 0)
    S = 10.0/L

    minval = 999999.0
    maxval = -999999
    for (u,_) in G.piter():
        x = u.x * S
        y = u.y * S
        val = noise.pnoise2(x, y)
        G.pset(u, val)

    polys = polygonate(G, lambda x : x > -0.1 and x < 0.2, False, None)

    for i in range(len(polys)):
        polys[i] = linear_simplify_poly(polys[i])

    draw_polys(polys)
    marx = G.W*0.1
    mary = G.H*0.1
    pylab.xlim([-marx, G.W+marx])
    pylab.ylim([-mary, G.H+mary])
    pylab.grid(True)
    pylab.show()
コード例 #6
0
ファイル: 005.py プロジェクト: kellegous/sketching
	def draw(self, context, pa, pb):
		n = self.n

		dx = pb.x - pa.x
		dy = pb.y - pa.y
		m = dy / dx

		di = dx / float(n)

		r = self.r
		f = self.f
		dj = 0.0

		pts = []
		for i in range(n + 1):
			x = di*i
			pts.append(Pt(
				pa.x + x,
				pa.y + x*m + r*noise.pnoise2(i/f, (pa.y + x*m)/f, 1)))

		context.set_line_width(1.0)
		context.move_to(pa.x, pa.y)
		for i in range(1, len(pts)):
			a = pts[i - 1]
			b = pts[i]
			context.curve_to(
				a.x + di/2.0, a.y,
				b.x - di/2.0, b.y,
				b.x, b.y)
		context.stroke()
コード例 #7
0
ファイル: mapmaker.py プロジェクト: mcccclean/piratemap
 def terrain(self):
     pixels = self.pixels
     center = (self.size[0]/2, self.size[1]/2)
     def dist(c):
         dx = center[0] - c[0]
         dy = center[1] - c[1]
         mag = math.sqrt(dx * dx + dy * dy)
         return mag
     ox = random.random() * 1
     oy = random.random() * 1
     for y in range(self.size[1]):
         for x in range(self.size[0]):
             freq = 90.5
             octaves = 6
             perlin = pnoise2(ox + x / freq, oy + y / freq, octaves) + 0.5
             mag = dist((x, y)) / 300.0
             height = perlin * (1 - mag) * 1.0
             self.heights[x, y] = height
             if height < 0:
                 height = 0
             for t in TERRAINS:
                 if height < t.threshold:
                     rgb = t.color
                     if t.name == "Snow":
                         self.tips.append((x, y))
                     break
             pixels[x, y] = tuple([int(c * 255.0) for c in rgb])
     return self
コード例 #8
0
ファイル: LayerPlanetsTerrain.py プロジェクト: Linzee/py-2050
 def generate(self, space, block_x, block_y, random):
     
     if space.getBlockLayer(block_x, block_y) is not 2:
         return
     
     thisPlanetKey = str(block_x) + "," + str(block_y)
     if thisPlanetKey not in space.planets:
         space.setBlockLayer(block_x, block_y, 3)
         return
     thisPlanet = space.planets[thisPlanetKey]
     
     planetsAroundCount = 0
     for dx in range(-1, 1):
         for dy in range(-1, 1):
             thatPlanetKey = str(block_x+dx)+","+str(block_y+dy)
             if thatPlanetKey in space.planets:
                 planetsAroundCount += 1
     
     planetsAroundFactor = (planetsAroundCount + 1)/2
     
     thisPlanet.height = []
     for i in range(0, self.HEIGHT_RESOLUTION):
         
         a = math.pi * 2 * (float(i) / self.HEIGHT_RESOLUTION)
         hx = self.PLANET_HEIGHT_RADIUS * thisPlanet.size * math.sin(a)
         hy = self.PLANET_HEIGHT_RADIUS * thisPlanet.size * math.cos(a)
         h = pnoise2(thisPlanet.position[0] + hx, thisPlanet.position[1] + hy, self.PLANET_HEIGHT_OCTAVES)
         
         thisPlanet.height.append(1.0 + self.MAX_HEIGHT + h * self.MAX_HEIGHT * planetsAroundFactor)
     
     space.setBlockLayer(block_x, block_y, 3)
コード例 #9
0
ファイル: worlsd.py プロジェクト: bagyr/worlsd
 def addNoise(self, octaves):
     freq = 16.0 * octaves
     for x in range(self.width):
         for y in range(self.height):
             self.heightmap[x][y] += \
                     int(pnoise2(x / freq, y / freq, octaves)\
                     * 127.0 + 128.0)
コード例 #10
0
ファイル: neighborhood.py プロジェクト: tps12/Dorftris
    def data(self):
        xlim = ylim = 100
        value = [[None for x in range(xlim)] for y in range(ylim)]
        
        data = self.source.data()
        noise = [[pnoise2(self.source.selection[1][0]+self.selection[1][0]+float(x)/xlim,
                          self.source.selection[0][0]+self.selection[0][0]+float(y)/ylim,
                          6, 0.65) * 1000
                  for x in range(xlim)]
                 for y in range(ylim)]

        hmin = hmax = 0
        for y in range(ylim):
            for x in range(xlim):
                yd = len(data)*(self.selection[1][0]/ylim+y/10.0/ylim)
                xd = len(data[0])*(self.selection[0][0]/xlim+x/10.0/xlim)

                h = self._height(data, yd, xd)
                n = noise[y][x]
                if h < 0:
                    h += -n if n > 0 else n
                else:
                    h += n if n > 0 else -n
                value[y][x] = h
        return value
コード例 #11
0
ファイル: coasts.py プロジェクト: pvigier/gaia
def get_noise(size, freq, octaves, persistence):
	offset = np.random.randint(size)
	perlin = np.zeros((size, size), dtype=np.uint8)
	for i in range(size):
		for j in range(size):
			perlin[i, j] = pnoise2(offset + j * freq / size, offset + i * freq / size, octaves, persistence) * 127.0 + 128
	return perlin
コード例 #12
0
ファイル: neighborhood.py プロジェクト: tps12/Dorftris
    def makebackground(self, surface):
        surface.fill((0,0,0))
        
        template = Surface(2*(min(self.zoom.width, self.zoom.height),))
        template.fill((0,0,0,255))
        width,height = template.get_size()

        ylim = surface.get_height()/height
        xlim = surface.get_width()/width

        data = self._data
        noise = [[pnoise2(self._selected[1][0]+x,
                          self._selected[0][0]+y,
                          4, 0.85) * 50
                  for x in range(xlim)]
                 for y in range(ylim)]

        hmin = hmax = 0
        for y in range(ylim):
            for x in range(xlim):
                yd = len(data)*float(y)/ylim
                xd = len(data[0])*float(x)/xlim

                h = self._height(data, yd, xd)
                n = noise[y][x]
                if h < 0:
                    h += -n if n > 0 else n
                else:
                    h += n if n > 0 else -n
                if h < hmin:
                    hmin = h
                if h > hmax:
                    hmax = h

        self.rects = []
        for y in range(ylim):
            for x in range(xlim):
                block = template.copy()
                yd = len(data)*float(y)/ylim
                xd = len(data[0])*float(x)/xlim

                h = self._height(data, yd, xd)
                n = noise[y][x]
                if h < 0:
                    h += -n if n > 0 else n
                else:
                    h += n if n > 0 else -n
                if h < 0:
                    color = 0, 0, int(255 * (1 - h/hmin))
                else:
                    color = 0, int(255 * h/hmax), 0
                block.fill(color)
                if self.selection:
                    if self.selection[0][0] <= yd <= self.selection[0][1]:
                        if self.selection[1][0] <= xd <= self.selection[1][1]:
                            block.fill((255,0,0,32),
                                       special_flags = BLEND_ADD)
                rect = Rect(x*width, y*height, width, height)
                surface.blit(block, rect.topleft)
                self.rects.append((rect, (yd, xd)))
コード例 #13
0
ファイル: mapGen.py プロジェクト: PaperTanuki/Delve
def mapGenerator2(width, height):
    grid = []
    for i in range(width):
        fila = []
        for j in range(height):
            x = (i * 1.0) / width
            y = (j * 1.0) / height

            seed = random.random()
            seed2 = random.randint(10, 250)

            n = noise.pnoise2(seed2 * x + 10, 10 * y, 1, 0.5, 0.2, 1024, 1024, 0) * 1.5 + 0.6

            # if n == 0.0:
            #     fila.append('/')

            if n < 0.15:
                fila.append("~")
            elif n >= 0.15 and n < 0.6:
                fila.append(".")
            elif n >= 0.75:
                fila.append("#")

        grid.append(fila)
    return grid
コード例 #14
0
ファイル: test.py プロジェクト: Connor124/Gran-Theft-Crop-Toe
 def test_perlin_2d_range(self):
     from noise import pnoise2
     for i in range(-10000, 10000):
         x = i * 0.49
         y = -i * 0.67
         n = pnoise2(x, y)
         self.assertTrue(-1.0 <= n <= 1.0, (x, y, n))
コード例 #15
0
ファイル: model.py プロジェクト: SIben/mvrptw
def make_last_point(last_point, width, height, factor):
    """
    Generates a new last point in order to help with the route generation.
    It uses the following parameters:

    - last_point (the former last point)
    - width (the width of the window)
    - height (the height of the window)
    - factor (a user-chosen factor)
    """
    newx = \
	pnoise2(last_point.get_x() / width, last_point.get_y() / height)
    newy = \
	pnoise2(last_point.get_y() / height, last_point.get_x() / width)
    newx = CLAMP(last_point.get_x() + newx * factor, 0, width)
    newy = CLAMP(last_point.get_y() + newy * factor, 0, height)
    return Point(newx, newy)
コード例 #16
0
 def applyPertubation(self, frequency=32.0, displacement=32.0):
     width = self.width*self.cPatchSize
     height = self.height*self.cPatchSize
     frequency = float(frequency) / float(width)
     
     tmp = numpy.zeros([width*self.cPatchSize+1,height*self.cPatchSize+1], dtype=float)
     
     for i in range(width):
         for j in range(height):
             u = i + int(pnoise2(j * frequency, i * frequency, 1) * displacement)
             v = j + int(pnoise2(j * frequency, i * frequency, 2) * displacement)
             if u < 0: u = 0
             if v < 0: v = 0
             if u >= width: u = width - 1
             if v >= height: v = height - 1
             tmp[i][j] = self.d_array[u][v]
     self.d_array = tmp
コード例 #17
0
ファイル: test.py プロジェクト: Connor124/Gran-Theft-Crop-Toe
 def test_perlin_2d_octaves_range(self):
     from noise import pnoise2
     for i in range(-1000, 1000):
         for o in range(10):
             x = -i * 0.49
             y = i * 0.67
             n = pnoise2(x, y, octaves=o + 1)
             self.assertTrue(-1.0 <= n <= 1.0, (x, n))
コード例 #18
0
ファイル: 007.py プロジェクト: kellegous/sketching
def draw_doodle_dah(context, x, y, vx, vy, r):
	v = (1 + noise.pnoise2(vx, vy, 1))/2.0
	a = 0.2+v*0.6
	context.set_source_rgba(*color_of(0xff0099, a=a))
	context.arc(x, y, r, 0, 2*math.pi)
	context.fill()

	context.set_source_rgb(*color_of(0x333333))
	context.arc(x, y, r, 0, 2*math.pi)
	context.stroke()
コード例 #19
0
ファイル: terrain.py プロジェクト: eykd/orphan
 def glyph(cls, at):
     row, col = at.position
     col_prime = int(
         round(
             abs(
                 (time() * 0.1 + (col * 0.1) + pnoise2(row*0.1, col*0.1)) % 1
                 ) * (len(cls.glyphs) - 1)
             )
         )
     return cls.glyphs[col_prime]
コード例 #20
0
ファイル: 007.py プロジェクト: kellegous/sketching
def draw_empty_spot(context, x, y, vx, vy, r):
	v = (1 + noise.pnoise2(vx, vy, 1))/2.0
	a = v*0.3
	context.set_source_rgba(*color_of(0x333333, a=0.1))
	context.arc(x, y, r, 0, 2*math.pi)
	context.fill()

	context.set_line_width(1.0)
	context.set_source_rgba(*color_of(0x333333, a=0.3))
	context.arc(x, y, r, 0, 2*math.pi)
	context.stroke()
コード例 #21
0
ファイル: noise_node.py プロジェクト: nfactorial/imagegen
def evaluate_noise(eval_info):
    """
    :param eval_info: Parameters describing the sample currently being evaluated.
    :return: The evaluated value at the supplied sample location.
    """
    octaves = eval_info.evaluate('octaves', eval_info.x, eval_info.y)
    frequency = eval_info.evaluate('frequency', eval_info.x, eval_info.y)
    frequency_x = frequency / eval_info.image_size[0] * octaves
    frequency_y = frequency / eval_info.image_size[0] * octaves
    pnoise = noise.pnoise2(eval_info.x / frequency_x, eval_info.y / frequency_y, octaves=octaves)
    pnoise = 0.5 + pnoise / 2.0
    return Color(pnoise, pnoise, pnoise, pnoise)
コード例 #22
0
ファイル: planet.py プロジェクト: Kthulhu/noise
def create_bands_texture(bands=14.0, stretch=2.0, turbulence=8.0, 
	color1=(1.0, 0.8, 0.6), color2=(0.1, -0.3, -0.4)):
	coords = range(TEXTURE_SIZE)
	texel = (ctypes.c_ubyte * (3 * TEXTURE_SIZE**2))()
	for y in coords:
		for x in coords:
			p = pnoise2(x * 15.0 / TEXTURE_SIZE, y * 15.0 / TEXTURE_SIZE, octaves=5, 
				repeatx=15.0, repeaty=15.0) * math.pi * 2.0
			px = (x + math.sin(p) * turbulence)
			py = (y + math.cos(p) * turbulence)
			v = pnoise2(
				px / stretch / TEXTURE_SIZE, py * bands / TEXTURE_SIZE, octaves=4,
				repeaty=bands, repeatx=1.0/stretch)
			r, g, b = blend((v + 1.0) / 2.0, color1, color2, 1.75 + (p**5)*0.003)
			texel[(x + (y * TEXTURE_SIZE))*3] = max(min(int(r * 255.0), 255), 0)
			texel[(x + (y * TEXTURE_SIZE))*3 + 1] = max(min(int(g * 255.0), 255), 0)
			texel[(x + (y * TEXTURE_SIZE))*3 + 2] = max(min(int(b * 255.0), 255), 0)
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXTURE_SIZE, TEXTURE_SIZE, 0, 
		GL_RGB, GL_UNSIGNED_BYTE, ctypes.byref(texel))
	return texel
コード例 #23
0
def evaluate_turbulence(eval_info):
    """
    :param eval_info: EvalInfo object containing the sample being evaluated.
    :return: The evaluated value at the supplied sample location.
    """
    octaves = eval_info.evaluate('octaves', eval_info.x, eval_info.y)
    frequency = eval_info.evaluate('frequency', eval_info.x, eval_info.y)
    frequency_x = frequency / eval_info.image_size[0] * octaves
    frequency_y = frequency / eval_info.image_size[0] * octaves
    pnoise = noise.pnoise2(eval_info.x / frequency_x, eval_info.y / frequency_y, octaves=octaves)
    pnoise = math.fabs(pnoise)
    return Color(pnoise, pnoise, pnoise, pnoise)
コード例 #24
0
ファイル: gol.py プロジェクト: Pranz/gsgpy
def initialize(self):
	self.con   = libtcod.console_new(main.SCREEN_WIDTH, main.SCREEN_HEIGHT)
	random.seed()
	noise_seed = random.randint(-10000,10000)
	scale      = 0.02
	self.noise = lambda x,y: noise.pnoise2(scale * (x + noise_seed), scale * (y + noise_seed),15,0.5,3)
	self.world = [[self.noise(x,y) > -0.1 for y in range(0,GOL_HEIGHT+2)] for x in range(0,GOL_WIDTH+2)]
	for x in range(0,GOL_WIDTH+2):
		self.world[x][0]            = False
		self.world[x][GOL_HEIGHT+1] = False
	for y in range(0,GOL_HEIGHT+2):
		self.world[0][y]            = False
		self.world[GOL_WIDTH+1][y]  = False
コード例 #25
0
 def applyPerlinNoise(self, octaves=1, frequency=1, persistence=0.5, amplitude=100):
     """ TerrainGenerator.applyPerlinNoise(...)
         - applyPerlinNoise() method generates a heightmap with perlin noise and applies it on top of
         the current heightmap. If used to generate the initial heightmap, TerrainGenerator.initialize()
         must be called first.
     """
     width = self.width*self.cPatchSize
     height = self.height*self.cPatchSize
     frequency = float(frequency) / float(width)
     
     for y in range(height):
         for x in range(width):
             noise = pnoise2(x * frequency, y * frequency, octaves, persistence)
             self.d_array[x][y] += noise*amplitude
コード例 #26
0
ファイル: terrain.py プロジェクト: eykd/orphan
 def glyph(cls, at):
     try:
         return cls.glyph_cache[at.position]
     except KeyError:
         row, col = at.position
         col_prime = int(
             round(
                 abs(
                     (pnoise2(row*0.1, col*0.1)) % 1
                     ) * (len(cls.glyphs) - 1)
                 )
             )
         g = cls.glyph_cache[at.position] = cls.glyphs[col_prime]
         return g
コード例 #27
0
ファイル: 2dnoise.py プロジェクト: datosh/natureofcode
    def generate(self, octaves, persistance, lacunarity):
        base_x = random.randint(0, 100)
        base_y = random.randint(0, 100)

        for x in range(self.screen_width):
            for y in range(self.screen_height):
                xoff = (x / self.screen_width * 7) + base_x
                yoff = (y / self.screen_height * 7) + base_y
                color = int(abs(noise.pnoise2(
                    xoff, yoff,
                    octaves,
                    persistance,
                    lacunarity) * 3333))
                self.image.set_at(
                    (x, y),
                    (color % 255, color % 255, color % 255))
コード例 #28
0
 def drawLand(self):
   if self.seed == None:
     seed = random.randint(1, 1000)
     self.seed = seed
   else:
     seed = self.seed
   noise = []
   for tile in self.getTiles():
     relX = float(tile.col / self.width)
     relY = float(tile.row / self.height)
     tile.noise = pnoise2(relX, relY, 13, 0.6, base = seed)
     noise.append(tile.noise)
   min_noise = min(noise)
   max_noise = max(noise)
   noise_range = float(max_noise - min_noise)
   for tile in self.getTiles():
     tile.elevation = (tile.noise + abs(min_noise)) / noise_range
コード例 #29
0
ファイル: worlds.py プロジェクト: twocngdagz/AIKIF
 def add_mountains(self):
     """
     instead of the add_blocks function which was to produce
     line shaped walls for blocking path finding agents, this
     function creates more natural looking blocking areas like
     mountains
     """
     from noise import pnoise2
     import random
     random.seed()
     octaves = (random.random() * 0.5) + 0.5
     freq = 17.0 * octaves  # 
     for y in range(self.grd.grid_height - 1):
         for x in range(self.grd.grid_width - 1):
             pixel = self.grd.get_tile(y,x)
             if pixel == 'X':     # denoise blocks of mountains
                 n = int(pnoise2(x/freq, y / freq, 1)*11+5)
                 if n < 1:
                     self.grd.set_tile(y, x, '#')
コード例 #30
0
ファイル: noise_maker.py プロジェクト: Jeffdude/Parcae
def perlinNoise(wWidth, wHeight):
    """
    wrapper for 'noise' packages pnoise2 function
    """
    # create the map
    landscape = np.empty((wWidth, wHeight), dtype=np.float)
    landscape.fill(-1)
    

    max_height = 0.0
    denom = 16.0
    # generate the noise
    for x in range(len(landscape)):
        for y in range(len(landscape[0])):
            height = noise.pnoise2(x / denom, y / denom) * 10 + 10
            landscape[x][y] = height
            if height > max_height:
                max_height = height
    return (landscape, max_height)