Пример #1
0
    def get_background(self, clk):
        z = clk * self.__background_speed + self.__z_offset

        # if self.__dim == 5:
        # if 1:
           #  data = STREAM.read(CHUNK, exception_on_overflow=False)
           #  wave_data = wave.struct.unpack("%dh" % CHUNK, data)
           #  np_array_data = np.array(wave_data)
           #  audio_data = np.abs(np_array_data * window)
           #  audio_data = audio_data[::int(CHUNK / 64)]
           #  max_ = max(audio_data)
           #  #if max_ < 20.0:
           #  #    audio_data *= 0

           #  norm2 = plt.Normalize(0, max_)
           # # self.__audio_data = gaussian_filter1d(16 * norm2(audio_data), 1)
           #  self.__audio_data = 16 * norm2(audio_data)
        

        # else:

        for y in range(self.screen_height):
            for x in range(self.screen_width):
                if self.__dim == 0:
                    self.__bw[y][x] = int(snoise3(y / self.__freq, y / self.__freq, z / self.__freq, self.__octaves) * 127.0 + 128.0)

                elif self.__dim == 1:
                    self.__bw[y][x] = int(snoise3(x / self.__freq, x / self.__freq, z / self.__freq, self.__octaves) * 127.0 + 128.0)

                elif self.__dim == 2:
                    self.__bw[y][x] = int(snoise3(x / self.__freq, y / self.__freq, z / self.__freq, self.__octaves) * 127.0 + 128.0)

                elif self.__dim == 3:
                    self.__bw[y][x] = int(snoise3((x + clk) / self.__freq, y / self.__freq, z / self.__freq, self.__octaves) * 127.0 + 128.0)

                elif self.__dim == 4:
                    self.__bw[y][x] = int(snoise3(x / self.__freq, (y + clk) / self.__freq, z / self.__freq, self.__octaves) * 127.0 + 128.0)

                # elif self.__dim == 5:
                #     if 16 - y > self.__audio_data[x]:
                #        self.__bw[y][x] = int(snoise3(y / self.__freq, y / self.__freq, z / self.__freq, self.__octaves) * 0)
                #     else:
                #        self.__bw[y][x] = int(snoise3(y / self.__freq, y / self.__freq, z / self.__freq, self.__octaves) * 127.0 + 128.0)



        rgb = gradients[self.__curr_gradient](norm(self.__bw))
        img_array = np.uint8(rgb * 255 * self.background_brightness)
        # if self.__dim == 5:
        #     for y in range(self.screen_height):
        #         for x in range(self.screen_width):
        #             if 16 - y > self.__audio_data[x]:
        #                 img_array[y][x] *= 0


        img = Image.fromarray(img_array).convert('RGB')

        

        return img
Пример #2
0
def p_calc():
    global z
    for i in range(fn):
        for j in range(fn):
            f[i, j, 0] = noise.snoise3(j * fs, i * fs, z)
            f[i, j, 1] = noise.snoise3(j * fs, i * fs, z + 100)
    z += 0.001
Пример #3
0
    def draw(self, dt):
        if self._mixer.is_onset():
            self._offset_z += self.parameter('beat-color-boost').get()

        angle = self.parameter('angle').get()
        #self._offset_x += dt * self.parameter('speed').get() * math.cos(angle) * 2 * math.pi
        #self._offset_y += dt * self.parameter('speed').get() * math.sin(angle) * 2 * math.pi
        self._offset_x += dt * self.parameter('speed').get()
        self._offset_z += dt * self.parameter('color-speed').get()
        posterization = self.parameter('resolution').get()

        rotMatrix = np.array([(math.cos(angle), -math.sin(angle)), (math.sin(angle),  math.cos(angle))])
        x,y = rotMatrix.T.dot(self.pixel_locations.T)
        x *= self.parameter('stretch').get()
        x += self._offset_x
        y += self._offset_y
        locations = np.asarray([x,y]).T

        hues = np.asarray([snoise3(self.scale * location[0], \
                                   self.scale * location[1], \
                                   self._offset_z, 1, 0.5, 0.5) for location in locations])
        hues = (1.0 + hues) / 2
        hues = self.hue_min + ((np.int_(hues * posterization) / float(posterization)) * (self.hue_max - self.hue_min))
        brights = np.asarray([snoise3(self.luminance_scale * location[0], self.luminance_scale * location[1], self._offset_z, 1, 0.5, 0.5) for location in locations])
        brights = (1.0 + brights) / 2
        brights *= self._luminance_steps
        luminances = self.lum_fader.color_cache[np.int_(brights)].T[1]

        self.setAllHLS(hues, luminances, 1.0)
Пример #4
0
    def draw(self, dt):
        if self._mixer.is_onset():
            self._offset_z = -self._offset_z
            
        self._setup_pars()
        self._offset_x += dt * self.parameter('speed').get() * math.cos(self.parameter('angle').get() * 2 * math.pi)
        self._offset_y += dt * self.parameter('speed').get() * math.sin(self.parameter('angle').get() * 2 * math.pi)
        self._offset_z += dt * self.parameter('color-speed').get()
        if self._mixer.is_onset():
            posterization = 2
        else:
            posterization = self.parameter('resolution').get()

        luminance_table = []
        luminance = 0.0
        for input in range(self._luminance_steps):
            if input > self.parameter('blackout').get() * self._luminance_steps:
                luminance -= 0.01
            elif input < self.parameter('whiteout').get() * self._luminance_steps:
                luminance += 0.01
            else:
                luminance = 0.5
            luminance = clip(0, luminance, 1.0)
            luminance_table.append(math.floor(luminance * posterization) / posterization)
            
        
        for pixel, location in self.pixel_locations:
            hue = (1.0 + snoise3(self.scale * location[0] + self._offset_x, self.scale * location[1] + self._offset_y, self._offset_z, 1, 0.5, 0.5)) / 2
            hue = self.hue_min + ((math.floor(hue * posterization) / posterization) * (self.hue_max - self.hue_min))
            
            brightness = self._luminance_steps * (1.0 + snoise3(self.luminance_scale * location[0] + self._offset_x, self.luminance_scale * location[1] + self._offset_y, self._offset_z, 1, 0.5, 0.5)) / 2
            
            self.setPixelHLS(pixel, (hue, luminance_table[int(brightness)], 1.0))
