Created
October 29, 2016 01:23
-
-
Save CharlyJazz/eb3b895d61c3c2a9ca611258b38981cc to your computer and use it in GitHub Desktop.
Python - Generator that creates the fibonacci sequence and then becomes dodecafonism song
This file contains 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
from __future__ import division | |
from itertools import chain | |
from pyknon.genmidi import Midi | |
from pyknon.music import Note, NoteSeq | |
def fib(n): | |
a, b = 0, 1 | |
fibo = [a, b] | |
while b < n: | |
fibo.append(b) | |
yield fibo | |
a, b = b, a + b | |
fibo_seq = chain(fib(10E10)) | |
seq = list(fibo_seq)[0] | |
midi = Midi(tempo=120) | |
midi.seq_notes(NoteSeq([Note(x % 12, 6, 1/16) for x in seq]), time=1) | |
midi.seq_notes(NoteSeq([Note(x % 21, 5, 1/16) for x in seq]), time=0) | |
midi.seq_notes(NoteSeq([Note(x % 12, 4, 1/16) for x in seq]), time=2) | |
midi.write("fibonacci.mid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment