aboutsummaryrefslogtreecommitdiff
path: root/renderers/PygameRenderer.py
blob: ad50c1e1b5f9bd18388a491fbbf7210c5834bbd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from operationscore.Renderer import *
import util.TimeOps as timeops 
import pygame
from pygame.locals import *
import pdb
class PygameRenderer(Renderer):
    """PygameRenderer is a renderer which renders the LightSystem to a pygame display"""

    def initRenderer(self):
        pygame.init()
        self.screen = pygame.display.set_mode((1300,500))
        self.background = pygame.Surface(self.screen.get_size())
        self.background = self.background.convert()
        self.background.fill(Color(0,0,0))
        self.stopwatch = timeops.Stopwatch()
        self.stopwatch.start()
    
    def render(self, lightSystem, currentTime=timeops.time()):
        self.background.fill(Color(0,0,0))
        #print 'drawing color:',light.color
        if 'Scale' in self:
            scale = self['Scale']
        else:
            scale = 1
        for light in lightSystem:
            scaledLoc = [l*scale for l in light.location] 
            pygame.draw.circle(self.background, light.state(currentTime), scaledLoc, \
                self['Scale'])

        self.screen.blit(self.background, (0,0))
        pygame.display.flip()
        self.stopwatch.stop()
        pygame.display.set_caption(str(int(1000/self.stopwatch.elapsed())))
        self.stopwatch.start()