#!/usr/bin/env python

from numpy import *
from math import *
import Gnuplot, Gnuplot.funcutils
import time

class particle(object):
    
    def __init__(self,pos):
	self.trajectory = []
        self.move(pos)
	#self.position = pos
	#self.trajectory = pos

    def __str__(self):
	rep = "particle is at: " + repr(self.position) + "\n"
	rep2 = "its trajectory was" + repr(self.trajectory)
	return rep + rep2

    def move(self,pos):
	self.position = pos
	self.trajectory.append(pos)


    def plot_trajectory(self):
	"""Plot the trajectory of the particle using gnuplot
        """
    	g = Gnuplot.Gnuplot()
	#x,y,z = array_split(self.trajectory,3,axis=0)
	#print self.trajectory, x,y,z
	#g.splot(x,y,z)
        g.reset()
        #string = 'set title "time: ' + str(t) +' s"'
        #g(string)
        g('set ylabel "y-axis [arb. units]"')   #this is how you access gnupot commands
        g('set xlabel "x-axis [arb. units]"')
        g('set zlabel "z-axis [arb. units]"')
        data_rho = Gnuplot.Data(self.trajectory, with_ ='line', title = 'rho')
	g.splot(data_rho)
	#z = time.sleep(20.00) 	#wait a little so you can look at it


def main():
    pos = [0.,0.,0.]
    p = particle(pos)
    print p
    pos = [1.,2.,3.]
    p.move(pos)
    print p
    pos = [1.,3.,1.]
    p.move(pos)
    print p
    pos = [1.,5.,4.]
    p.move(pos)
    print p
    p.plot_trajectory()
    raw_input('Please press the return key to continue...\n')

main()
