Module:Subpixel list

From ALttP Speedrunning Wiki
Revision as of 09:19, 15 May 2019 by Kan (talk | contribs)
Jump to: navigation, search

Documentation for this module may be created at list/doc&action=edit&redlink=1 Module:Subpixel list/doc

local p = {}

local HEX = require('Module:Base convert')

function p.main(frame)
	local args = frame:getParent().args
	local v = args[1] or '$16'

	v = tonumber(string.gsub(v, '%$',''), 10) -- remove hex indicator

	local ret = { }
	local sub = 0

	repeat
		local v1, v2 = v/16, v%16
		v1 = math.floor(v1)
		sub = sub + v2
		if sub>=16 then
			v1 = v1 + math.floor(sub/16)
			sub = sub%16
		end
		table.insert(ret, v1)
	until sub==0

	return table.concat(ret, ',')
end

return p