Пример #5
0
def parse_block_only_water_magma(fresh_block, array_geos_worlds, tiles, iso_array, iso_array_mat):
	world_block_pos = from_dfworld_to_world(vec3(map_info.block_size_x*16-16 - fresh_block.map_x, fresh_block.map_y, fresh_block.map_z))

	# temporary array_geos
	magma_array_geos = []
	water_array_geos = []

	x, z = 15, 0
	max_count = max(len(fresh_block.water), len(fresh_block.magma))
	for i in range(max_count):
		magma = fresh_block.magma[i] if i < len(fresh_block.magma) else 0
		water = fresh_block.water[i] if i < len(fresh_block.water) else 0

		if magma > 0 or water > 0:
			if magma > 0:
				tile_pos = vec3(world_block_pos.x + x, world_block_pos.y - (1.0 - magma / 7)*0.5, world_block_pos.z + z)
				tile_scale = vec3(1, magma/7., 1)
				iso_array[x, z] = magma/7.
				current_array_geos = magma_array_geos
			elif water > 0:
				tile_pos = vec3(world_block_pos.x + x, world_block_pos.y - (1.0 - water / 7)*0.5, world_block_pos.z + z)
				tile_scale = vec3(1, water/7., 1)
				iso_array[x, z] = water/7.
				current_array_geos = water_array_geos

			iso_array_mat[x, z] = 4

			id_tile = hash_from_pos(tile_pos.x, tile_pos.y, tile_pos.z)

			# block["blocks"][id_tile] = {"m": mat4.TranslationMatrix(tile_pos), "mat": block_mat} # perfect grid
			n1 = noise.snoise3(tile_pos.x, tile_pos.y, tile_pos.z)
			n2 = noise.snoise3(tile_pos.x+0.5, tile_pos.y, tile_pos.z)
			n3 = noise.snoise3(tile_pos.x, tile_pos.y+0.5, tile_pos.z)
			m = mat4.TransformationMatrix(tile_pos, vec3(n1 * 0.1, n2 * 0.1, n3 * 0.1), tile_scale)
			tiles[id_tile] = {"m": m, "mat": 4} # with rumble

			current_array_geos.append(m)

		x -= 1
		if x < 0:
			x = 15
			z += 1

	# reset water and magma
	if len(magma_array_geos) > 0:
		array_geos_worlds[tile_geos[tile_type.MAGMA]["id_geo"]] = magma_array_geos

	if len(water_array_geos) > 0:
		array_geos_worlds[tile_geos[tile_type.WATER]["id_geo"]] = water_array_geos

	iso_array[:, -1] = iso_array[:, -2]
	iso_array[-1, :] = iso_array[-2, :]

	iso_array_mat[:, -1] = iso_array_mat[:, -2]
	iso_array_mat[-1, :] = iso_array_mat[-2, :]

	return array_geos_worlds, tiles, iso_array, iso_array_mat
Пример #6
0
    def Move(self):
        if self.target != None:
            self.moving = True
            self.diff = (self.target[0] - self.x, self.target[1] - self.y)
            self.distToTarget = Mag(self.diff)
            
            if self.distToTarget < self.radius:
                self.target = None
                self.eatingFood = False

                self.noiseValue_x = noise.snoise3(
                            self.NOISE_x1 / self.NOISE_scale, 
                            self.NOISE_y1 / self.NOISE_scale, 
                            self.NOISE_z1, 
                            octaves=self.NOISE_octaves, 
                            persistence=self.NOISE_persistence, 
                            lacunarity=self.NOISE_lacunarity)

                self.noiseValue_y = noise.snoise3(
                            self.NOISE_x2 / self.NOISE_scale, 
                            self.NOISE_y2 / self.NOISE_scale, 
                            self.NOISE_z2, 
                            octaves=self.NOISE_octaves, 
                            persistence=self.NOISE_persistence, 
                            lacunarity=self.NOISE_lacunarity)

                self.NOISE_z1 += 0.3

                self.NOISE_z2 += 0.3

            else:
                try:
                    self.T_angle = math.degrees(math.acos(self.diff[0] / self.distToTarget))

                    if self.diff[1] > 0:
                        self.T_angle = 360 - self.T_angle
                        
                except ZeroDivisionError:
                    self.T_angle = 0

            self.x += math.cos(math.radians(-self.T_angle)) * self.speed
            self.y += math.sin(math.radians(-self.T_angle)) * self.speed

        else:
            self.moving = False

            if self.searchCoolDown <= 0:
                self.SearchFood()

            RandFunc(0.05, lambda: self.SetTarget([self.x + self.noiseValue_x * 200, self.y + self.noiseValue_y * 200]))
Пример #7
0
def calc_field(draw=False):
  global z
  a_len = 40
  for i in range(fn):
    for j in range(fn):
      f[i,j,0] = noise.snoise3(j*fs,i*fs,z, octaves=1)
      f[i,j,1] = noise.snoise3(j*fs,i*fs,z+100, octaves=1)
      if draw and i%10==0 and j%10 == 0:
        start = (0.5*fhscl+i*fhscl, 0.5*fwscl+j*fwscl)
        dest = (start[0]+f[i,j,0]*a_len, start[1]+f[i,j,1]*a_len)
        edge, _, _ = check_edge(*dest)
        if not edge: 
          line(start, dest)
  z+=0.001
Пример #8
0
def add_noise_to_sphere(poly_data, octaves, offset=0, scale=0.5):
    """
    Expects sphere with radius 1 centered at the origin
    """
    wrap_data_object = dsa.WrapDataObject(poly_data)
    points = wrap_data_object.Points
    normals = wrap_data_object.PointData['Normals']

    points_with_noise = []
    zipped = list(zip(points, normals))
    for point, normal in tqdm(zipped):
        offset_point = point + offset
        noise = scale * snoise3(*offset_point, octaves=octaves)
        point_with_noise = point + noise * normal
        points_with_noise.append(point_with_noise)
    points_with_noise = np.array(points_with_noise)

    vertices = vtk.vtkPoints()
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')
        points_with_noise_vtk = numpy_to_vtk(points_with_noise)
    vertices.SetData(points_with_noise_vtk)
    poly_data.SetPoints(vertices)

    return poly_data
Пример #9
0
def create_3d_texture(width, scale):
    """Create a grayscale 3d texture map with the specified 
	pixel width on each side and load it into the current texture
	unit. The luminace of each texel is derived using the input 
	function as:

	v = func(x * scale, y * scale, z * scale)

	where x, y, z = 0 in the center texel of the texture.
	func(x, y, z) is assumed to always return a value in the 
	range [-1, 1].
	"""
    coords = range(width)
    texel = (ctypes.c_byte * width**3)()
    half = 0  #width * scale / 2.0

    for z in coords:
        for y in coords:
            for x in coords:
                v = snoise3(x * scale - half,
                            y * scale - half,
                            z * scale - half,
                            octaves=4,
                            persistence=0.25)
                texel[x + (y * width) + (z * width**2)] = int(v * 127.0)
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, width, width, 0,
                 GL_LUMINANCE, GL_BYTE, ctypes.byref(texel))
    return texel
