Initial commit from version 1e-99
[beatscape.git] / accuracygraph.py
1 import pygame
2 from bmevent import *
3 from keyhandler import *
4
5 class AccuracyGraph:
6         linecolor = (255,255,0)
7         tickcolor = (200,200,200)
8         accpoints = [-90,-60,-30,-15,0,15,30,60,90]
9         
10         def __init__(self,rect):
11                 self.screen = pygame.display.get_surface()
12                 self.disprect = rect
13                 self.datapoints = [0]
14                 self.ratio = rect.height / 100.0
15                 self.tickpoints = map(lambda y: (y * self.ratio) + (rect.height/2), self.accpoints)
16                 self.n_hits = 0
17                 self.total = 0
18
19         def addpoint(self,point):
20                 self.datapoints[0] = point
21                 self.total += point
22                 self.n_hits += 1
23                 return self.total / float(self.n_hits)
24
25         def draw(self):
26                 self.screen.fill((0,0,0), self.disprect)
27                 for t in self.tickpoints:
28                         y = self.disprect.top + t
29                         pygame.draw.line(self.screen, self.tickcolor,
30                                 (self.disprect.left, y), (self.disprect.right-1, y))
31                 if abs(self.datapoints[0]) > 100:
32                         return
33                 y = self.disprect.height / 2 + self.disprect.top + (self.datapoints[0] * self.ratio)
34                 pygame.draw.line(self.screen, self.linecolor,
35                         (self.disprect.left, y), (self.disprect.right, y),2)
36