# konigsberg.py: simple python script for traversing the seven bridges of # konigsberg and creating a csound score from the resulting path # Adam Parrish # algorithmic composition # itp fall 2007 from random import randrange max_moves = 1200 note_length = 7.5 time_step = 0.04 # 0: north bank # 1: nw bridge 1 # 2: nw bridge 2 # 3: ne bridge # 4: west island # 5: ew bridge # 6: east island # 7: sw bridge 1 # 8: sw bridge 2 # 9: se bridge # 10: south bank nodes = ( (1, 2, 3), (0, 4), (0, 4), (0, 6), (1, 2, 5, 7, 8), (4, 6), (2, 5, 9), (4, 10), (4, 10), (10, 6), (7, 8, 9) ) notes = ( '10.00', '9.11', '9.05', '9.07', '8.00', '8.07', '9.00', '7.05', '7.07', '7.11', '7.00' ) if __name__ == '__main__': # print function table definition print "f 1 0 512 10 1" curtime = 0 curnode = randrange(len(nodes)) moves = [] for i in range(max_moves): print "i 1 %.4f %.4f %s" % (curtime, note_length, notes[curnode]) moves.append(curnode) nextnode = -1 # keep getting a random node until we find one that hasn't occurred for # the past two turns while 1: nextnode = nodes[curnode][randrange(len(nodes[curnode]))] if nextnode not in moves[-2:]: break curtime = curtime + time_step curnode = nextnode