Пример #10
0
def create_3d_texture(width, scale):
	"""Create a grayscale 3d texture map with the specified 
	pixel width on each side and load it into the current texture
	unit. The luminace of each texel is derived using the input 
	function as:

	v = func(x * scale, y * scale, z * scale)

	where x, y, z = 0 in the center texel of the texture.
	func(x, y, z) is assumed to always return a value in the 
	range [-1, 1].
	"""
	coords = range(width)
	texel = (ctypes.c_byte * width**3)()
	half = 0 #width * scale / 2.0 

	for z in coords:
		for y in coords:
			for x in coords:
				v = snoise3(x * scale - half, y * scale - half, z * scale - half, octaves=4, persistence=0.25)
				texel[x + (y * width) + (z * width**2)] = int(v * 127.0)
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
	glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, width, width, width, 0, 
		GL_LUMINANCE, GL_BYTE, ctypes.byref(texel))
	return texel
Пример #11
0
def generate_noise(x, y=0, z=None, w=None, scale=1, offset_x=0.0, offset_y=0.0,
                   octaves=1, persistence=0.5, lacunarity=2.0):
    """Generate simplex noise.

    :param x: The x coordinate of the noise value
    :param y: The y coordinate of the noise value
    :param z: The z coordinate of the noise value
    :param w: A fourth dimensional coordinate
    :param scale: The scale of the base plane
    :param float offset_x: How much to offset `x` by on the base plane
    :param float offset_y: How much to offset `y` by on the base plane
    :param int octaves: The number of passes to make calculating noise
    :param float persistence: The amplitude multiplier per octave
    :param float lacunarity: The frequency multiplier per octave

    """
    x = (x + offset_x) / scale
    y = (y + offset_y) / scale
    if z is not None:
        z /= scale
    if w is not None:
        w /= scale
    if z is None and w is None:
        return noise.snoise2(x, y, octaves=octaves,
                             lacunarity=lacunarity,
                             persistence=persistence)
    elif w is None:
        return noise.snoise3(x, y, z, octaves=octaves,
                             lacunarity=lacunarity,
                             persistence=persistence)
    else:
        return noise.snoise4(x, y, z, w, octaves=octaves,
                             lacunarity=lacunarity,
                             persistence=persistence)
Пример #12
0
 def block_exists(avgY, x, y, z):
     return noise.snoise3(x/8.0, y/8.0, z/8.0, 10) > 0.05
     thresh = math.sin(x / 8.0 * 3.1415 + 3.1415/2)*1.5
     thresh += math.sin(z / 8.0 * 3.1415 + 3.1415/2)*1.5
     thresh = thresh / 2 + avgY
     return random.randint(0, 100) > 75
     return y < thresh
Пример #13
0
    def generate_height_map(self, dimensions, seed_val):
        """
        Generates a height map in the form of a MuxMap with nothing but clear
        hexes and water.

        :keyword tuple dimensions: A (width, height) tuple that determines the
            dimensions of the generated map.
        :param int seed_val: An integer value that serves as the map's seed.
        :rtype: MuxMap
        :returns: A heightmap in the form of a MuxMap.
        """

        max_elev = 1.0 + self.watertable_mod
        land_elev_divisor = max_elev / 9.0

        mmap = MuxMap(dimensions=dimensions)
        for y in range(0, mmap.get_map_height()):
            for x in range(0, mmap.get_map_width()):
                h = noise.snoise3(
                    x=x / self.frequency,
                    y=y / self.frequency,
                    z=seed_val,
                    octaves=self.octaves,
                )
                elev = self._val_to_elev(h, land_elev_divisor)
                #print "%d,%d -> %d" % (x,y,elev)
                mmap.set_hex_elevation(x, y, elev)
                #print "N%d" %self.map.get_hex_elevation(x, y, )
                #time.sleep(0.01)
        return mmap
Пример #14
0
    def create_from_noise(seed, position):
        matrix = [[0 for _ in range(16)] for _ in range(16)]
        for x in range(16):
            for y in range(16):
                value = (noise.snoise3((position[0] * c.CHUNK_SIZE + x) * 0.01,
                                       (position[1] * c.CHUNK_SIZE + y) * 0.01,
                                       seed,
                                       octaves=8) + 1) / 2
                if value < 0.4:
                    id = 0
                elif value < 0.5:
                    id = 1
                elif value < 0.55:
                    id = 2
                elif value < 0.65:
                    id = 3
                elif value < 0.75:
                    id = 4
                elif value < 0.83:
                    id = 5
                elif value < 1:
                    id = 6

                matrix[y][x] = id

        return Chunk(matrix, position)
Пример #15
0
def snoise2dz(size,
              z,
              scale=0.05,
              octaves=1,
              persistence=0.25,
              lacunarity=2.0):
    """
    z as seeds
    scale이 작을 수록 패턴이 커지는 효과
    """
    import noise
    z_l = len(z)

    data = np.empty((z_l, size[0], size[1]), dtype='float32')
    for iz in range(z_l):
        zvalue = z[iz]
        for y in range(size[0]):
            for x in range(size[1]):
                v = noise.snoise3(x * scale,
                                  y * scale,
                                  zvalue,
                                  octaves=octaves,
                                  persistence=persistence,
                                  lacunarity=lacunarity)
                data[iz, y, x] = v
    data = data * 0.5 + 0.5
    if __debug__:
        assert data.min() >= 0. and data.max() <= 1.0
    return data
Пример #16
0
def make_noises(timesteps, size, time_multiple=1, fix_seed=False):
    """

    Multi-purpose noise generator in (t,x,y)

    Used primarily for generating observations as well as cloud layers

    Parameters
    ----------
    timesteps: int
        length of time dimension
    size: int
        Output size in x and y
    time_multiple: int
        Stretch time effect which essentially removes auto-correlation
        in time. This is useful for example for modelling clouds where
        there may not necessarily be auto-correlation between days...
    fix_seed: bool
        Whether to fix seed to generate the same noise each time
    """
    noises = np.zeros((timesteps, size, size))
    if fix_seed:
        # fix random numbers so that noise appears the same for each run
        np.random.seed(0)
    # choosing some random starting offset for x,y,t
    # so that noise isn't the same every time...
    z0, x0, y0 = np.random.randint(0, 100, size=3)
    for t, z in enumerate(np.linspace(0, 1, timesteps)):
        for i, x in enumerate(np.linspace(0, 1, size)):
            for j, y in enumerate(np.linspace(0, 1, size)):
                # increasign the number of octaves increases the noise...
                noises[t, j, i] = noise.snoise3(x0 + x, y0 + y, z0 + (time_multiple * z), octaves=12)
    return noises
