Module:SB tree: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local yesno = require("Module:Yesno")


-- Function that constructs a sequence of ratios according to the Stern-Brocot tree
-- Function that constructs a sequence of ratios according to the Stern-Brocot tree
Line 117: Line 119:
-- Test function that produces the ratios of the SB tree as a multi-column table, using different arguments
-- Test function that produces the ratios of the SB tree as a multi-column table, using different arguments
-- To try this out, add the following text (not as a lua comment):
-- To try this out, add the following text (not as a lua comment):
-- {{#invoke:SB_tree|sb_table}}
-- {{#invoke: SB_tree|sb_table}}
function p.sb_table(frame)
function p.sb_table(frame)
-- Call the sb function
-- Call the sb function
-- Start/stop ratios are the same, depth is deeper, and edge-extend is allowed
-- Start/stop ratios are the same, depth is deeper, and edge-extend is allowed
local depth = frame.args['Depth'] or 4
local depth = frame.args["Depth"] or 4
local edge_extend = frame.args['Edge Extend'] or 2
local edge_extend = frame.args["Edge Extend"] or 2
local start_ratio_unparsed = frame.args['Start Ratio'] or "1/1"
local start_ratio_unparsed = frame.args["Start Ratio"] or "1/1"
local stop_ratio_unparsed = frame.args['Stop Ratio'] or "1/0"
local stop_ratio_unparsed = frame.args["Stop Ratio"] or "1/0"
local stagger_ratios = (frame.args['Stagger Ratios'] and string.lower(frame.args['Stagger Ratios'])) == "true" and true or false
local stagger_ratios = (frame.args["Stagger Ratios"] and string.lower(frame.args["Stagger Ratios"])) == "true" and true or false
-- Parse ratios
-- Parse ratios
Line 136: Line 138:
-- Create the table
-- Create the table
result = '{| class="wikitable"\n'
result = "{| class=\"wikitable\"\n|-\n"
result = result .. "|+\n"
.. "! "
result = result .. "|-\n"
-- Create the header cell
-- Create the header cell
if stagger_ratios then
if stagger_ratios then
result = result .. '! colspan="' .. depth + edge_extend + 1 .. " | Ratios\n"
result = result .. "colspan=\"" .. depth + edge_extend + 1 .. "\" | "
else
result = result .. "| Ratios\n"
end
end
result = result .. "Ratios\n"
-- Create the individual rows
-- Create the individual rows
Line 156: Line 155:
-- Stagger ratios
-- Stagger ratios
for j = 1, depth + edge_extend + 1 do
for j = 1, depth + edge_extend + 1 do
result = result .. "| "
if j == sb_tree_depths[i] then
if j == sb_tree_depths[i] then
result = result .. "|" .. sb_tree_ratios[i][1] .. "/" ..  sb_tree_ratios[i][2] .. "\n"
result = result .. sb_tree_ratios[i][1] .. "/" ..  sb_tree_ratios[i][2]
else
result = result .. "|\n"
end
end
result = result .. "\n"
end
end
else
else
-- Don't stagger ratios
-- Don't stagger ratios
result = result .. "|" .. sb_tree_ratios[i][1] .. "/" .. sb_tree_ratios[i][2] .. "\n"
result = result .. "| " .. sb_tree_ratios[i][1] .. "/" .. sb_tree_ratios[i][2] .. "\n"
end
end
end
end
Line 170: Line 169:
result = result .. "|}"
result = result .. "|}"
return result
-- Debugger option
local debugg = yesno(frame.args["debug"])
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p