|
|
|
import os, random
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
light_directory = os.fsencode(str(os.getcwd() + "/planets/light"))
|
|
|
|
noise_directory = os.fsencode(str(os.getcwd() + "/planets/noise"))
|
|
|
|
sphere_directory = os.fsencode(str(os.getcwd() + "/planets/sphere"))
|
|
|
|
|
|
|
|
amount_lights = len(os.listdir(light_directory))
|
|
|
|
amount_noise = len(os.listdir(noise_directory))
|
|
|
|
amount_sphere = len(os.listdir(sphere_directory))
|
|
|
|
|
|
|
|
def changeImageColor(im, red, green, blue):
|
|
|
|
# Split into 3 channels
|
|
|
|
r, g, b, a = im.split()
|
|
|
|
# Change channel by factor
|
|
|
|
r = r.point(lambda i: i * red)
|
|
|
|
g = g.point(lambda i: i * green)
|
|
|
|
b = b.point(lambda i: i * blue)
|
|
|
|
# Recombine back to RGB image
|
|
|
|
result = Image.merge('RGBA', (r, g, b, a))
|
|
|
|
return result
|
|
|
|
|
|
|
|
def changePlanetLayerColor(planetLayer):
|
|
|
|
red = random.uniform(-0.5,1.5)
|
|
|
|
green = random.uniform(-0.5,1.5)
|
|
|
|
blue = random.uniform(-0.5,1.5)
|
|
|
|
print(red,green,blue)
|
|
|
|
changedColor = changeImageColor(planetLayer, red, green, blue)
|
|
|
|
return changedColor
|
|
|
|
|
|
|
|
def blendPlanetParts(light, noise1, noise2, noise3, sphere, alpha):
|
|
|
|
blended = Image.blend(sphere, light, alpha)
|
|
|
|
blended = Image.blend(blended, noise1, alpha)
|
|
|
|
blended = Image.blend(blended, noise2, alpha)
|
|
|
|
blended = Image.blend(blended, noise3, alpha)
|
|
|
|
return blended
|
|
|
|
|
|
|
|
def mergePlanetParts(light, noise1, noise2, noise3, sphere):
|
|
|
|
planet = sphere
|
|
|
|
planet.paste(light, (0, 0), light)
|
|
|
|
planet.paste(noise1, (0, 0), noise1)
|
|
|
|
planet = Image.blend(planet, noise2, 0.1)
|
|
|
|
planet = Image.blend(planet, noise3, 0.1)
|
|
|
|
#planet.paste(noise2, (0, 0), noise2)
|
|
|
|
#planet.paste(noise3, (0, 0), noise3)
|
|
|
|
return planet
|
|
|
|
|
|
|
|
|
|
|
|
def createRandomPlanet(seed):
|
|
|
|
|
|
|
|
random.seed(seed)
|
|
|
|
light = Image.open("planets/light/light" + str(random.randrange(0,amount_lights)) + ".png").convert('RGBA')
|
|
|
|
noise1 = Image.open("planets/noise/noise" + str(random.randrange(0,amount_noise)) + ".png").convert('RGBA')
|
|
|
|
noise2 = Image.open("planets/noise/noise" + str(random.randrange(0,amount_noise)) + ".png").convert('RGBA')
|
|
|
|
noise3 = Image.open("planets/noise/noise" + str(random.randrange(0,amount_noise)) + ".png").convert('RGBA')
|
|
|
|
sphere = Image.open("planets/sphere/sphere" + str(random.randrange(0,amount_sphere)) + ".png").convert('RGBA')
|
|
|
|
|
|
|
|
light = changePlanetLayerColor(light)
|
|
|
|
noise1 = changePlanetLayerColor(noise1)
|
|
|
|
noise2 = changePlanetLayerColor(noise2)
|
|
|
|
noise3 = changePlanetLayerColor(noise3)
|
|
|
|
sphere = changePlanetLayerColor(sphere)
|
|
|
|
|
|
|
|
planet = mergePlanetParts(light, noise1, noise2, noise3, sphere)
|
|
|
|
|
|
|
|
return planet
|
|
|
|
|
|
|
|
|
|
|
|
planet = createRandomPlanet(random.randrange(0,10000))
|
|
|
|
planet.save("planet2.png")
|