Exemple #1
0
def shape():
    if request.method == 'POST':
        # get data
        side = int(request.form.get('side'))
        shape = request.form.get('shape')
        # print(shape)

        outline = request.form.get('outline')

        nColors = request.form.get('nColors')
        # print(nColors)

        colors = []

        for i in range(int(nColors)):
            colors.append(request.form.get('rgb' + str(i + 1)))

        error = None

        try:
            colors = [tuple(bytes.fromhex(x[1:])) for x in colors]
        except Exception as e:
            print(e)
            error = "ERROR: Invalid color hex"

        if side > 5000 or side < 100:
            error = "WARNING: Image too large OR Image too small"

        if error != None:
            print(error)
            return render_template('error.html', context=error)
        else:
            fname = "wall-{}.png".format(int(time.time()))
            fpath = 'static/images/' + fname
            img = wallgen.nGradient(side, *colors)

            if outline:
                outline = tuple(bytes.fromhex("#2c2c2c"[1:]))
            else:
                outline = None

            if shape == 'hexagon':
                img = wallgen.genHexagon(side, side, img, outline)
            elif shape == 'squares':
                img = wallgen.genSquares(side, side, img, outline)
            elif shape == 'diamond':
                img = wallgen.genDiamond(side, side, img, outline)
            elif shape == 'triangle':
                img = wallgen.genTriangle(side, side, img, outline)
            elif shape == 'isometric':
                img = wallgen.genIsometric(side, side, img, outline)
            # print(fpath)
            img.save(fpath)
            imgurl = url_for('static', filename='images/' + fname)
            return render_template("download.html",
                                   context=imgurl,
                                   home="shape")
    else:
        return render_template('shape.html')
Exemple #2
0
def poly():
	if request.method == 'POST':
		# get data

		side = int(request.form.get('side'))
		np = int(request.form.get('np'))

		outline = request.form.get('outline')
		
		nColors = request.form.get('nColors')
		# print(nColors)

		colors = []

		for i in range(int(nColors)):
			colors.append(request.form.get('rgb'+str(i+1)))

		error = None
		
		try:
			colors = [tuple(bytes.fromhex(x[1:])) for x in colors]
		except Exception as e:
			print(e)
			error = "ERROR: Invalid color hex"
		
		if side > 5000 or side < 100:
			error = "WARNING: Image too large OR Image too small"
		if np < 10 or np > 1000:
			error = "WARNING: Too less points OR too many points"

		if error != None:
			print(error)
			return render_template('error.html', context=error)
		else:
			fname = "wall-{}.png".format(int(time.time()))
			fpath = 'static/images/'+fname
			
			shift = side//10
			nside = side + shift*2 # increase size to prevent underflow

			img = wallgen.nGradient(side, *colors)

			pts = wallgen.genPoints(np, nside, nside)
			img = wallgen.genPoly(side, side, img, pts, shift, shift, outl=outline)

			# print(fpath)
			img.save(fpath)

			imgurl = url_for('static',filename='images/'+fname)
			return render_template("download.html", context=imgurl, home="poly")
	else:
		return render_template('poly.html')