Module:MOS in EDO: Difference between revisions
m Shortened column header |
Added cell colors |
||
| Line 2: | Line 2: | ||
local utils = require('Module:Utils') | local utils = require('Module:Utils') | ||
local p = {} | local p = {} | ||
-- Global variables for cell colors | |||
-- Dark blue for large steps, light blue for small steps | |||
-- For mosses that are reversed (starts with s and ends with L), use orange instead | |||
p.cell_color_none = "NONE" -- For cells that don't have a color (default cell color applies) | |||
p.cell_color_perfect_size = "NONE" -- Only applies for steps of an edo | |||
p.cell_color_large = "B3B3E0" | |||
p.cell_color_small = "EAEAFF" | |||
p.cell_color_lg_rev = "DAB9A0" | |||
p.cell_color_sm_rev = "FFE3D0" | |||
-- Helper function | -- Helper function | ||
| Line 189: | Line 199: | ||
-- Add the step pattern for successive mosses until the pattern becomes that for an edo | -- Add the step pattern for successive mosses until the pattern becomes that for an edo | ||
while current_scale ~= nil and starting_mos_valid do | while current_scale ~= nil and starting_mos_valid do | ||
-- Calculate current step ratio | |||
-- Use this to determine which cell colors to use | |||
local step_ratio_gcd = utils._gcd(current_step_sizes["L"], current_step_sizes["s"]) | |||
local large_step_size = current_step_sizes["L"] | |||
local small_step_size = current_step_sizes["s"] | |||
-- Is the first step a large step? | |||
local first_step_is_large_step = current_scale[1] == large_step_size | |||
-- Add the step sizes | -- Add the step sizes | ||
result = result .. string.format('|-\n') | result = result .. string.format('|-\n') | ||
for i = 1, #current_scale do | for i = 1, #current_scale do | ||
local current_step = current_scale[i] | local current_step = current_scale[i] | ||
-- Calculate cell color | |||
local cell_color = "NONE" | |||
if large_step_size == small_step_size then | |||
cell_color = p.cell_color_none | |||
elseif first_step_is_large_step then | |||
if current_step == large_step_size then | |||
cell_color = p.cell_color_large | |||
elseif current_step == small_step_size then | |||
cell_color = p.cell_color_small | |||
end | |||
elseif not first_step_is_large_step then | |||
if current_step == large_step_size then | |||
cell_color = p.cell_color_lg_rev | |||
elseif current_step == small_step_size then | |||
cell_color = p.cell_color_sm_rev | |||
end | |||
end | |||
if current_step == 1 then | if current_step == 1 then | ||
result = result .. string.format('| 1\n') | result = result .. string.format('| 1\n') | ||
else | else | ||
result = result .. string.format('| colspan="%i" | %i\n', current_step, current_step) | if cell_color == p.cell_color_none then | ||
result = result .. string.format('| colspan="%i" | %i\n', current_step, current_step) | |||
else | |||
result = result .. string.format('| bgcolor="%s" colspan="%i" | %i\n', cell_color, current_step, current_step) | |||
end | |||
end | end | ||
end | end | ||
| Line 203: | Line 245: | ||
local scale_sig = p.mos_step_pattern_to_scale_sig(current_scale) | local scale_sig = p.mos_step_pattern_to_scale_sig(current_scale) | ||
local current_step_sizes = p.calculate_step_sizes(current_scale) | local current_step_sizes = p.calculate_step_sizes(current_scale) | ||
-- Get the tamnams name, if there is one | -- Get the tamnams name, if there is one | ||
| Line 214: | Line 250: | ||
local tamnams_name = mos.tamnams_name[scale_sig] | local tamnams_name = mos.tamnams_name[scale_sig] | ||
local current_step_count = #current_scale | local current_step_count = #current_scale | ||
-- Use step sizes to determine whether the mos is an edo | |||
local reduced_large_step_size = current_step_sizes["L"] / step_ratio_gcd | |||
local reduced_small_step_size = current_step_sizes["s"] / step_ratio_gcd | |||
if reduced_large_step_size == reduced_small_step_size then | if reduced_large_step_size == reduced_small_step_size then | ||