Initial commit from version 1e-99
[beatscape.git] / rotowidget.py
1 import pygame
2 from bmevent import *
3 from keyhandler import *
4 from math import exp,pi,sqrt
5
6 # A rotowidget displays two axes of information in a rotary fashion.  A
7 # central "pulser" is designed to show the score, and an arc around the
8 # edge shows the progress through the song.
9 class RotoWidget:
10         # Color format: (level, color)
11         # If the first item's level is greater than zero, the first
12         # color is black
13         pulsecolors = [(0,(180,0,0)), (80,(50,255,0))]
14         arccolors = [(0,(200,0,200))]
15         r = -0.2
16         
17         def __init__(self,center,radius,period):
18                 self.screen = pygame.display.get_surface()
19                 self.center = center
20                 self.radius = radius
21                 self.period = period
22                 self.pulsev = 0
23                 self.arcv = 0
24                 self.t = 0
25
26         def draw(self,t):
27                 rad = self.radius * (self.pulsev / 100.0) + (0.1 * self.radius) * exp(self.r * (t % self.period))
28                 if rad > self.radius:
29                         rad = self.radius
30
31                 pc = (0,0,0)
32                 for n in range(len(self.pulsecolors)-1,-1,-1):
33                         if self.pulsecolors[n][0] <= self.pulsev:
34                                 pc = self.pulsecolors[n][1]
35                                 break
36                 pygame.draw.circle(self.screen,pc,self.center,rad,0)
37
38                 ac = (0,0,0)
39                 for n in range(len(self.arccolors)-1,-1,-1):
40                         if self.arccolors[n][0] <= self.arcv:
41                                 ac = self.arccolors[n][1]
42                                 break
43                 pygame.draw.arc(self.screen,ac,(self.center[0]-self.radius, self.center[1]-self.radius, self.radius*2, self.radius*2),0,2*pi*(self.arcv / 100.0),3)
44