Skip to content

Instantly share code, notes, and snippets.

@jg75
Created May 15, 2019 20:20
Show Gist options
  • Save jg75/f1b5e225e1157491663e84fce5321e39 to your computer and use it in GitHub Desktop.
Save jg75/f1b5e225e1157491663e84fce5321e39 to your computer and use it in GitHub Desktop.
FoxDot
"""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