Module:Color: Difference between revisions

From Wiki of ZZT
Jump to navigation Jump to search
(WIP: Writing a module for generating color swatches)
 
m (Make indentation consistent: MediaWiki's built-in editor seems to like tabs)
Line 21: Line 21:


local ega_color_names = {
local ega_color_names = {
    "black",
"black",
    "dark blue",
"dark blue",
    "dark green",
"dark green",
    "dark cyan",
"dark cyan",
    "dark red",
"dark red",
    "dark purple",
"dark purple",
    "dark brown",
"dark brown",
    "light gray",
"light gray",
    "dark gray",
"dark gray",
    "blue",
"blue",
    "green",
"green",
    "cyan",
"cyan",
    "red",
"red",
    "purple",
"purple",
    "yellow",
"yellow",
    "white"
"white"
}
}


function index_to_name(i)
function index_to_name(i)
    if i ~= math.floor(i) or i < 0 or i > 15 then
if i ~= math.floor(i) or i < 0 or i > 15 then
        return "???"
return "???"
    end
end
    return ega_color_names[i + 1]
return ega_color_names[i + 1]
end
end


function combo_name(bg_index, fg_index)
function combo_name(bg_index, fg_index)
    blinking = false
blinking = false
    if bg_index >= 8 then
if bg_index >= 8 then
        blinking = true
blinking = true
        bg_index = bg_index - 8
bg_index = bg_index - 8
    end
end
    result = index_to_name(fg_index) .. " on " .. index_to_name(bg_index)
result = index_to_name(fg_index) .. " on " .. index_to_name(bg_index)
    if blinking then
if blinking then
        result = "blinking " .. result
result = "blinking " .. result
    end
end
    return result
return result
end
end


function p.swatch(frame)
function p.swatch(frame)
    bg = frame.args.bg
bg = frame.args.bg
    fg = frame.args.fg
fg = frame.args.fg
return combo_name(bg, fg)
return combo_name(bg, fg)
end
end


return p
return p

Revision as of 05:55, 11 January 2021

Documentation for this module may be created at Module:Color/doc

local p = {}

local ega_hex_codes = {
	"#000",
	"#00a",
	"#0a0",
	"#0aa",
	"#a00",
	"#a0a",
	"#a50",
	"#aaa",
	"#555",
	"#55f",
	"#5f5",
	"#5ff",
	"#f55",
	"#f5f",
	"#ff5",
	"#fff"
}

local ega_color_names = {
	"black",
	"dark blue",
	"dark green",
	"dark cyan",
	"dark red",
	"dark purple",
	"dark brown",
	"light gray",
	"dark gray",
	"blue",
	"green",
	"cyan",
	"red",
	"purple",
	"yellow",
	"white"
}

function index_to_name(i)
	if i ~= math.floor(i) or i < 0 or i > 15 then
		return "???"
	end
	return ega_color_names[i + 1]
end

function combo_name(bg_index, fg_index)
	blinking = false
	if bg_index >= 8 then
		blinking = true
		bg_index = bg_index - 8
	end
	result = index_to_name(fg_index) .. " on " .. index_to_name(bg_index)
	if blinking then
		result = "blinking " .. result
	end
	return result
end

function p.swatch(frame)
	bg = frame.args.bg
	fg = frame.args.fg
	return combo_name(bg, fg)
end

return p