# animate.py
# Lillian Lee (LJL2)
# Mar 19, 2014

"""Convenience function for demoing A3 stuff in lecture (16)"""

import trial
import inflviz
import matplotlib
import matplotlib.pyplot as plt


def anim(tr):
    """Visualize each step of propagating through the rows of trial tr"""
    # Assumes you have the definitions of Node and Trial correct.
    # An inelegant implementation of animation, but it was quick to code up.

    trial.showit(tr)

    for gen in range(tr.g - 1):
        # Check if there are any converted nodes in the current generation
        some_converted = False
        for node in tr.nodelist[gen]:
            if node.is_converted():
                some_converted = True
        if some_converted:
            # There is a propagation to animate
            tr._propagate_row(gen)
            inflviz.plot_trial(tr)
            plt.show()
        plt.show()

if __name__ == '__main__':
    g=10; n=10; c=4; d=3; t=2

    d = int(raw_input('Choose d: '))
    t = int(raw_input('Choose t: '))

    print "trial: d=" + str(d) + ", t=" + str(t)
    t = trial.Trial(g=g,n=n,c=c,d=d,t=t)
    anim(t)