from Tkinter import *
from visual import *
from visual.graph import *

from random import *

import time,sys,thread


##anglePlotW = display(title='Angle Plots', xtitle='t', ytitle='Angle', width=600, height=200, x=620, y=430, background=(.95,.95,.95))
##anglePlotW.fov = pi/900.0
##anglePlotW.forward = (0,0,-1)

##anglePlotW.userzoom = 1
##anglePlotW.userspin = 1
##anglePlotW.autoscale = 1
##anglePlotW.visible = 1


class AnglePlot:
    nSpinsX = 3
    nSpinsY = 2

    angleCurveA = gcurve(color=color.red)
    angleCurveB = gcurve(color=color.green)
    angleCurveC = gcurve(color=color.blue)
        
   
    def __init__(self,nSpinsX,nSpinsY):
        self.nSpinsX = nSpinsX
        self.nSpinsY = nSpinsY
  

    def addCurves(self,spinArray,t):
        dotA = float(dot(spinArray[0][0][0],spinArray[0][1][0]))
        dotB = float(dot(spinArray[0][1][0],spinArray[0][2][0]))
        dotC = float(dot(spinArray[0][2][0],spinArray[0][0][0]))

##        if abs(dotA) < 1.0:     diffAngleA = arccos(dotA)
##        else:                   diffAngleA = pi
##        if abs(dotB) < 1.0:     diffAngleB = arccos(dotB)
##        else:                   diffAngleB = pi
##        if abs(dotC) < 1.0:     diffAngleC = arccos(dotC)
##        else:                   diffAngleC = pi
##        
##        newpos = vector(diffAngleA,diffAngleB,diffAngleC)
     
#        self.angleCurveA.plot(pos=(t,dotA))
        self.angleCurveB.plot(pos=(t,dotB))
#        self.angleCurveC.plot(pos=(t,dotC))

        
    def updateCurves(self,spinArray,t):
        dotA = float(dot(spinArray[0][0][0],spinArray[0][1][0]))
        dotB = float(dot(spinArray[0][1][0],spinArray[0][2][0]))
        dotC = float(dot(spinArray[0][2][0],spinArray[0][0][0]))

##        if abs(dotA) < 1.0:     diffAngleA = arccos(dotA)
##        else:                   diffAngleA = pi
##        if abs(dotB) < 1.0:     diffAngleB = arccos(dotB)
##        else:                   diffAngleB = pi
##        if abs(dotC) < 1.0:     diffAngleC = arccos(dotC)
##        else:                   diffAngleC = pi
##        
##        newpos = vector(diffAngleA,diffAngleB,diffAngleC)
        
#        self.angleCurveA.plot(pos=(t,dotA))
        self.angleCurveB.plot(pos=(t,dotB))
#        self.angleCurveC.plot(pos=(t,dotC))
        

    def resetPoints(self):
        pass





