2025-01-20 21:59:27 +01:00
|
|
|
|
|
|
|
# -------------------------------------------------------------------
|
|
|
|
# ORTHOGRAPHIC
|
|
|
|
# Your personal aerial satellite. Always on. At any altitude.*
|
|
|
|
# Developed by MarStrMind
|
|
|
|
# License: Open Software License 3.0
|
|
|
|
# Up to date version always on marstr.online
|
|
|
|
# -------------------------------------------------------------------
|
|
|
|
# perlin.py
|
|
|
|
# Generates a perlin noise image which is used to determine how which
|
|
|
|
# resource looks.
|
|
|
|
# -------------------------------------------------------------------
|
|
|
|
|
|
|
|
from PIL import Image # Depends on the Pillow lib
|
|
|
|
from random import randrange
|
|
|
|
import random
|
|
|
|
import numpy as np
|
2025-02-01 16:39:15 +01:00
|
|
|
import glob
|
|
|
|
from defines import *
|
2025-01-20 21:59:27 +01:00
|
|
|
from perlin_numpy import (
|
|
|
|
generate_perlin_noise_2d, generate_fractal_noise_2d
|
|
|
|
)
|
|
|
|
|
|
|
|
class mstr_perlin:
|
|
|
|
|
|
|
|
def __init__(self, tag, value, mlat, mlng, zl):
|
|
|
|
self._tag = tag
|
|
|
|
self._value = value
|
|
|
|
self._mlat = mlat
|
|
|
|
self._mlng = mlng
|
|
|
|
|
|
|
|
self._zl = zl
|
|
|
|
self._mapscale = 0
|
|
|
|
if zl == 16: self._mapscale = 80
|
|
|
|
if zl == 18: self._mapscale = 20
|
|
|
|
|
|
|
|
|
2025-02-01 16:39:15 +01:00
|
|
|
def _generateColorIndex(self):
|
|
|
|
idx = []
|
|
|
|
|
|
|
|
colorsrc = glob.glob(mstr_datafolder + "textures/" + self._tag + "/" + self._value + "/*.png")
|
|
|
|
if len(colorsrc) >= 4:
|
|
|
|
picknum = list(range(0, len(colorsrc)))
|
|
|
|
picksel = random.sample(picknum, 4)
|
|
|
|
|
|
|
|
for p in range(0, 4):
|
|
|
|
ptc = Image.open(colorsrc[picksel[p]])
|
|
|
|
ptc = ptc.resize((1,1), resample=Image.Resampling.BILINEAR)
|
|
|
|
clr = ptc.getpixel((0,0))
|
|
|
|
res = (clr[0], clr[1], clr[2])
|
|
|
|
idx.append(res)
|
2025-01-20 21:59:27 +01:00
|
|
|
|
|
|
|
return idx
|
|
|
|
|
|
|
|
|
|
|
|
# Generates a Perlin map depending on what we need
|
|
|
|
def _generatePerlinMap(self):
|
2025-02-01 16:39:15 +01:00
|
|
|
#idx = self._findBaseColor()
|
|
|
|
clr = self._generateColorIndex()
|
2025-01-20 21:59:27 +01:00
|
|
|
bw = self._mlng * self._mapscale
|
|
|
|
bh = self._mlat * self._mapscale
|
2025-02-01 16:39:15 +01:00
|
|
|
base = Image.new("RGBA", (bw,bh))
|
2025-01-20 21:59:27 +01:00
|
|
|
|
2025-02-01 16:39:15 +01:00
|
|
|
if len(clr) == 4:
|
2025-02-06 19:37:33 +01:00
|
|
|
wh = 3072
|
2025-02-01 16:39:15 +01:00
|
|
|
base = Image.new("RGBA", (bw,bh), clr[0])
|
2025-01-20 21:59:27 +01:00
|
|
|
|
2025-02-01 16:39:15 +01:00
|
|
|
for c in range(len(clr)):
|
|
|
|
np.random.seed(randrange(10000000, 100000000))
|
|
|
|
noise1 = generate_fractal_noise_2d((wh,wh), (64,64), 5)
|
|
|
|
np.random.seed(randrange(10000000, 100000000))
|
|
|
|
noise2 = generate_fractal_noise_2d((wh,wh), (32,32), 4)
|
|
|
|
|
|
|
|
im1 = Image.new("RGBA", (wh,wh))
|
|
|
|
im2 = Image.new("RGBA", (wh,wh))
|
|
|
|
|
|
|
|
for y in range(0, wh):
|
|
|
|
for x in range(0, wh):
|
|
|
|
n = (noise1[y][x] + 1) / 2
|
|
|
|
v = (
|
|
|
|
clr[c][0],
|
|
|
|
clr[c][1],
|
|
|
|
clr[c][2],
|
|
|
|
int(n*255)
|
|
|
|
)
|
|
|
|
im1.putpixel((x,y), v)
|
|
|
|
|
|
|
|
for y in range(0, wh):
|
|
|
|
for x in range(0, wh):
|
|
|
|
n = (noise2[y][x] + 1) / 2
|
|
|
|
v = (
|
|
|
|
clr[c][0],
|
|
|
|
clr[c][1],
|
|
|
|
clr[c][2],
|
|
|
|
int(n*255)
|
|
|
|
)
|
|
|
|
im2.putpixel((x,y), v)
|
|
|
|
|
|
|
|
im = Image.blend(im1,im2, alpha=0.675)
|
|
|
|
base.alpha_composite(im)
|
2025-01-20 21:59:27 +01:00
|
|
|
|
|
|
|
# Provide the perlin map
|
|
|
|
return base
|