-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_generator.py
More file actions
46 lines (40 loc) · 1.34 KB
/
map_generator.py
File metadata and controls
46 lines (40 loc) · 1.34 KB
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
import numpy as np
from noise import pnoise2
import matplotlib.pyplot as plt
import csv # Import the csv module
# Settings for the noise map
width = 30
height = 30
scale = 0.1 # Scale of the noise
octaves = 6 # Number of octaves
persistence = 0.5
lacunarity = 2.0
seed = np.random.randint(0, 100)
# Generate the noise map
noise_map = np.zeros((height, width))
for y in range(height):
for x in range(width):
noise_value = pnoise2(x * scale,
y * scale,
octaves=octaves,
persistence=persistence,
lacunarity=lacunarity,
repeatx=width,
repeaty=height,
base=seed)
noise_map[y][x] = noise_value
# Display the noise map using matplotlib
# plt.figure(figsize=(8, 8))
# plt.imshow(noise_map, cmap='gray')
# plt.colorbar()
# plt.title('50x50 Perlin Noise Map')
# plt.show()
# Normalize the noise map
noise_map = (noise_map - np.min(noise_map)) / (np.max(noise_map) - np.min(noise_map))
# Save the noise map to a CSV file
with open('noise_map.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for row in noise_map:
writer.writerow(row)
# Print message when done
print("Noise map has been saved to 'noise_map.csv'")