from visual.graph import *
from random import *

graphone = gcurve(color=color.cyan)
graphtwo = gcurve(color=color.red)
graphthree = gcurve(color=color.yellow)

newlist = list()

newlistone = list()
newlisttwo = list()

graphpos = list()
graphipos = list()
graphdpos = list()

thesum = 0
total = 0

maxN = 480
maxRun = 1

run = 0

v = 0
l = -v


def ci(element1,element2):
    if element1 == "T" and element2 == "T":
        return('T')
    if element1 == "T" and element2 == "F":
        return('C')
    if element1 == "T" and element2 == "O":
        return('T')
    if element1 == "T" and element2 == "C":
        return('F')

        
    if element1 == "F" and element2 == "T":
        return('C')
    if element1 == "F" and element2 == "F":
        return('F')
    if element1 == "F" and element2 == "O":
        return('F')
    if element1 == "F" and element2 == "C":
        return('T')
        
        
    if element1 == "O" and element2 == "T":
        return('T')
    if element1 == "O" and element2 == "F":
        return('F')
    if element1 == "O" and element2 == "O":
        return('O')
    if element1 == "O" and element2 == "C":
        return('O')

    if element1 == "C" and element2 == "T":
        return('F')
    if element1 == "C" and element2 == "F":
        return('T')
    if element1 == "C" and element2 == "O":
        return('O')  
    if element1 == "C" and element2 == "C":
        return('C')

def su(element1,element2):
    if element1 == "T" and element2 == "T":
        return('T')
    if element1 == "T" and element2 == "F":
        return('O')
    if element1 == "T" and element2 == "O":
        return('T')
    if element1 == "T" and element2 == "C":
        return('T')

        
    if element1 == "F" and element2 == "T":
        return('O')
    if element1 == "F" and element2 == "F":
        return('F')
    if element1 == "F" and element2 == "O":
        return('F')
    if element1 == "F" and element2 == "C":
        return('F')
        
        
    if element1 == "O" and element2 == "T":
        return('T')
    if element1 == "O" and element2 == "F":
        return('F')
    if element1 == "O" and element2 == "O":
        return('O')
    if element1 == "O" and element2 == "C":
        return('C')

    if element1 == "C" and element2 == "T":
        return('T')
    if element1 == "C" and element2 == "F":
        return('F')
    if element1 == "C" and element2 == "O":
        return('C')  
    if element1 == "C" and element2 == "C":
        return('C')
        
def product(oldlist,newlist,l):
    product = 0.0
    for m in xrange(l):
        product = compound(oldlist[m],product)
    return(productone)

def graphlist(givenlist):
    total = 0.0
    outlist = list()
    for n in xrange(maxN-1):
        if givenlist[n] == "T":
            total += 1
        if givenlist[n] == "F":
            total -= 1
        average = total/(n+1)
        outlist.append(average)
    return outlist

while run < maxRun:
    run += 1

    l = -v
    while l < maxN:  
        l += 1
        
        U = random()
        if 0 < U < .25:
            W = "F"
        if .25 < U < .5:
            W = "T"
        if .5 < U < .75:
            W = "O"
        if .75 < U < 1:
            W = "C"

        newlist.append(W)

    for n in xrange(maxN-1):
        newlistone.append(su(newlist[n],newlist[n+1]))
        newlisttwo.append(ci(newlist[n],newlist[n+1]))
        
    print("New List",newlist)
    print("Integral",newlistone)
    print("Derivative",newlisttwo)

    graphpositions = graphlist(newlist)
    graphipositions = graphlist(newlistone)
    graphdpositions = graphlist(newlisttwo)
    
    for n in xrange(maxN):
        graphone.plot(pos=(n,graphpositions[n]))
        graphtwo.plot(pos=(n,graphipositions[n]))
        graphthree.plot(pos=(n,graphdpositions[n]))    

