Fall 2006»CSCI 199 Homework 4 Template

CSCI 199 Homework 4 Template


 *  Author:     {Your Name} 
* Course: CSCI 199, Section 03
* Assignment: Homework 4
* Due Date: {The assignment's due date}
* Certification of Authenticity {include one of the following}:
* I certify that this work is entirely my own.
* I certify that this work is my own, but I received
* some assistance from: {Name(s), References, etc.}


Describe your approach. What does the-System model? What is(are) its sound input(s). What is the output?


Attach sample inputs (accepted formats are .mid (max 60K) and .aif (max 3M).


Attach sample outputs (accepted formats are .mid (max 60K) and .aif (max 3M).


Attach your code below.

# l-system.music.py   Version 1.0    23-nov-06   (bzm)
# Demonstrates how to generate music using L-systems.

from jMusic import *

from lsystem import# for recursive system modeling
from stack import *    # for storing things

# define the axiom and rules
model = LSystem('A',
                     ('A', 'FF[-A][+A]FA'),
                     ('F', 'FF')

model.depth = 2

def interpet(model):
    "Defines the meaning of each production symbol."

    phrase = Phrase()
    stack = Stack()

    # define rules
    def F(phrase):
        "Draw one length in current orientation"
        note = Note(C4, HN)
        #print "down, forward", model.length

    def f(phrase):
        "Move (no draw) one length in current orientation."
        note = Rest()
        #print "up, forward", model.length

    def push(phrase):
        "Save current state."
        #print "push, new length", model.length, "heading", turtle.heading()

    def pop(phrase):
        "Restore saved state."
        #print "pop, new length", model.length, "heading", turtle.heading()

    def left(phrase):
        "Tilt to the left."
        note = Note(E4, QN)
        #print "turn left, new orientation", model.angle

    def right(phrase):
        "Tilt to the right."
        note = Note(G4, QN)
        #print "turn right, new orientation", turtle.heading()

    def A(phrase):
        "Do nothing."
        #print "do nothing"

    def error(phrase):
        "Unrecognized symbol."
        raise ValueError(symbol)        # let them know

    # create a dictionary of symbol meanings
    dictionary = {}
    dictionary['F'] = F
    dictionary['f'] = f
    dictionary['['] = push
    dictionary[']'] = pop
    dictionary['-'] = left
    dictionary['+'] = right
    dictionary['A'] = A

    # interpet symbols
    for symbol in model.string:
        #print symbol
        dictionary.get(symbol, error)(phrase)

    # pack the phrase into a part
    part = Part()

    # pack the part into a score titled 'Bing'
    score = Score("L-System")

    # play the score as MIDI (1 means 'do not exit')
    #Play.midi(score, 1)

    # write the score as a MIDI file to disk
    Write.midi(score, "l-system.mid")

def main():

    # generate productions
    while not model.done and model.generation < model.depth:
        #print model.generation, model.string

    # interpret latest production
    #print "Current directions", model.string

if __name__  == '__main__':