Module:Powharmonic series: Difference between revisions

ArrowHead294 (talk | contribs)
No edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local yesno = require("Module:Yesno")


function p.powharmonic(frame)
function p.powharmonic(frame)
     local n = tonumber(frame.args["n"])
     local n = tonumber(frame.args["n"])
     local expo = tonumber(frame.args["expo"])
     local expo = tonumber(frame.args["expo"])
     local out_str = "{| class=\"wikitable\"\n" ..
     local result = "{| class=\"wikitable center-all\"\n"
    "|+ Intervals of the " .. expo .. "-Powharmonic series\n" ..
    .. "|+ style=\"font-size: 105%; white-space: nowrap;\" | " .. string.format("Intervals of the %s-Powharmonic series\n", expo)
    "! rowspan=\"2\" | Pitch #\n" ..
    .. "|-\n"
    "! colspan=\"2\" | Frequency multiplier\n" ..
    .. "! rowspan=\"2\" | Pitch !! colspan=\"2\" | Frequency multiplier !! colspan=\"3\" | Pitch\n"
    "! colspan=\"3\" | Pitch\n" ..
    .. "|-\n"
    "|-\n" ..
    .. "! Definition !! Decimal !! [[Cent]]s !! Change (cents) !! Octave-reduced (cents)"
    "! Definition\n" ..
    .. "\n"
    "! Decimal\n" ..
     local fmt_cent = string.format("%%.%df", tonumber(frame.args["prec"]))
    "! Cents\n" ..
    "! Change (cents)\n" ..
    "! Octave-reduced\n"
     local fmt_mul = string.format("%%+.%df", tonumber(frame.args["prec"]))
    local fmt_cent = "%+.2f"
     local p_prev = 0
     local p_prev = 0
     local p_current = 0
     local p_current = 0
Line 22: Line 19:
     for i = 1, n do
     for i = 1, n do
         p_current = 1200 * math.log(i) / math.log(2) * expo
         p_current = 1200 * math.log(i) / math.log(2) * expo
         out_str = out_str ..
         result = result
            "|-\n" ..
            .. "|-\n"
            "| " .. i .. "\n" ..
            .. "| ".. string.format("%s", i)
            "| " .. i .. "<sup>" .. expo .. "</sup>\n" ..
            .. " || " .. string.format("%s<sup>%s</sup>", i, expo)
            "| " .. string.format(fmt_mul, i^expo) .. "\n" ..
            .. " || " .. string.format(fmt_cent, i^expo)
            "| " .. string.format(fmt_cent, p_current) .. "\n" ..
            .. " || " .. string.format(fmt_cent, p_current)
            "| " .. string.format(fmt_cent, p_prev) .. "\n" ..
            .. " || " .. string.format(fmt_cent, p_current - p_prev)
            "| " .. string.format(fmt_cent, math.fmod(p_current, 1200)) .. "\n"
            .. " || " .. string.format(fmt_cent, math.fmod(p_current, 1200))
         p_prev = p_current - p_prev
            .. "\n"
         p_prev = p_current
     end
     end


     out_str = out_str .. "|}"
     result = result .. "|}"
     return out_str
      
    -- 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