Пример #17
0
    def draw(self, dt):
        if self._mixer.is_onset():
            self._offset_z += self.parameter('beat-color-boost').get()

        angle = self.parameter('angle').get()
        #self._offset_x += dt * self.parameter('speed').get() * math.cos(angle) * 2 * math.pi
        #self._offset_y += dt * self.parameter('speed').get() * math.sin(angle) * 2 * math.pi
        self._offset_x += dt * self.parameter('speed').get()
        self._offset_z += dt * self.parameter('color-speed').get()
        self._offset_z += dt * self._mixer.audio.getSmoothEnergy() * self.parameter('beat-color-boost').get()
        # posterization = self.parameter('resolution').get()

        rotMatrix = np.array([(math.cos(angle), -math.sin(angle)), (math.sin(angle),  math.cos(angle))])
        x,y = rotMatrix.T.dot(self.pixel_locations.T)
        x *= self.parameter('stretch').get()
        x += self._offset_x
        y += self._offset_y
        locations = np.asarray([x,y]).T

        luminance_scale = self.parameter('luminance-scale').get() / 100.0
        brights = np.asarray([snoise3(luminance_scale * location[0], luminance_scale * location[1], self._offset_z, 1, 0.5, 0.5) for location in locations])
        brights = (1.0 + brights) / 2
        brights *= self._luminance_steps
        LS = self.lum_fader.color_cache[np.int_(brights)].T
        luminances = LS[1] + self._mixer.audio.getEnergy() * self.parameter('audio-brightness').get()
        hue_offset = self.parameter('hue-offset').get() + self._mixer.audio.getSmoothEnergy() * self.parameter('audio-hue-offset').get()

        self.setAllHLS(LS[0] + hue_offset, luminances, LS[2])
Пример #18
0
 def test_simplex_3d_range(self):
     from noise import snoise3
     for i in range(-10000, 10000):
         x = i * 0.31
         y = -i * 0.7
         z = i * 0.19
         n = snoise3(x, y, z)
         self.assertTrue(-1.0 <= n <= 1.0, (x, y, z, n))
Пример #19
0
    def get_background(self, clk):
        z = clk * self.__background_speed + self.__z_offset
        

        data = STREAM.read(CHUNK, exception_on_overflow=False)
        wave_data = wave.struct.unpack("%dh" % CHUNK, data)
        np_array_data = np.array(wave_data)
        audio_data = np.abs(np_array_data * window)
        audio_data = audio_data[::int(CHUNK / 64)]
        if self.__smooth:
            audio_data = gaussian_filter1d(audio_data, 1)

        max_ = max(audio_data)

        # if max_ < 20.0:
           # return img

        norm2 = plt.Normalize(0, max_)
       # self.__audio_data = gaussian_filter1d(16 * norm2(audio_data), 1)
       

        audio_data = 16 * norm2(audio_data)

        


       

        for y in range(self.screen_height):
            for x in range(self.screen_width):
                if 16 - y > audio_data[x]:
                   self.__bw[y][x] = int(snoise3(y / self.__freq, y / self.__freq, z / self.__freq, self.__octaves) * 0)
                else:
                   self.__bw[y][x] = int(snoise3(y / self.__freq, y / self.__freq, z / self.__freq, self.__octaves) * 127.0 + 128.0)

        rgb = gradients[self.__curr_gradient](norm(self.__bw))
        img_array = np.uint8(rgb * 255 * self.background_brightness)

        for y in range(self.screen_height):
            for x in range(self.screen_width):
                if 16 - y > audio_data[x]:
                    img_array[y][x] *= 0

        img = Image.fromarray(img_array).convert('RGB')

        return img
Пример #20
0
 def test_simplex_3d_range(self):
     from noise import snoise3
     for i in range(-10000, 10000):
         x = i * 0.31
         y = -i * 0.7
         z = i * 0.19
         n = snoise3(x, y, z)
         self.assertTrue(-1.0 <= n <= 1.0, (x, y, z, n))
Пример #21
0
 def test_simplex_3d_octaves_range(self):
     from noise import snoise3
     for i in range(-1000, 1000):
         x = -i * 0.12
         y = i * 0.55
         z = i * 0.34
         for o in range(10):
             n = snoise3(x, y, z, octaves=o + 1)
             self.assertTrue(-1.0 <= n <= 1.0, (x, y, z, o + 1, n))
def main(
        output_path,
        size,
        noise_offset,
        noise_scale,
        min_persistence,
        max_persistence,
        ):
    import numpy as np
    import nibabel as nib
    from tqdm import trange
    from noise import snoise3

    """
    Original JavaScript code:

    let center = createVector(width/2, height/2);
    let maxd = center.mag();
    for (let i = 0; i < height; i++) {
        for (let j = 0; j < width; j++) {
            let p = createVector(j, i);
            let d = dist(p.x, p.y, center.x, center.y);
            persistence = map(d, 0, maxd, 0.01, 0.6);
            noiseDetail(octaves, persistence);
            let noiseVal = noise(noiseOffset + j * noiseScaleX, noiseOffset + i * noiseScaleY);
            noiseVal -= intensityOffset;
            noiseVal = constrain(noiseVal, 0, 1);
            let intensity = map(noiseVal, 0, 1, 0, 255);
            intensity = constrain(intensity, 0, 255);
            set(j, i, intensity);
        }
    }
    """
    output_size = si, sj, sk = 3 * [size]
    output = np.empty(output_size, np.float32)
    center = np.array(output_size) / 2
    maxd = np.linalg.norm(center)
    for i in trange(si):
        for j in range(sj):
            for k in range(sk):
                p = np.array((i, j, k))
                d = get_distance(p, center)
                persistence = map(d, 0, maxd, min_persistence, max_persistence)
                noise_val = snoise3(
                    noise_offset + k * noise_scale,
                    noise_offset + j * noise_scale,
                    noise_offset + i * noise_scale,
                    octaves=4,
                    persistence=persistence,
                )
                noise_val = (noise_val + 1) / 2  # [0, 1]
                output[i, j, k] = noise_val
    affine = np.eye(4)
    affine[:3, 3] = -center
    nii = nib.Nifti1Image(output, affine)
    nii.to_filename(output_path)
    return 0
Пример #23
0
 def get_biome(self, x, y):
     biomes = tuple(b for b in BIOMES.keys())
     values = []
     for i, b in enumerate(biomes, 1):
         magnitude = self.magnitude
         v = noise.snoise3(x * magnitude, y * magnitude, self.seed+i, octaves=self.octaves)
         values.append(v)
     i = values.index(max(values))
     return biomes[i]
