def crearImagen(): if request.method == 'POST': width = (int(request.form['widht'])) x1 = (int(request.form['x1'])) y1 = (int(request.form['y1'])) y2 = (int(request.form['y2'])) x2 = (int(request.form['x2'])) numIter = (int(request.form['numIter'])) color = (request.form['color']) paleta = [[255,0,0],[255,0,0],[255,0,0]] mandelbrot.renderizaMandelbrotBonito(x1,y1,x2,y2,width,numIter,"static/imagen.png",paleta,3) return """ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Index</title> <link rel="stylesheet" type="text/css" href="../static/style.css"> </head> <body> <img src='/static/imagen.png' alt='Dynamic Image' > </body> </html>""" else: return '''<form action="/imagen" method="post">
def POST(self): form = myform() if not form.validates(): return render.ejercicio_05(form) else: # Limpiamos la cache (solo se hará cada 10 peticiones) clean_cache() # Obtenemos los valores x1 = float(form.d.x1) y1 = float(form.d.y1) x2 = float(form.d.x2) y2 = float(form.d.y2) ancho = int(form.d.ancho) iteraciones = int(form.d.iteracciones) color1 = form.d.color1 color2 = form.d.color2 nombreFicheroPNG = 'images/imagen_x1%sy1%sx2%sy2%sancho%scolor1%scolor2%s.png' % (x1, y1, x2, y2, ancho, color1, color2) if not os.path.exists(nombreFicheroPNG): #mandelbrot.renderizaMandelbrot(x1, y1, x2, y2, ancho, iteraciones, nombreFicheroPNG) paleta = (HTMLColorToRGB(color1), HTMLColorToRGB(color2)) nColoresPaleta = 10 mandelbrot.renderizaMandelbrotBonito(x1, y1, x2, y2, ancho, iteraciones, nombreFicheroPNG, paleta, nColoresPaleta) web.header('Content-Type', 'image/png') return open(nombreFicheroPNG, 'rb') # Datos binarios
def show_mandelbrot(): # Show a Mandelbrot set image x1 = request.args.get('x1') or -1 x2 = request.args.get('x2') or 1 y1 = request.args.get('y1') or -1 y2 = request.args.get('y2') or 1 width = request.args.get('width') or 300 iters = request.args.get('iters') or 10 c1 = request.args.get('c1',type=str) or "0-0-0" c2 = request.args.get('c2',type=str) or "255-255-0" c3 = request.args.get('c3',type=str) or "255-50-0" filename = "./static/mandelbrot_cache/f_P_%s_%s_%s_%s_W_%s_I_%s_C1_%s_C2_%s_C3_%s.png" % (x1,x2,y1,y2,width,iters,c1,c2,c3) clean_cache("./static/mandelbrot_cache/",86400) # Delete files more than a day older if not os.path.isfile(filename): c1 = tuple([int(x) for x in c1.split("-")]) c2 = tuple([int(x) for x in c2.split("-")]) c3 = tuple([int(x) for x in c3.split("-")]) mb.renderizaMandelbrotBonito(float(x1),float(y1),float(x2),float(y2),int(width),int(iters),filename,[c1,c2,c3],3) return ''' <!DOCTYPE html> <head> <link rel="stylesheet" type="text/css" href="/static/style.css"> </head> <html> <body> <img src='%s'> </body> </html> ''' % filename
def crearImagen(): if request.method == 'POST': width = (int(request.form['widht'])) x1 = (int(request.form['x1'])) y1 = (int(request.form['y1'])) y2 = (int(request.form['y2'])) x2 = (int(request.form['x2'])) numIter = (int(request.form['numIter'])) color = (request.form['color']) paleta = [[255, 0, 0], [255, 0, 0], [255, 0, 0]] mandelbrot.renderizaMandelbrotBonito(x1, y1, x2, y2, width, numIter, "static/imagen.png", paleta, 3) return """ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Index</title> <link rel="stylesheet" type="text/css" href="../static/style.css"> </head> <body> <img src='/static/imagen.png' alt='Dynamic Image' > </body> </html>""" else: return '''<form action="/imagen" method="post">
def parametros(x1, x2, y1, y2, pixeles,iteraciones, paletas): fichero = "./foto.png" if(paletas == 1): paleta = [(15,99,32),(53,23,65),(89,32,56)] elif(paletas == 2): paleta = [(145,9,3),(21,124,126),(255,0,43)] else: paleta = [(15,99,32),(111,32,54),(87,32,76)] renderizaMandelbrotBonito(float(x1), float(y1), float(x2), float(y2), int(pixeles), int(iteraciones), fichero, paleta, 3) return send_file(fichero, mimetype = "image/png")
def pintar(): cleanCache() #Obtenemos los valores metidos x1 = float(request.form['x1']) x2 = float(request.form['x2']) y1 = float(request.form['y1']) y2 = float(request.form['y2']) ancho = int(request.form['ancho']) iteraciones = int(request.form['iteraciones']) color1 = request.form['color1'] color1 = color1[1:len(color1)] rr1 = (int(color1[0:2], 16)) gg1 = (int(color1[2:4], 16)) bb1 = (int(color1[4:6], 16)) color2 = request.form['color2'] color2 = color2[1:len(color2)] rr2 = (int(color2[0:2], 16)) gg2 = (int(color2[2:4], 16)) bb2 = (int(color2[4:6], 16)) color3 = request.form['color3'] color3 = color3[1:len(color3)] rr3 = (int(color3[0:2], 16)) gg3 = (int(color3[2:4], 16)) bb3 = (int(color3[4:6], 16)) #Nombre del nuevo fractal name = "mandelbrot" + str(x1) + str(x2) + str(y1) + str(y2) + str( ancho) + str(iteraciones) + color1 + color2 + color3 + ".png" if path.exists("./imagenes/" + name): #mandamos la imagen pues ya existe return send_file("./imagenes/" + name, mimetype="image/png") else: #Creamos la imagen renderizaMandelbrotBonito(x1, y1, x2, y2, ancho, iteraciones, name, [(rr1, gg1, bb1), (rr2, gg2, bb2), (rr3, gg3, bb3)], 3) return send_file("./imagenes/" + name, mimetype="image/png")
def prog1(): clean_cache() x1 = request.args.get('x1') # x1 y1 = request.args.get('y1') # y1 x2 = request.args.get('x2') # x2 y2 = request.args.get('y2') # y2 ancho = request.args.get('ancho') # ancho r1 = request.args.get('r1') # r1 g1 = request.args.get('g1') # g1 b1 = request.args.get('b1') # b1 r2 = request.args.get('r2') # r2 g2 = request.args.get('g2') # g2 b2 = request.args.get('b2') # b2 r3 = request.args.get('r3') # r3 g3 = request.args.get('g3') # g3 b3 = request.args.get('b3') # b3 n = request.args.get('n') # n paleta = [(int(r1), int(g1), int(b1)), (int(r2), int(g2), int(b2)), (int(r3), int(g3), int(b3))] archivo = "fractalb" + "_x1" + str(x1) + "_y1" + str(y1) + "_x2" + str( x2) + "_y2" + str(y2) + "_a" + str(ancho) + "_" + str(r1) + str( g1) + str(b1) + "_" + str(r2) + str(b2) + str(g2) + "_" + str( r3) + str(g3) + str(b3) + ".png" url = 'http://0.0.0.0:8080/png/' + archivo my_file = Path('./static/imagenes/fractales/archivo') if not my_file.exists(): renderizaMandelbrotBonito(float(x1), float(y1), float(x2), float(y2), int(ancho), 100, './static/imagenes/fractales/' + archivo, paleta, int(n)) return redirect(url, code=302)
def pagina(): x1 = request.args.get('x1') y1 = request.args.get('y1') x2 = request.args.get('x2') y2 = request.args.get('y2') tamano = request.args.get('tamano') iteraciones = request.args.get('iteraciones') paleta = eval(request.args.get('paleta')) total = x1 + y1 + x2 + y2 + tamano + iteraciones for i in paleta: total = total + str(i[0]) + str(i[1]) + str(i[2]) nombreFichero = "static/imagenes" + total + ".png" #if os.path.isfile(nombreFichero) == False: renderizaMandelbrotBonito(float(x1), float(y1), float(x2), float(y2), int(tamano), int(iteraciones), nombreFichero, paleta, len(paleta)) return """ <html> <head> <meta http-equiv="content-type" content="charset=utf-8"> <title>Ejercicio2</title> </head> <body style="background:grey;"> <img src="%s"> </body> </html> """ % nombreFichero