/accuracygraph.py
import pygame
from bmevent import *
from keyhandler import *

class AccuracyGraph:
	linecolor = (255,255,0)
	tickcolor = (200,200,200)
	accpoints = [-90,-60,-30,-15,0,15,30,60,90]
	
	def __init__(self,rect):
		self.screen = pygame.display.get_surface()
		self.disprect = rect
		self.datapoints = [0]
		self.ratio = rect.height / 100.0
		self.tickpoints = map(lambda y: (y * self.ratio) + (rect.height/2), self.accpoints)
		self.n_hits = 0
		self.total = 0

	def addpoint(self,point):
		self.datapoints[0] = point
		self.total += point
		self.n_hits += 1
		return self.total / float(self.n_hits)

	def draw(self):
		self.screen.fill((0,0,0), self.disprect)
		for t in self.tickpoints:
			y = self.disprect.top + t
			pygame.draw.line(self.screen, self.tickcolor,
				(self.disprect.left, y), (self.disprect.right-1, y))
		if abs(self.datapoints[0]) > 100:
			return
		y = self.disprect.height / 2 + self.disprect.top + (self.datapoints[0] * self.ratio)
		pygame.draw.line(self.screen, self.linecolor,
			(self.disprect.left, y), (self.disprect.right, y),2)