Пример #24
0
def noise3(point, scale, persistence=.5, lacunarity=2, octaves=2):
    x, y, z = point
    scalex, scaley, scalez = scale
    return noise.snoise3(x / scalex,
                         y / scaley,
                         z / scalez,
                         persistence=persistence,
                         lacunarity=lacunarity,
                         octaves=octaves)
Пример #25
0
 def test_simplex_3d_octaves_range(self):
     from noise import snoise3
     for i in range(-1000, 1000):
         x = -i * 0.12
         y = i * 0.55
         z = i * 0.34
         for o in range(10):
             n = snoise3(x, y, z, octaves=o + 1)
             self.assertTrue(-1.0 <= n <= 1.0, (x, y, z, o+1, n))
Пример #26
0
def make_noise(vsize, freq=16.0, octaves=4, persistence=0.5, lacunarity=2.0):
    result = np.zeros(vsize)
    octaves = 8
    freq = freq * octaves
    for i in range(vsize[0]):
        for j in range(vsize[1]):
            for k in range(vsize[2]):
                result[i,j,k] = noise.snoise3(i/freq, j/freq, k/freq, octaves=octaves, persistence=persistence, lacunarity=lacunarity)
    return result
Пример #27
0
def generate_noise(x,
                   y,
                   scale=1,
                   seed=0,
                   offset_x=0.0,
                   offset_y=0.0,
                   octaves=1,
                   persistence=0.5,
                   lacunarity=2.0,
                   repeat_x=None,
                   repeat_y=None):
    """Generate simplex noise.

    :param x: The x coordinate of the noise value
    :param y: The y coordinate of the noise value
    :param scale: The scale of the base plane
    :param seed: A third dimensional coordinate to use as a seed
    :param float offset_x: How much to offset `x` by on the base plane
    :param float offset_y: How much to offset `y` by on the base plane
    :param int octaves: The number of passes to make calculating noise
    :param float persistence: The amplitude multiplier per octave
    :param float lacunarity: The frequency multiplier per octave
    :param repeat_x: The width of a block of noise to repeat
    :param repeat_y: The height of a block of noise to repeat

    """
    noise_x = (x / scale) + offset_x
    noise_y = (y / scale) + offset_y
    if repeat_x is not None and repeat_y is not None:
        return snoise3(noise_x,
                       noise_y,
                       seed,
                       octaves=octaves,
                       lacunarity=lacunarity,
                       persistence=persistence,
                       repeatx=repeat_x,
                       repeaty=repeat_y)
    else:
        return snoise3(noise_x,
                       noise_y,
                       seed,
                       octaves=octaves,
                       lacunarity=lacunarity,
                       persistence=persistence)
Пример #28
0
def generate(size, seed, type):
    width = size
    height = round(size / 2)
    freq = 1
    octaves = 10
    persistence = 0.5
    lacunarity = 2.0
    tex = Image.new('RGB', (width, height))
    spec = Image.new('RGB', (width, height))
    scale = 5
    latitudes = [
        lat / scale for lat in range(int(-90 * scale),
                                     int(90 * scale) + 1)
    ]
    longitudes = [
        lng / scale for lng in range(int(-180 * scale),
                                     int(180 * scale) + 1)
    ]
    radius = height / pi
    lng_std = 0
    lat_std = 0
    if seed == '':
        rand = randint(-20000, 20000)
    else:
        rand = eval(seed)
    for x, y in product(range(width), range(height)):
        uvx = x / width
        uvy = y / height
        my = sin(uvy * pi - pi / 2)
        mx = cos(uvx * 2 * pi) * cos(uvy * pi - pi / 2)
        mz = sin(uvx * 2 * pi) * cos(uvy * pi - pi / 2)
        z = noise.snoise3((mx + rand) / freq, (my + rand) / freq,
                          mz / freq,
                          octaves=octaves,
                          persistence=persistence,
                          lacunarity=lacunarity)
        z_normalized = (z + 1) / 2
        if type == 'Surface':
            color_a = (int(z_normalized * eval(values['LandR'])),
                       int(z_normalized * eval(values['LandG'])),
                       int(z_normalized * eval(values['LandB'])))
            color_b = (eval(values['OceanR']), eval(values['OceanG']),
                       eval(values['OceanB']))
        if type == 'Bump':
            color_a = (int(z_normalized * 200), int(z_normalized * 200),
                       int(z_normalized * 200))
            color_b = (0, 0, 0)
        if type == 'Specular':
            color_a = (0, 0, 0)
            color_b = (255, 255, 255)
        if z_normalized > eval(values['OceanLevel']):
            color = color_a
        else:
            color = color_b
        tex.putpixel((x, y), color)
    return tex
Пример #29
0
def crackle(vertices, amount=0.1,scale=1):
  for i in xrange(len(vertices)):
    l = np.linalg.norm(vertices[i])
    vertices[i] /= l
    l+= np.arctan(noise.snoise3(
      vertices[i][0]*scale/10,
      vertices[i][1]*scale,
      vertices[i][2]*scale/10,
      )*100)*amount
    vertices[i] *= l
Пример #30
0
def simple_noise(point, divider=5, **kwargs):
    """
    
    :param pyworld.utils.position.Point point: 
    :param divider: for the result of noise function
    :param kwargs: passed to `noise.snoise3`
    :return: 
    """
    abs_coords = (abs(point.x), abs(point.y))
    return noise.snoise3(point.x, point.y, random.randint(min(abs_coords), max(abs_coords)), **kwargs) / divider
Пример #31
0
def snoise3(x,
            y=None,
            z=None,
            octaves=1,
            gain=0.5,
            lacunarity=2,
            amp=1,
            repeat=1):
    if y is not None:
        return amp * fit_11_to_01(
            noise.snoise3(x * repeat, y * repeat, z * repeat, octaves, gain,
                          lacunarity))
    else:
        r = np.empty((len(x), ), dtype=np.float64)
        for i, d in enumerate(x):
            r[i] = amp * fit_11_to_01(
                noise.snoise3(d[0] * repeat, d[1] * repeat, d[2] * repeat,
                              octaves, gain, lacunarity))
        return r
