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")
            x += xdir
            z += zv

        return True

def get_projection_north_deviation(proj, lat, lng):
    x1, y1 = proj(lng, lat - 0.2)
    x2, y2 = proj(lng, lat + 0.2)

    return atan2(x2-x1, y2-y1)

if __name__ == '__main__':
    from sys import argv
    from datetime import datetime
    from heightmap import HeightMap
    from suncalc import solar_position
    from math import sin, cos

    with open(argv[1], 'rb') as f:
        hm = HeightMap.load(f)

    t = datetime.strptime(argv[2], '%Y-%m-%d %H:%M')
    sunpos = solar_position(t, hm.lat, hm.lng)
    dev = get_projection_north_deviation(hm.proj, hm.lat, hm.lng)
    sun_x = -sin(sunpos['azimuth'] - dev) * cos(sunpos['altitude'])
    sun_y = -cos(sunpos['azimuth'] - dev) * cos(sunpos['altitude'])
    sun_z = sin(sunpos['altitude'])

    sm = ShadowMap(hm.lat, hm.lng, hm.resolution, hm.size, hm.proj, sun_x, sun_y, sun_z, hm, 1.5)
    sm.to_image().save(argv[3])
Exemple #5
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()
Exemple #6
0
from PIL import Image, ImageChops, ImageDraw
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("heightmap", type=str, help="Path to heightmap file")
parser.add_argument("start", type=str, help="Start date and time (YYYY-MM-DD HH:MM)")
parser.add_argument("end", type=str, help="End date and time (YYYY-MM-DD HH:MM)")
parser.add_argument("interval", type=int, help="Interval between images in minutes")
parser.add_argument("output_directory", type=str, help="Path to store images in")
parser.add_argument("--background-map", type=str, default=None, help="Path to background map image")
parser.add_argument("--opacity", type=float, default=1, help="Opacity for shadow when overlaid (0-1)")

args = parser.parse_args()

with open(args.heightmap, "rb") as f:
    hm = HeightMap.load(f)

t1 = datetime.strptime(args.start, "%Y-%m-%d %H:%M")
t2 = datetime.strptime(args.end, "%Y-%m-%d %H:%M")
delta = timedelta(minutes=args.interval)

bkg = None
if args.background_map:
    bkg = Image.open(args.background_map).convert("RGB")
    transparency = int(255 - args.opacity * 255)

t = t1
while t <= t2:
    print t.strftime("%Y-%m-%d_%H%M.png"), "..."
    sunpos = solar_position(t, hm.lat, hm.lng)
    dev = get_projection_north_deviation(hm.proj, hm.lat, hm.lng)