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[1][0][0]))
        dotB = float(dot(spinArray[1][0][0],spinArray[2][0][0]))        # centers around 0 in one attractor???
        dotC = float(dot(spinArray[2][0][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
     
#        self.angleCurveA.plot(pos=(t,diffAngleA))       # centers around 2.5 ?
        self.angleCurveB.plot(pos=(t,diffAngleB))       # centers around pi/2
#        self.angleCurveC.plot(pos=(t,diffAngleC))       # centers around 2.25

        
    def updateCurves(self,spinArray,t):
        dotA = float(dot(spinArray[0][0][0],spinArray[1][0][0]))
        dotB = float(dot(spinArray[1][0][0],spinArray[2][0][0]))
        dotC = float(dot(spinArray[2][0][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
               
#        self.angleCurveA.plot(pos=(t,diffAngleA))
        self.angleCurveB.plot(pos=(t,diffAngleB))
#        self.angleCurveC.plot(pos=(t,diffAngleC))
        

    def resetPoints(self):
        pass