Пример #32
0
def generate_noise(
    x,
    y,
    scale=1,
    seed=0,
    offset_x=0.0,
    offset_y=0.0,
    octaves=1,
    persistence=0.5,
    lacunarity=2.0,
    repeat_x=None,
    repeat_y=None,
):
    """Generate simplex noise.

    :param x: The x coordinate of the noise value
    :param y: The y coordinate of the noise value
    :param scale: The scale of the base plane
    :param seed: A third dimensional coordinate to use as a seed
    :param float offset_x: How much to offset `x` by on the base plane
    :param float offset_y: How much to offset `y` by on the base plane
    :param int octaves: The number of passes to make calculating noise
    :param float persistence: The amplitude multiplier per octave
    :param float lacunarity: The frequency multiplier per octave
    :param repeat_x: The width of a block of noise to repeat
    :param repeat_y: The height of a block of noise to repeat

    """
    noise_x = (x / scale) + offset_x
    noise_y = (y / scale) + offset_y
    if repeat_x is not None and repeat_y is not None:
        return snoise3(
            noise_x,
            noise_y,
            seed,
            octaves=octaves,
            lacunarity=lacunarity,
            persistence=persistence,
            repeatx=repeat_x,
            repeaty=repeat_y,
        )
    else:
        return snoise3(noise_x, noise_y, seed, octaves=octaves, lacunarity=lacunarity, persistence=persistence)
Пример #33
0
def simplex_noise_2d(x, y, seed=0, octaves=1, freq_ratio=16.0) -> float:
    """
    Create simplex noise between 0 and 1
    :param seed: seed to use
    :param octaves: higher number makes the noise smoother
    :param freq_ratio: how often to sample as the ratio changes
    :return: float between 0 and 1
    """
    freq = octaves * freq_ratio
    return (noise.snoise3(seed, x / freq, y / freq, octaves) + 1) / 2
Пример #34
0
def get_noise(x_pos, y_pos, z_pos):
    if (settings.NOISE_TYPE == 1):
        return noise.pnoise3(
            RAND_X_OFFSET +
            (x_pos / settings.WINDOW_WIDTH * settings.SCALE), RAND_Y_OFFSET +
            (y_pos / settings.WINDOW_HEIGHT * settings.SCALE), z_pos) + 1
    elif (settings.NOISE_TYPE == 2):
        return noise.snoise3(
            RAND_X_OFFSET +
            (x_pos / settings.WINDOW_WIDTH * settings.SCALE), RAND_Y_OFFSET +
            (y_pos / settings.WINDOW_HEIGHT * settings.SCALE), z_pos) + 1
Пример #35
0
    def get(self, start, end, progress):
        for pixel, loc in enumerate(self.pixel_locations):
            blend = (1.0 + snoise3(0.01 * loc[0], 0.01 * loc[1], progress, 1, 0.5, 0.5)) / 2.0
            self.frame[pixel] = blend * start[pixel] + ((1.0 - blend) * end[pixel])

        # Mix = 1.0 when progress = 0.5, 0.0 at either extreme
        mix = 1.0 - fabs(2.0 * (progress - 0.5))

        if progress < 0.5:
            return ((1.0 - mix) * start) + (mix * self.frame)
        else:
            return (mix * self.frame) + ((1.0 - mix) * end)
Пример #36
0
def init_terrain():
    global chunk_density
    chunk_density = numpy.zeros((chunk_size, height_offset, chunk_size), dtype=numpy.float32)

    for sx in range(chunk_size):
        for sy in range(height_offset):
            for sz in range(chunk_size):
                chunk_density.itemset((sx, sy, sz), noise.snoise3(sx / 10, sy / 10, sz / 10))

    chunks[(0, 0)] = Chunk((0, 0))
    chunks[(0, 0)].generate()
    chunks[(0, 0)].mesh()
Пример #37
0
def simple_noise(point, divider=5, **kwargs):
    """
    
    :param pyworld.utils.position.Point point: 
    :param divider: for the result of noise function
    :param kwargs: passed to `noise.snoise3`
    :return: 
    """
    abs_coords = (abs(point.x), abs(point.y))
    return noise.snoise3(point.x, point.y,
                         random.randint(min(abs_coords), max(abs_coords)), **
                         kwargs) / divider
Пример #38
0
def make_noise():
    vertices_data = []
    colours_data = []
    size = 200
    seed = 5
    octaves = 5
    for x, y in itertools.product(range(size * 2), range(size * 2)):
        vertices_data.append(tuple((x, y)))
        colours_data.append(noise.snoise3(seed, x, y, octaves))
        vertices_data.append(tuple((x, y + 1)))
        colours_data.append(noise.snoise3(seed, x, y + 1, octaves))
        vertices_data.append(tuple((x + 1, y)))
        colours_data.append(noise.snoise3(seed, x + 1, y, octaves))

        vertices_data.append(tuple((x + 1, y + 1)))
        colours_data.append(noise.snoise3(seed, x + 1, y + 1, octaves))
        vertices_data.append(tuple((x + 1, y)))
        colours_data.append(noise.snoise3(seed, x + 1, y, octaves))
        vertices_data.append(tuple((x, y + 1)))
        colours_data.append(noise.snoise3(seed, x, y + 1, octaves))

    vertices = np.array([
        tuple(((v[0] - size) / size, (v[1] - size) / size))
        for v in vertices_data
    ]).astype(np.float32)
    colours = np.array(colours_data).astype(np.float32)
Пример #39
0
def randomize1(z, threshold, normal):
    # controller.clearScreen()
    # z = 1
    global curr
    # curr = [ [ [0, 0, 0]  for y in range(height)] for x in range(width)]
    for y in range(width):
        for x in range(height):
            r = 128.0 + 127.0 * (snoise3(x * scale,
                                         y * scale,
                                         start + z * zScale,
                                         octaves=1,
                                         persistence=per))
            g = 128.0 + 127.0 * (snoise3(x * scale + dist,
                                         y * scale + dist,
                                         start + z * zScale,
                                         octaves=1,
                                         persistence=per))
            b = 128.0 + 127.0 * (snoise3(x * scale - dist,
                                         y * scale - dist,
                                         start + z * zScale,
                                         octaves=1,
                                         persistence=per))
            if (normal):
                curr[x][y][0] = r
                curr[x][y][1] = g
                curr[x][y][2] = b
            if r > 255 * threshold or g > 255 * threshold or \
            b > 255 * threshold:
                if normal:
                    curr[x][y][3] = 1
                    controller.setPixel(x, y, r, g, b)
                else:
                    # print(curr[x][y], curr[x][y] == [0, 0, 0])
                    if curr[x][y][3] == 0:
                        curr[x][y][3] = 1
                        controller.setPixel(x, y, curr[x][y][0], curr[x][y][1],
                                            curr[x][y][2])
                    else:
                        curr[x][y][3] = 0
                        controller.setPixel(x, y, 0, 0, 0)
