-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeightMapGen.py
37 lines (27 loc) · 1.05 KB
/
HeightMapGen.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
__author__ = 'Ian'
from PIL import Image, ImageChops
from noise import pnoise2, snoise2
import math
def generateNoise(resolution, octaves, frequency):
img = Image.new('RGB', (resolution, resolution), "black")
pixels = img.load()
for x in range(img.size[0]):
for y in range(img.size[1]):
sample = int(snoise2(x / frequency, y / frequency, octaves) * 127 + 128)
color = (sample, sample, sample)
pixels[x, y] = color
return img
def generateRadial(resolution, threshold):
img = Image.new('RGB', (resolution, resolution), "black")
pixels = img.load()
for x in range(img.size[0]):
for y in range(img.size[1]):
color = (255, 255, 255)
distance = math.pow(math.pow(x - 127, 2) + math.pow(y - 127, 2), 0.5)
val = (127 - int(distance)) * threshold
pixels[x, y] = (val, val, val)
return img
noise = generateNoise(255, 5, 80.0)
grad = generateRadial(255, 4)
heightMap = ImageChops.subtract(grad, noise)
heightMap.save("heightMap.png", "PNG")