from Tkinter import *
from visual import *
from random import *

import time,sys,thread


phaseSpaceW = display(title='Phase Space', width=500, height=500, x=720, y=530, center=(0,0,0), background=(0.0,0.0,0.0))
phaseSpaceW.fov = pi/900.0
phaseSpaceW.forward = (-1,-1,-1)

phaseSpaceW.userzoom = 1
phaseSpaceW.userspin = 1
phaseSpaceW.range = 1.5
phaseSpaceW.visible = 1

phaseSpaceW.select()



##xAxis = []
##for x in arange(-1.0,1.0,1.999):
##    xAxis.append(vector(x,0,0))
##xAxisLine = curve(pos=xAxis, color=(.0,.0,.0))
##
##yAxis = []
##for y in arange(-1.0,1.0,1.999):
##    yAxis.append(vector(0,y,0))
##yAxisLine = curve(pos=yAxis, color=(.0,.0,.0))
##
##zAxis = []
##for z in arange(-1.0,1.0,1.999):
##    zAxis.append(vector(0,0,z))
##zAxisLine = curve(pos=zAxis, color=(.0,.0,.0))



class PhaseSpace:
    nSpinsX = 3
    nSpinsY = 2

    
    def __init__(self,nSpinsX,nSpinsY):
        self.nSpinsX = nSpinsX
        self.nSpinsY = nSpinsY
        
        polarDot = sphere(visible=0)


    def addPoint(self,spinArray):
        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)
        
        newpos = vector(dotA,dotB,dotC)
        self.polarDot = sphere(pos=newpos, color=(0.5,0.7,0.8), radius=0.002, visible=1)
        

    def resetPoints(self):
        pass
        