Пример #40
0
    def generate_surface(self, chunk_x, chunk_z):
        real_pos_x = chunk_x*16
        real_pos_z = chunk_z*16

        if (real_pos_x, real_pos_z) not in self.surface:
            octaves = 10
            freq = 16.0 * octaves
            scale = 5

            for x in xrange(real_pos_x, real_pos_x + 16):
                for z in xrange(real_pos_z, real_pos_z + 16):
                    point = int((noise.snoise3(x / freq, z / freq, self.seed, octaves) * 127.0 + 128.0)/scale)
                    self.surface[(x, z)] = point
    def update(self, *args, **kwargs) -> None:
        new_noise = np.zeros(self.noise.shape)
        for y in range(new_noise.shape[0]):
            y_shift = self.palette.scale * y
            for x in range(new_noise.shape[1]):
                x_shift = self.palette.scale * x
                new_noise[y][x] = snoise3(self.x + x_shift, self.y + y_shift, self.z) * 0.5 + 0.5

        self.noise = (1 - self.palette.smoothing) * new_noise + self.palette.smoothing * self.noise

        self.x += self.palette.speed / 8
        self.y -= self.palette.speed / 16
        self.z += self.palette.speed / 4
Пример #42
0
    def map_angle(x_in: float, y_in: float) -> float:
        a0 = 30 * math.pi / 180
        f0 = 0.009

        c = total_x

        phi = x_in / c * 2 * math.pi
        r = c / (2 * math.pi)

        x = r * math.cos(phi)
        y = r * math.cos(phi)
        z = y_in

        return a0 * noise.snoise3(
            f0 * x,
            f0 * y,
            f0 * z,
        ) + 0.25 * a0 * noise.snoise3(
            2 * f0 * x + 1000,
            2 * f0 * y + 1000,
            2 * f0 * z + 1000,
        ) + 0.0 * a0 * (random.random() - 0.5)
Пример #43
0
    def update_map(self, center):
        self.offset = [
            center[0] - self.size[0] // 2, center[1] - self.size[1] // 2
        ]

        for i in range(self.size[1]):
            for j in range(self.size[0]):
                self.tile_map[j][i] = int(
                    noise.snoise3(
                        (i + self.offset[1]) / 48,
                        (j + self.offset[0]) / 48, self.seed * 255, 4) * 3 + 2)
                self.collision_map[j][i] = 0 if (
                    self.tile_map[j][i] in global_consts.PASSABLE_TILES) else 1
Пример #44
0
 def get_terrain_type(self, x, y):
     biome = self.get_biome(x, y)
     terrains = tuple(t[0] for t in BIOMES[biome])
     biomes_mods = tuple(t[1] for t in BIOMES[biome])
     biomes_mags = tuple(t[2] for t in BIOMES[biome])
     values = []
     for i, b in enumerate(terrains):
         magnitude = self.magnitude * biomes_mags[i]
         v = noise.snoise3(x * magnitude, y * magnitude, self.seed+b+10, octaves=self.octaves)
         v = v * .5 + .5
         values.append(v * biomes_mods[i])
     i = values.index(max(values))
     return terrains[i]
    def build_moisture_map(self):
        size = len(self.fullMap)
        seed = random.randint(0,1000000)
        logging.info('Using seed = ' + str(seed) + ' for humidity map generation.')

        for y in range(size):
            for x in range(size):
                v = snoise3(x / 33.0, y / 33.0, seed, 3, 0.27, 4.0)
                #v is [-1, 1] so adding 1 makes it [0,2]
                #We need to select between 3 different humidities so we need to make it [0,3)
                #That is why we subtract 0.000001
                v = ((v + 1.0)* 3.0 / 2.0) - 0.000001
                self.moisture_map[x][y] = v
Пример #46
0
def generate_rainfall_from_temperature(nodes):
    from everett.features.climate import whittaker
    import noise
    for node in nodes:
        temperature_to_consider = node.get_feature(['surface', 'temperature'])
        min_rainfall, max_rainfall = whittaker.rainfall_range(temperature_to_consider)
        if min_rainfall is None or max_rainfall is None:
            node.set_feature(['precipitation', 'mm'], 0.0)
        else:
            # noise_point = 0.5*(noise.pnoise2(b.longitude/180.0, b.latitude/90.0) + 1.0)
            # noise_point = random.uniform(0.0, 1.0)
            noise_point = 0.5*(1.0+noise.snoise3(node.x, node.y, node.z))
            node.set_feature(['precipitation', 'mm'], (noise_point * (max_rainfall - min_rainfall) + min_rainfall))
Пример #47
0
    def get(self, start, end, progress):
        for pixel, loc in self.pixel_locations:
            blend = (1.0 + snoise3(0.01 * loc[0], 0.01 * loc[1], progress, 1, 0.5, 0.5)) / 2.0
            a, b = self.pixel_addr[pixel]
            self.frame[a][b] = blend * start[a][b] + ((1.0 - blend) * end[a][b])

        # Mix = 1.0 when progress = 0.5, 0.0 at either extreme
        mix = 1.0 - fabs(2.0 * (progress - 0.5))

        if progress < 0.5:
            return ((1.0 - mix) * start) + (mix * self.frame)
        else:
            return (mix * self.frame) + ((1.0 - mix) * end)
Пример #48
0
 def draw(self, dt):
     delta = dt * self.speed
     d3 = self.color_speed * dt
     posterization = self.parameter('resolution').get()
     setp = self.setp
     
     for pixel, location in self.pixel_locations:
         hue = (1.0 + snoise3(self.scale * (location[0] + delta), self.scale * (location[1] + delta), d3, 1, 0.5, 0.5)) / 2.0
         hue = self.hue_min + ((math.floor(hue * posterization) / posterization) * (self.hue_max - self.hue_min))
         
         brightness = (1.0 + snoise3(self.luminance_scale * (location[0] + delta), self.luminance_scale * (location[1] + delta), d3, 1, 0.5, 0.5)) / 2.0
         
         if brightness > self.parameter('whiteout').get():
             saturation = (brightness - self.parameter('whiteout').get()) / (1 - self.parameter('whiteout').get()) * 2
             if saturation > 1.0: saturation = 1.0
             saturation = math.floor(saturation * posterization) / posterization
             brightness = 1.0
         else:
             saturation = 1.0
         
         brightness = 0 if brightness < self.parameter('blackout').get() else 1.0
         
         setp(pixel, hsv_float_to_rgb_uint8((hue, saturation, brightness)))                    
    def build_temperature_map(self):
        size = len(self.fullMap)
        seed = random.randint(0,1000000)
        logging.info('Using seed = ' + str(seed) + ' for temperature map generation.')

        for y in range(size):
            for x in range(size):
                v = snoise3(x / 15.0, y / 15.0, seed, 5, 0.25, 4.0)
                v = (v + 1)/2.0
                #The larger the value the closer it is to the middle of the map
                distanceFromCenterY = abs(y - (size/2.0))
                v = (v * 0.5) + 0.5

                yScore = (v) * (size*(3/5) - distanceFromCenterY)

                #Each square goes from [0,255] depending on temperature
                self.temperature_map[x][y] = yScore * 255.0/(size*(3/5))
