Quantcast

Jump to content

Welcome to GameOn365
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

[Lua] Convert RGB Colors to Hex

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Nick Admin

Nick

    Lead Software Developer

  • Root Administrator Admin
  • 343 posts
Function
-- Function decToHex (renamed, updated): http://lua-users.org/lists/lua-l/2004-09/msg00054.html
local function decToHex(IN)
	local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
	while IN>0 do
    	I=I+1
    	IN,D=math.floor(IN/B),math.fmod(IN,B)+1
    	OUT=string.sub(K,D,D)..OUT
	end
	return OUT
end

-- Function rgbToHex: http://gameon365.net/index.php
local function rgbToHex(c)
	local output = decToHex(c["r"]) .. decToHex(c["g"]) .. decToHex(c["b"]);
	return output
end

Usage
local rgbcolor = {};
 	local rgbcolor["r"] = 214;
 	local rgbcolor["g"] = 42;
 	local rgbcolor["b"] = 172;

local hexcolor = rgbToHex(rgbcolor);

GameOn365 Administrator, Community Manager, and Lead Web Software Developer
Minecraft Server Administrator, Developer, and Support Team Lead

#2
brarei200

brarei200

    Member

  • Members
  • 22 posts
  • :
Nice tutorial, think you can write this in VB?

#3
Nick Admin

Nick

    Lead Software Developer

  • Root Administrator Admin
  • 343 posts

Nice tutorial, think you can write this in VB?


Thanks. I doubt I could rewrite it for VB, as my experience is mainly with PHP and Lua.
GameOn365 Administrator, Community Manager, and Lead Web Software Developer
Minecraft Server Administrator, Developer, and Support Team Lead




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users