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
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
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)
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)
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
def simplexNoise(dimensions, scale_x=1, scale_y=1, salt=None, pepper=None): """ Makes a salt and pepper texture using multiple colors with the same proability :param dimensions: The Textures dimensions :param condiments: The colors to choose from """ salt = np.array([0, 0, 0]) if salt is None else np.array(salt) pepper = np.array([1, 1, 1]) if pepper is None else np.array(pepper) img = np.empty((dimensions[0], dimensions[1], 3)) for x in range(dimensions[0]): for y in range(dimensions[1]): color = (SimplexNoise().noise2(x / scale_x, y / scale_y) + 1) / 2 img[x, y] = np.array(salt * color + pepper * (1 - color)) return img
def circle_perlin(dimensions, circle_scale=1, perlin_scale=1, randomness=1): """ Makes a salt and pepper texture using multiple colors with the same proability :param dimensions: The Textures dimensions :param condiments: The colors to choose from """ img = np.empty((dimensions[0], dimensions[1], 3)) for x in range(dimensions[0]): for y in range(dimensions[1]): perlin = (SimplexNoise().noise2( x / perlin_scale, y / perlin_scale) + 1) * randomness color = (math.cos(x * circle_scale + perlin) + math.sin(y * circle_scale + perlin) + 2) / 4 img[x, y] = np.array([color] * 3) return img
def sine_perlin(dimensions, perlin_scale=1, sine_scale=1, randomness=0, salt=None, pepper=None): """ Makes a salt and pepper texture using multiple colors with the same proability :param dimensions: The Textures dimensions :param condiments: The colors to choose from """ salt = np.array([0, 0, 0]) if salt is None else np.array(salt) pepper = np.array([1, 1, 1]) if pepper is None else np.array(pepper) img = np.empty((dimensions[0], dimensions[1], 3)) for x in range(dimensions[0]): for y in range(dimensions[1]): perlin = (SimplexNoise().noise2( x / perlin_scale, y / perlin_scale) + 1) * randomness sine = (math.sin(x * sine_scale + perlin) + 1) / 2 img[x, y] = np.array(salt * sine + pepper * (1 - sine)) return img
from pyglet import image from pyglet.gl import glClearColor, glEnable, GL_CULL_FACE, glTexParameteri, \ GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST, \ GL_TEXTURE_MAG_FILTER, GL_FOG, glFogfv, GL_FOG_COLOR, \ GLfloat, glHint, GL_FOG_HINT, GL_DONT_CARE, glFogi, \ GL_FOG_MODE, GL_LINEAR, glFogf, GL_FOG_START, \ GL_FOG_END, GL_QUADS from pyglet.graphics import Batch, TextureGroup from pyglet.window import mouse from pycraft.objects import brick, grass, sand, stone from pycraft.util import normalize, sectorize, reverse_sectorize, \ cube_vertices, cube_shade, batch_cube_vertices from pycraft.shader import Shader simplex_noise2 = SimplexNoise(256).noise2 TEXTURE_PATH = 'pycraft/objects/textures.png' FACES = [ (0, 1, 0), (0, -1, 0), (-1, 0, 0), (1, 0, 0), (0, 0, 1), (0, 0, -1), ] class World: def __init__(self): # A Batch is a collection of vertex lists for batched rendering.
def __init__(self, period: int = 256, octaves: int = 0): self.simplex_noise = SimplexNoise(period=period) self.octaves = octaves
import pygame from math import floor from noise.perlin import SimplexNoise pygame.init() display = pygame.display.set_mode((800, 600)) still_on = True clock = pygame.time.Clock() noise = SimplexNoise() class Walker(): def __init__(self): self.x = display.get_width() / 2 self.y = display.get_height() / 2 self.x_off = 10001 self.y_off = 10000 self.rate = 0.001 self.speed = 1 self.radius = 20 def draw(self): color = lambda x: int( floor(abs(noise.noise2(self.x + x, self.y + x) * 255))) pygame.draw.circle(display, (color(1), color(1), 255), (int(floor(self.x)), int(floor(self.y))), self.radius) def step(self): step_x = noise.noise2(self.x_off, self.x_off) * self.speed