This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
aaronmallen's profile picture

ender_item setFrequency() question...

Started by aaronmallen, 10 November 2016 - 12:32 AM
aaronmallen #1
Posted 10 November 2016 - 01:32 AM
What is the frequency exactly… I tested on an ender tank and on a tank with gray,white,green I get 3335 as a response to getFrequency(). My question is what exactly is this number?
Anavrins #2
Posted 10 November 2016 - 05:09 AM
There's 3 colors slot, of which there is 16 possible colors for each.
You have to look at the frequency in hexadecimal to understand how it works.
Frequency for colors "black, white, black", will be 0xF0F in hexadecimal.
You can see how a letter corresponds to a color, F means black, 0 means white, and the full list of colors can be found in the window api https://github.com/alekso56/ComputercraftLua/blob/master/rom/apis/window#L2
Few other examples,
Magenta, Orange, Pink would be 0x612
LightGray, Purple, Red would be 0xEA8
Gray, White, Green would be 0xD07, which corresponds to 3335 in decimal.
Edited on 10 November 2016 - 04:09 AM
aaronmallen #3
Posted 11 November 2016 - 03:19 AM
Is there an easy way to convert a combination of colors into this value in CC?
Bomb Bloke #4
Posted 11 November 2016 - 03:57 AM
local function getHex(...)
	local output = 0
	
	for i = 1, 3 do
		output = output + (math.log(arg[i]) / math.log(2)) * 16 ^ (i - 1)
	end
	
	return output
end

print(getHex(colours.grey, colours.white, colours.green))  --> 3335