/rotowidget.py
import pygame
from bmevent import *
from keyhandler import *
from math import exp,pi,sqrt

# A rotowidget displays two axes of information in a rotary fashion.  A
# central "pulser" is designed to show the score, and an arc around the
# edge shows the progress through the song.
class RotoWidget:
	# Color format: (level, color)
	# If the first item's level is greater than zero, the first
	# color is black
	pulsecolors = [(0,(180,0,0)), (80,(50,255,0))]
	arccolors = [(0,(200,0,200))]
	r = -0.2
	
	def __init__(self,center,radius,period):
		self.screen = pygame.display.get_surface()
		self.center = center
		self.radius = radius
		self.period = period
		self.pulsev = 0
		self.arcv = 0
		self.t = 0

	def draw(self,t):
		rad = self.radius * (self.pulsev / 100.0) + (0.1 * self.radius) * exp(self.r * (t % self.period))
		if rad > self.radius:
			rad = self.radius

		pc = (0,0,0)
		for n in range(len(self.pulsecolors)-1,-1,-1):
			if self.pulsecolors[n][0] <= self.pulsev:
				pc = self.pulsecolors[n][1]
				break
		pygame.draw.circle(self.screen,pc,self.center,rad,0)

		ac = (0,0,0)
		for n in range(len(self.arccolors)-1,-1,-1):
			if self.arccolors[n][0] <= self.arcv:
				ac = self.arccolors[n][1]
				break
		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)