Created
May 15, 2019 20:20
-
-
Save jg75/f1b5e225e1157491663e84fce5321e39 to your computer and use it in GitHub Desktop.
FoxDot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""An example of procedurally generated music using FoxDot.""" | |
from atexit import register | |
from FoxDot import Clock, pluck, p1 | |
def fibonacci(n): | |
"""Get a list of numbers in the fibonacci sequence.""" | |
step = 1 if n >= 0 else -1 | |
seq = [0, 1] | |
for _ in range(step, n, step): | |
seq.append(seq[-2] + seq[-1] if step == 1 else seq[-2] - seq[-1]) | |
return seq | |
def play(): | |
"""Play the fibonacci sequence.""" | |
sequence = fibonacci(9)[2:] | |
sustain = [i for i in range(len(sequence), 0, -1)] | |
register(Clock.clear) | |
p1 >> pluck(sequence, sus=sustain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment