Module:MOS mode degrees: Difference between revisions
m Commented out tiebreaker code for testing |
Added cell coloring to indicate which cells are perfect intervals (default color), the large size (light yellow), the small size (light blue), or an altered size (light red) |
||
| Line 509: | Line 509: | ||
return alterations | return alterations | ||
end | |||
-- Helper function | |||
-- Calculates row colors given precalculated degree vectors for each mode | |||
function p.calculate_row_colors(input_mos, input_mode_vectors) | |||
-- Default input mos and brightest/darkest true mos modes | |||
local input_mos = input_mos or mos.new(5, 2) | |||
local brightest_true_mode = mos.brightest_mode(input_mos) | |||
local darkest_true_mode = string.reverse(brightest_true_mode) | |||
-- Default input mode vectors | |||
local input_mode_vectors = input_mode_vectors or p.calculate_mos_mode_degrees(input_mos, p.calculate_step_pattern_rotations(input_mos, brightest_true_mode, true)) | |||
-- Brightest and darkest vectors | |||
local brightest_vector = p.calculate_mode_degrees(input_mos, brightest_true_mode) | |||
local darkest_vector = p.calculate_mode_degrees(input_mos, darkest_true_mode) | |||
local cell_color_perfect_size = "NONE" | |||
local cell_color_large_size = "fffff0" | |||
local cell_color_small_size = "eaeaff" | |||
local cell_color_altered_size = "ffe0e0" | |||
local row_colors = {} | |||
for i = 1, #input_mode_vectors do | |||
local cell_colors = {} | |||
for j = 1, #input_mode_vectors[i] do | |||
if input_mode_vectors[i][j] == 0 then | |||
table.insert(cell_colors, cell_color_perfect_size) | |||
elseif brightest_vector[j] == input_mode_vectors[i][j] then | |||
table.insert(cell_colors, cell_color_large_size) | |||
elseif darkest_vector[j] == input_mode_vectors[i][j] then | |||
table.insert(cell_colors, cell_color_small_size) | |||
else | |||
table.insert(cell_colors, cell_color_altered_size) | |||
end | |||
end | |||
table.insert(row_colors, cell_colors) | |||
end | |||
return row_colors | |||
end | end | ||
| Line 535: | Line 575: | ||
-- Get mosstep vectors for all modes | -- Get mosstep vectors for all modes | ||
local mosstep_vectors = p.calculate_mos_mode_degrees(input_mos, modes) | local mosstep_vectors = p.calculate_mos_mode_degrees(input_mos, modes) | ||
-- Get row colors | |||
local row_colors = p.calculate_row_colors(input_mos, mosstep_vectors) | |||
-- Create table | -- Create table | ||
| Line 572: | Line 615: | ||
end | end | ||
-- Add scale degrees | -- Add scale degrees with cell coloring | ||
for j = 1, #mosstep_vectors[i] do | for j = 1, #mosstep_vectors[i] do | ||
result = result .. string.format('| %s\n', p.decode_quality(mosstep_vectors[i][j])) | if row_colors[i][j] == "NONE" then | ||
result = result .. string.format('| %s\n', p.decode_quality(mosstep_vectors[i][j])) | |||
else | |||
result = result .. string.format('| style="background:#%s" | %s\n', row_colors[i][j], p.decode_quality(mosstep_vectors[i][j])) | |||
end | |||
end | end | ||
end | end | ||
| Line 610: | Line 657: | ||
-- Get mosstep vectors for all modes | -- Get mosstep vectors for all modes | ||
local mosstep_vectors = p.calculate_mos_mode_degrees(input_mos, modes) | local mosstep_vectors = p.calculate_mos_mode_degrees(input_mos, modes) | ||
-- Get row colors | |||
local row_colors = p.calculate_row_colors(input_mos, mosstep_vectors) | |||
-- Create table | -- Create table | ||
| Line 647: | Line 697: | ||
end | end | ||
-- Add scale degrees | -- Add scale degrees with cell coloring | ||
for j = 1, #mosstep_vectors[i] do | for j = 1, #mosstep_vectors[i] do | ||
result = result .. string.format('| %s\n', p.decode_quality(mosstep_vectors[i][j])) | if row_colors[i][j] == "NONE" then | ||
result = result .. string.format('| %s\n', p.decode_quality(mosstep_vectors[i][j])) | |||
else | |||
result = result .. string.format('| style="background:#%s" | %s\n', row_colors[i][j], p.decode_quality(mosstep_vectors[i][j])) | |||
end | |||
end | end | ||
end | end | ||