diff --git a/app.py b/app.py index 5a8bbc2..a1d0c5e 100644 --- a/app.py +++ b/app.py @@ -1,20 +1,22 @@ import os -from flask import Flask, render_template +from flask import Flask, render_template, send_file from planets import createRandomPlanet app = Flask(__name__) - IMG_FOLDER = os.path.join('static', 'IMG') - app.config['UPLOAD_FOLDER'] = IMG_FOLDER + +@app.route('/') +def index(): + planet = os.path.join(app.config['UPLOAD_FOLDER'], 'planet.png') + return render_template('index.html', planet=planet) + @app.route('/') def hello(seed): - print(seed) createRandomPlanet(seed) planet = os.path.join(app.config['UPLOAD_FOLDER'], 'planet.png') - return render_template('hello.html', planet=planet) - + return send_file(planet) if __name__=='__main__': app.run(debug=True, host='0.0.0.0') \ No newline at end of file diff --git a/planet2.png b/planet2.png deleted file mode 100644 index 8972167..0000000 Binary files a/planet2.png and /dev/null differ diff --git a/planets.py b/planets.py index 13b84f6..3b1d52f 100644 --- a/planets.py +++ b/planets.py @@ -1,7 +1,6 @@ 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")) @@ -11,13 +10,12 @@ 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 @@ -25,7 +23,6 @@ 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 @@ -63,7 +60,3 @@ def createRandomPlanet(seed): planet = mergePlanetParts(light, noise1, noise2, noise3, sphere) planet.save("static/IMG/planet.png") return - - -#planet = createRandomPlanet('Elijah') -#planet.save("planet2.png") \ No newline at end of file diff --git a/static/IMG/planet.png b/static/IMG/planet.png index 98b98b9..e4625b2 100644 Binary files a/static/IMG/planet.png and b/static/IMG/planet.png differ diff --git a/templates/hello.html b/templates/index.html similarity index 67% rename from templates/hello.html rename to templates/index.html index 2cf64ac..6f530cc 100644 --- a/templates/hello.html +++ b/templates/index.html @@ -2,9 +2,10 @@ - Hello Worl! + Planets +

Welcome to Planets

Planet - + \ No newline at end of file