Module:MOS modes: Difference between revisions

Ganaram inukshuk (talk | contribs)
Added todo to code
Ganaram inukshuk (talk | contribs)
No edit summary
Line 4: Line 4:


-- Function that takes a mos and produces all of the modes by brightness
-- Function that takes a mos and produces all of the modes by brightness
-- The mos is entered as a data structure provided by Module:MOS
function p.modes_by_brightness(input_mos)
function p.modes_by_brightness(input_mos)
-- Default parameter, which corresponds to 5L 2s <2/1>
-- Default parameter, which corresponds to 5L 2s <2/1>
Line 11: Line 12:
local nL = input_mos.nL
local nL = input_mos.nL
local ns = input_mos.ns
local ns = input_mos.ns
local peridos = rat.gcd(nL, ns)
local periods = rat.gcd(nL, ns)
-- Find its brightest mode as a string of L's and s's
-- Find its brightest mode as a string of L's and s's
Line 19: Line 20:
local gen = mos.bright_gen(input_mos)
local gen = mos.bright_gen(input_mos)
local gen_in_mossteps = gen['L'] + gen['s']
local gen_in_mossteps = gen['L'] + gen['s']
local period_size  = round((nL + ns) / peridos)
local period_size  = round((nL + ns) / periods)
 
-- For a mos xL ys, there are x+y unique modes that can be achieved by the following process:
-- For a mos xL ys, there are x+y unique modes that can be obtained by the following process:
-- For a generator g in mossteps (that is, less than x+y), take the substring of the brightest
-- For a generator g in mossteps (g < x+y) and starting with the brightest mode (as a string
-- mode's step sequence and move them to the end to get the next-brightest mode. Repeat this
-- of L's and s's), move the first g steps to the end to get the next-brightest mode.
-- process to get all modes. The x+y-1th time this is done will be the darkest mode.
-- Repeat this process with the rotated string to get all modes. The x+y-1th time this is done
-- In case the mos is a multiperiod mos nxL nys, consider it as the mos for xL ys and duplicate
-- will be the darkest mode.
-- the result n times. This way, the number of rotations needed to be performed is still x+y-1.
-- In the case of a multiperiod mos nxL nys, consider it as the mos for xL ys and duplicate
-- each result n times. This way, the number of rotations needed to be performed is still x+y-1.
local brightest_mode_substr = string.sub(brightest_mode, 1, period_size)
local brightest_mode_substr = string.sub(brightest_mode, 1, period_size)
local modes = { brightest_mode }
local modes = { brightest_mode }
local current_mode = brightest_mode_substr
local current_mode = brightest_mode_substr
Line 40: Line 40:
-- Duplicate the string (just in case) then add it to the array of modes
-- Duplicate the string (just in case) then add it to the array of modes
local current_mode_duplicated = string.rep(current_mode, peridos)
local current_mode_duplicated = string.rep(current_mode, periods)
table.insert(modes, current_mode_duplicated)
table.insert(modes, current_mode_duplicated)
end
end
Line 49: Line 49:
-- Test function that produces the modes of a mos as a table
-- Test function that produces the modes of a mos as a table
-- TODO:
-- TODO:
-- - Allow for mos to be extracted from the page's title for use as a template
-- - Allow for mos to be extracted from the page's title for use as a future template
-- - Add UDP listing as a column
-- - Add UDP listing as a column
-- - Allow for input of mode names
-- - Allow for input of mode names
-- - Expand this (possibly as a separate template) for mos intervals
function p.modes_table(frame)
function p.modes_table(frame)
-- Mos is entered as "xL ys" since mos module can parse that format
-- Mos is entered as "xL ys" since the mos module can parse that format
local mosstring = "3L 4s"
local mosstring = "3L 4s"
local input_mos = mos.parse(mosstring)
local input_mos = mos.parse(mosstring)