User:Xenwolf/Python: Difference between revisions

Xenwolf (talk | contribs)
m add automatic table of contents
Xenwolf (talk | contribs)
Generate EDO exposés: retailored function
 
Line 31: Line 31:
== Generate EDO exposés ==
== Generate EDO exposés ==


The following script creates most of the parameters for the EDO info boxes (1..99):
The following script creates most of the parameters for EDO info boxes, it can also be used as a module:


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import math
import math


# formatted size string
# step size in cents
def ed_interval_size(steps, division=12, equiv=2, digits=0):
def ed_interval_size(steps, division=12, equiv=2):
     return f'{math.log(equiv, 2)/division*steps * 1200:.{digits}f}'
     return math.log(equiv, 2)/division * steps * 1200


def ed_expose(n):
# format (most of) of XenWiki info box
def edo_info(n):
    a = ed_interval_size(1, n, 2)
     p5s = round(n*math.log(3/2, 2))
     p5s = round(n*math.log(3/2, 2))
     p5c = round(p5s*1200/n)
     p5c = round(p5s*1200/n)
Line 54: Line 56:
     A1 = f'{A1s}\{n} ({A1c}¢)'
     A1 = f'{A1s}\{n} ({A1c}¢)'
     print(f'{n} EDO ')
     print(f'{n} EDO ')
     print(f'| Step size = {ed_interval_size(1, n, 2, 5)}¢')
     print(f'| Step size = {a:.5f}¢')
     print(f'| Fifth = {p5}')
     print(f'| Fifth = {p5}')
     print(f'| Major 2nd = {M2}')
     print(f'| Major 2nd = {M2}')
Line 61: Line 63:
     print()
     print()


# some examples
if __name__ == "__main__":
for n in range(1, 100):
    # some EDO examples
    ed_expose(n)
    for n in range(1, 100):
        ed_expose(n)
</syntaxhighlight>
</syntaxhighlight>