Exemple #1
0
def CreateWorldRGB(N, M, seed=None, sea_level=0.45, biome_table_name=None):
    '''
    Create two heightmaps and return RGB 2D-matrix.
    seed - world seed. None if random.
    sea_level - limit of water.
    biome_table_name - name of .csv file with colors
    '''

    map_power = max(TwoPower(N), TwoPower(M))
    biome_table, water_color = LoadBiomeTable(biome_table_name)

    phys_map = HeightMap(map_power, seed)[:N, :M]
    humid_map = HeightMap(map_power,
                          None if seed is None else seed + 1)[:N, :M]

    phys_ind = ((phys_map-sea_level) / (1-sea_level) *
                biome_table.shape[0]).astype(int) - \
        (phys_map == 1.0)

    humid_ind = (humid_map * biome_table.shape[1]).astype(int) - \
        (humid_map == 1.0)

    RGB_map = biome_table[phys_ind, humid_ind]
    RGB_map[phys_map < sea_level] = water_color

    return RGB_map
def main():
    parser = register_parsers()
    args = parser.parse_args()

    x_offset = int(random.random() *
                   pow(10, 3) if args.random else args.x_offset)
    y_offset = int(random.random() *
                   pow(10, 3) if args.random else args.y_offset)

    noise_ranges = [
        NoiseRange('peak', args.peak),
        NoiseRange('mountain', args.mountain),
        NoiseRange('land', args.land),
        NoiseRange('sand', args.sand),
        NoiseRange('shore', args.shore),
        NoiseRange('water', args.water),
    ]

    height_map = HeightMap(
        width=args.width,
        height=args.height,
        noise_ranges=noise_ranges,
        scale=args.scale,
        octaves=args.octaves,
        persistence=args.persistence,
        lacunarity=args.lacunarity,
        x_offset=x_offset,
        y_offset=y_offset,
        base_x_offset=args.base_x_offset,
        base_y_offset=args.base_y_offset,
    )

    moisture_map = MoistureMap(
        width=args.width,
        height=args.height,
        noise_ranges=[],  # dont specify noise ranges
        scale=args.scale,
        octaves=args.octaves,
        persistence=args.persistence,
        lacunarity=args.lacunarity,
        x_offset=x_offset,
        y_offset=y_offset,
        base_x_offset=args.base_x_offset,
        base_y_offset=args.base_y_offset,
    )

    height_map.moisturize(moisture_map)

    height_map.draw_image(args.tilesize)

    if not args.save:
        height_map.show_image()

    if args.save or click.confirm('Save map?', default=False):
        file_name = 'maps/' + args.file

        height_map.save(file_name, indent=4 if args.minify == False else None)

        print('Saved to: %s' % file_name + '.json')
def display_image(width: int,
                  height: int,
                  lacunarity: float = 3.0,
                  octaves: int = 8,
                  persistence: float = 0.5,
                  scale: float = 200,
                  x_offset: float = 0.0,
                  y_offset: float = 0.0,
                  base_x_offset: float = 0.0,
                  base_y_offset: float = 0.0,
                  tile_size: int = 4,
                  waterLevel: float = -0.72,
                  shoreLevel: float = -0.44,
                  sandLevel: float = -0.16,
                  landLevel: float = 0.12,
                  mountainLevel: float = 0.44,
                  peakLevel: float = 0.72,
                  json: bool = False):
    noise_ranges = [
        NoiseRange('peak', peakLevel),
        NoiseRange('mountain', mountainLevel),
        NoiseRange('land', landLevel),
        NoiseRange('sand', sandLevel),
        NoiseRange('shore', shoreLevel),
        NoiseRange('water', waterLevel),
    ]

    height_map = HeightMap(
        width=width,
        height=height,
        noise_ranges=noise_ranges,
        scale=scale,
        octaves=octaves,
        persistence=persistence,
        lacunarity=lacunarity,
        x_offset=x_offset,
        y_offset=y_offset,
        base_x_offset=base_x_offset,
        base_y_offset=base_y_offset,
    )

    moisture_map = MoistureMap(
        width=width,
        height=height,
        noise_ranges=[],  # dont specify noise ranges
        scale=scale,
        octaves=octaves,
        persistence=persistence,
        lacunarity=lacunarity,
        x_offset=x_offset,
        y_offset=y_offset,
        base_x_offset=base_x_offset,
        base_y_offset=base_y_offset,
    )

    height_map.moisturize(moisture_map)
    height_map.draw_image(tile_size)

    if json:
        return height_map.get_json()

    memoryStorage = BytesIO()

    height_map.get_image().save(memoryStorage, format="png")

    return Response(content=memoryStorage.getvalue(), media_type="image/png")
Exemple #4
0
            self.calculate_sea_boundary(landmass) for landmass in landmasses
        ]

        for coastline in coastlines:
            for edge in coastline:
                plt.plot(edge[:, 0], edge[:, 1], 'k-', linewidth=0.3)
        plt.show()
        # TODO: For each landmass, generate polygon

        # TODO: Fractal subdivide and smooth each coast

    def sketch(self):
        self.setup_sketch()
        self.sketch_coastline()
        # plt.show()


if __name__ == "__main__":
    heightmap = HeightMap(2000, sea_level=0.4)
    heightmap.add_global_gradient()
    # heightmap.add_cone()
    for _ in range(10):
        heightmap.add_hill()
    for _ in range(7):
        heightmap.add_hill(valley=True)
    heightmap.simulate_fluvial_erosion()
    heightmap.simulate_fluvial_erosion()
    heightmap.simulate_fluvial_erosion()

    sketcher = Sketcher(heightmap)
    sketcher.sketch()