Пример #50
0
    def generate(self):
        for sx in range(chunk_size):
            x = sx + self.cx * chunk_size

            for sz in range(chunk_size):
                z = sz + self.cz * chunk_size

                height = round((noise.snoise3(x / zoom, z / zoom, seed, octaves=3) + 1) / 2 * chunk_height) + height_offset
                block_id = None

                if 114 <= height:
                    block_id = 1

                elif 90 <= height < 114:
                    block_id = 2

                elif 82 <= height < 90:
                    block_id = 3

                elif height < 82:
                    block_id = 4

                for y in range(height - 2, height + 1):
                    self.blocks.add((sx, y, sz))

                if block_id == 2:
                    self.block_map[sx, height, sz] = 2
                    self.block_map[sx, height - 4:height, sz] = 8
                else:
                    self.block_map[sx, height - 4:height + 1, sz] = block_id

                self.block_map[sx, 1:height - 4, sz] = 5
                self.block_map[sx, 0, sz] = 7

        if self.add_blocks is not None:
            for block, value in self.add_blocks.items():
                self.block_map.itemset(block, value)
                self.blocks.add(block)

        if self.remove_blocks is not None:
            for block in self.remove_blocks:
                self.block_map.itemset(block, 0)
                self.blocks.discard(block)
Пример #51
0
    def modify_map(self, seed_val, mmap):
        """
        :param float seed_val: An value between 0.0 and 1.0 that serves as the
            map's seed. This gets passed to the heightmap and all modifiers.
        :param MuxMap mmap: The map to modify.
        """

        modded_seed = self._get_modified_seed_val(seed_val, self.seed_modifier)

        for y in range(0, mmap.get_map_height()):
            for x in range(0, mmap.get_map_width()):
                if mmap.terrain_list[y][x] in self.NOTOUCH_TERRAINS:
                    continue
                if mmap.elevation_list[y][x] < self.minimum_elevation:
                    continue
                h = noise.snoise3(
                    x=x / self.frequency,
                    y=y / self.frequency,
                    z=modded_seed,
                    octaves=self.octaves,
                )
                if h > self.mountain_thresh:
                    mmap.set_hex_terrain(x, y, '^')
Пример #52
0
def make_noise():
    vertices_data = []
    colours_data = []
    size = 200
    seed = 5
    octaves = 5
    for x, y in itertools.product(range(size * 2), range(size * 2)):
        vertices_data.append(tuple((x, y)))
        colours_data.append(noise.snoise3(seed, x, y, octaves))
        vertices_data.append(tuple((x, y + 1)))
        colours_data.append(noise.snoise3(seed, x, y + 1, octaves))
        vertices_data.append(tuple((x + 1, y)))
        colours_data.append(noise.snoise3(seed, x + 1, y, octaves))

        vertices_data.append(tuple((x + 1, y + 1)))
        colours_data.append(noise.snoise3(seed, x + 1, y + 1, octaves))
        vertices_data.append(tuple((x + 1, y)))
        colours_data.append(noise.snoise3(seed, x + 1, y, octaves))
        vertices_data.append(tuple((x, y + 1)))
        colours_data.append(noise.snoise3(seed, x, y + 1, octaves))

    vertices = np.array([tuple(((v[0] - size) / size, (v[1] - size) / size)) for v in vertices_data]).astype(np.float32)
    colours = np.array(colours_data).astype(np.float32)
Пример #53
0
def simplex3(octaves, persistence, scale, x, y, z):
    return noise.snoise3(x, y, z, octaves, persistence, scale)
    return cosine_interpolation(0, 255, noise.snoise2(x, y, octaves, persistence, scale))
Пример #54
0
#!/usr/bin/env python
import time
import math
import mxp
from noise import snoise3

mtx = mxp.Matrix()

t = 0
while True:
	t = t + 0.02
	for x in range(10):
		for y in range(10):
			color = [0, 0, 0]
			seed = snoise3(x / 15 + math.sin(t/3), y / 15 + math.cos(t/3), t/10) * math.pi * 2
			color[0] = int((math.sin(seed) + 1) * 127)
			color[1] = int((math.sin(seed + 2/3 * math.pi) + 1) * 127)
			color[2] = int((math.sin(seed + 4/3 * math.pi) + 1) * 127)
			mtx.setPixel(x, y, color)
	mtx.flip()
	time.sleep(0.01)
Пример #55
0
def f(x, y, colour, r, iterations):
	return colour(noise.snoise3(r*math.sin(2 * math.pi * x/C), r*math.cos(2 * math.pi * x/C), float(y)/R, iterations))
Пример #56
0
import numpy as np
import noise
# help(noise)
import minecraft

width = 250
solids = []

solidity = np.zeros([width] * 3).astype(np.int32)

for x in range(width):
    for y in range(width):
        for z in range(width):
            scale = .05
            p = noise.snoise3(x * scale,y* scale,z* scale, octaves=1, persistence=.5, lacunarity=2.0)
            if p > 0:
                solids.append((x,y,z, 1))
                solidity[x,y,z] = 1

all_patterns = set([])
for x in range(0, width - 2, 3):
    for y in range(0, width - 2, 3):
        for z in range(0, width - 2, 3):
            all_patterns.add(tuple(solidity[x:x+3, y:y+3, z:z+3].flatten()))


# print len(all_patterns), "/", (width - 2) ** 3
# print 1.0 * len(all_patterns) / (width - 2) ** 3
# minecraft.main(solid = solids)

all_patterns = list(all_patterns)
Пример #57
0
def get_height(x, z):
    return round((noise.snoise3(x / zoom, z / zoom, seed, octaves=3) + 1) / 2 * chunk_height) + height_offset
Пример #58
0
#!/usr/bin/env python
import time
import math
import mxp
from noise import snoise3

mtx = mxp.Matrix()

t = 0
while True:
	t = t + 0.02
	for x in range(10):
		for y in range(10):
			color = [0, 0, 0]
			newx = x / 8 + math.sin(t / 2)
			newy = y / 8 + math.cos(t / 2)
			color[2] = int(snoise3(newx,		newy, t/3) * 127 + 128)
			color[0] = int(snoise3(newx + 15,	newy, t/5) * 127 + 128)
			color[1] = int(snoise3(newx + 30,	newy, t/7) * 127 + 128)
			mtx.setPixel(x, y, color)
	mtx.flip()
	time.sleep(0.01)