60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
aura_env.grad = function(c)
 | 
						|
	--c expected as [0, 1]
 | 
						|
	if c > 0.5 then
 | 
						|
		c = 1 - (2 * (c - 0.5))
 | 
						|
		return c, 1, 0, 1
 | 
						|
	else
 | 
						|
		c = c * 2
 | 
						|
		return 1, c, 0, 1
 | 
						|
	end
 | 
						|
end
 | 
						|
 | 
						|
local function hexgrad(val, min, max)
 | 
						|
	local function tohex(input)
 | 
						|
		local output = string.format("%x", input * 255)
 | 
						|
		return output
 | 
						|
	end
 | 
						|
	local function grad(c, min, max)
 | 
						|
		c = (((max - c) / (max - min)) * 1)
 | 
						|
		if c > 0.5 then
 | 
						|
			c = 1 - (2 * (c - 0.5))
 | 
						|
			return c, 1, 0, 1
 | 
						|
		else
 | 
						|
			c = c * 2
 | 
						|
			return 1, c, 0, 1
 | 
						|
		end
 | 
						|
	end
 | 
						|
	local color1, color2, color3, color4 = 0, 0, 0, 0
 | 
						|
	color1, color2, color3, color4 = grad(val, min, max)
 | 
						|
	color1, color2, color3, color4 = tohex(color1), tohex(color2), tohex(color3), tohex(color4)
 | 
						|
	color1, color2, color3, color4 = tostring(color1), tostring(color2), tostring(color3), tostring(color4)
 | 
						|
	if string.len(color1) == 1 then color1 = "0" .. color1 end
 | 
						|
	if string.len(color2) == 1 then color2 = "0" .. color2 end
 | 
						|
	if string.len(color3) == 1 then color3 = "0" .. color3 end
 | 
						|
	if string.len(color4) == 1 then color4 = "0" .. color4 end
 | 
						|
	local color = "\124c" .. color4 .. color1 .. color2 .. color3
 | 
						|
	return color
 | 
						|
end
 | 
						|
 | 
						|
local function RGBtoHex(rgb)
 | 
						|
	local hexadecimal = "FF"
 | 
						|
	for key, value in pairs(rgb) do
 | 
						|
		local hex = ""
 | 
						|
 | 
						|
		while value > 0 do
 | 
						|
			local index = math.fmod(value, 16) + 1
 | 
						|
			value = math.floor(value / 16)
 | 
						|
			hex = string.sub("0123456789ABCDEF", index, index) .. hex
 | 
						|
		end
 | 
						|
 | 
						|
		if string.len(hex) == 0 then
 | 
						|
			hex = "00"
 | 
						|
		elseif string.len(hex) == 1 then
 | 
						|
			hex = "0" .. hex
 | 
						|
		end
 | 
						|
 | 
						|
		hexadecimal = hexadecimal .. hex
 | 
						|
	end
 | 
						|
	return hexadecimal
 | 
						|
end
 |