Added euclidean evaluation

This commit is contained in:
2023-02-19 22:56:11 +02:00
parent cca08b250f
commit 9a4c970b95
3 changed files with 69 additions and 6 deletions

View File

@ -53,3 +53,23 @@ def string_rewrite(axiom: str, rules: dict):
pattern = re.compile("|".join(rules.keys()))
return pattern.sub(lambda m: next(_apply_rules(m)), axiom)
def euclidian_rhythm(pulses: int, length: int, rotate: int = 0):
"""Calculate Euclidean rhythms. Original algorithm by Thomas Morrill."""
def _starts_descent(list, index):
length = len(list)
next_index = (index + 1) % length
return list[index] > list[next_index]
def rotation(l, n):
return l[-n:] + l[:-n]
if pulses >= length:
return [True]
res_list = [pulses * t % length for t in range(-1, length - 1)]
bool_list = [_starts_descent(res_list, index) for index in range(length)]
return rotation(bool_list, rotate)