-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
82 lines (73 loc) · 2.08 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from biome import Biome, HeightMapBiome
from fastapi import FastAPI
from heightmap import HeightMap
from io import BytesIO
from moisturemap import MoistureMap
from noiserange import NoiseRange
from fastapi.responses import Response
app = FastAPI()
@app.get("/{width}/{height}/{scale}/{tile_size}")
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"
)