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 blendPlanetParts(light, noise, sphere, alpha): blended = Image.blend(sphere, light, alpha) blended2 = Image.blend(blended, noise, alpha) return blended2 def getRandomPlanet(): light = Image.open("planets/light/light" + str(random.randrange(0,amount_lights)) + ".png").convert('RGBA') noise = 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') planet = blendPlanetParts(light, noise, sphere, 0.1) return planet planet = getRandomPlanet() planet.save('planet1.png')