def test_noise():
    noise = libtcodpy.noise_new(1)
    libtcodpy.noise_set_type(noise, libtcodpy.NOISE_SIMPLEX)
    libtcodpy.noise_get(noise, [0])
    libtcodpy.noise_get_fbm(noise, [0], 4)
    libtcodpy.noise_get_turbulence(noise, [0], 4)
    libtcodpy.noise_delete(noise)
Example #2
0
def test_noise():
    noise = libtcodpy.noise_new(1)
    libtcodpy.noise_set_type(noise, libtcodpy.NOISE_SIMPLEX)
    libtcodpy.noise_get(noise, [0])
    libtcodpy.noise_get_fbm(noise, [0], 4)
    libtcodpy.noise_get_turbulence(noise, [0], 4)
    libtcodpy.noise_delete(noise)
Example #3
0
 def update_clouds(self, elapsed_time):
     self.cloud_tot_dx += elapsed_time * 5
     self.cloud_dx += elapsed_time * 5
     if self.cloud_dx >= 1.0:
         cols_to_translate = int(self.cloud_dx)
         self.cloud_dx -= cols_to_translate
         for x in range(cols_to_translate, self.width):
             for y in range(0, self.height):
                 self._clouds[x - cols_to_translate, y] = self._clouds[y, x]
     f = [0, 0]
     for x in range(self.width - cols_to_translate, self.width):
         for y in range(0, self.height):
             f[0] = 6.0 * (x + self.cloud_tot_dx) / self.width
             f[1] = 6.0 * y / self.height
             self._clouds[y, x] = 0.5 * (1.0 + 0.8 * tcod.noise_get_fbm(
                 self.noise, f, 4.0, tcod.NOISE_SIMPLEX))
Example #4
0
    def build_base_map(self, hill_cnt=60):
        self.add_land(hill_cnt, 16 * self.width / 200, 0.7, 0.6)
        tcod.heightmap_normalize(self._hm)
        tcod.heightmap_add_fbm(self._hm, noise2d, 2.20 * self.width / 400,
                               2.2 * self.width / 400, 0, 0, 10, 1.0, 2.05)
        tcod.heightmap_normalize(self._hm)
        self._hm2 = self._hm.copy()
        self.set_land_mass(0.6, SAND_HEIGHT)
        # Fix land/mountain ratio using x^3 curve above sea level
        for x in range(self.width):
            for y in range(self.height):
                h = self._hm[y, x]
                if h >= SAND_HEIGHT:
                    coef = (h - SAND_HEIGHT) / (1.0 - SAND_HEIGHT)
                    h = SAND_HEIGHT + coef * coef * coef * (1.0 - SAND_HEIGHT)
                    self._hm[y, x] = h

        f = [0, 0]
        for x in range(self.width):
            f[0] = 6.0 * x / self.width
            for y in range(self.height):
                f[1] = 6.0 * y / self.height
                self._clouds[y, x] = 0.5 * (1.0 + 0.8 * tcod.noise_get_fbm(
                    noise2d, f, 4.0, tcod.NOISE_SIMPLEX))
Example #5
0
    def compute_precipitation(self):
        water_add, slope_coef, base_precip = 0.03, 2.0, 0.01
        # // north/south winds
        for dir_y in [-1, 1]:
            for x in range(self.width - 1):
                noisex = [x * 5 / self.width]
                water_amount = 1.0 + tcod.noise_get_fbm(
                    noise1d, noisex, 3.0, tcod.NOISE_SIMPLEX)
                start_y = self.height - 1 if dir_y == -1 else 0
                end_y = -1 if dir_y == -1 else self.height
                for y in range(start_y, end_y, dir_y):
                    h = self._hm[y, x]
                    if x < SAND_HEIGHT:
                        water_amount += water_add
                    elif water_amount > 0.0:
                        if (y + dir_y) < self.height:
                            slope = self._hm[y + dir_y, x] - h
                        else:
                            slope = h - self._hm[y - dir_y, x]
                        if slope >= 0:
                            precip = water_amount * (base_precip +
                                                     slope * slope_coef)
                            self._precipitation[y, x] += precip
                            water_amount -= precip
                            water_amount = max(0.0, water_amount)

        # east/west winds
        for dir_x in [-1, 1]:
            for y in range(self.height - 1):
                noisey = [y * 5 / self.height]
                water_amount = 1.0 + tcod.noise_get_fbm(
                    noise1d, noisey, 3.0, tcod.NOISE_SIMPLEX)
                start_x = self.width - 1 if dir_x == -1 else 0
                end_x = -1 if dir_x == -1 else self.width
                for x in range(start_x, end_x, dir_x):
                    h = self._hm[y, x]
                    if x < SAND_HEIGHT:
                        water_amount += water_add
                    elif water_amount > 0.0:
                        if (x + dir_x) < self.width:
                            slope = self._hm[y, x + dir_x] - h
                        else:
                            slope = h - self._hm[y, x - dir_x]
                        if slope >= 0:
                            precip = water_amount * (base_precip +
                                                     slope * slope_coef)
                            self._precipitation[y, x] += precip
                            water_amount -= precip
                            water_amount = max(0.0, water_amount)

        fmin, fmax = self._precipitation.min(), self._precipitation.max()
        # latitude impact
        for y in range(self.height // 4, 3 * self.height // 4):
            lat = y - (self.height / 4) * (2 / self.height)
            coef = math.sin(2 * math.pi * lat)
            #     // latitude (0 : equator, -1/1 : pole)
            for x in range(self.width):
                f = [x / self.width, y / self.height]
                xcoef = coef + 0.5 * tcod.noise_get_fbm(
                    noise2d, f, 3.0, tcod.NOISE_SIMPLEX)
                self._precipitation[y, x] += (fmax - fmin) * xcoef * 0.1
        # very fast blur by scaling down and up
        factor = 8
        small_width = int((self.width + factor) / factor)
        small_height = int((self.height + factor) / factor)
        low_res_map = np.zeros((small_width, small_height))
        for x in range(self.width):
            for y in range(self.height):
                v = self._precipitation[y, x]
                ix = int(x / factor)
                iy = int(y / factor)
                low_res_map[ix, iy] += v
        coef = 1.0 / factor
        for x in range(self.width):
            for y in range(self.height):
                v = get_interpolated_float(low_res_map, x * coef, y * coef,
                                           small_width, small_height)
                self._precipitation[y, x] = v