Пример #1
0
    def init(self):

        try:
            import pygame
        except ImportError:
            raise BadEmulator("Pygame is not installed so cannot use Pygame emulator.")

        pygame.init()

        width=self.cols*100
        height=self.rows*100
        print("Making the screen ({:d}x{:d})".format(width,height))
        pygame.display.init()

        self.screen = pygame.display.set_mode((width, height))
        self.background = pygame.Surface(self.screen.get_size())
        self.background.fill(Colors.intToRGB(Colors.BLACK))
        systemFonts = pygame.font.get_fonts()
        monoFonts = [f for f in systemFonts if "mono" in f.lower()]
        if len(monoFonts) is 0:
            useFont = random.choice(systemFonts)
        else:
            useFont = random.choice(monoFonts)
        if "freemono" in systemFonts:   # I like it
            useFont = "freemono"
        self.font = pygame.font.SysFont(useFont, 14)
Пример #2
0
 def _buildAnimation (self):
     self.dropFrames()
     self.frame = LSFrameGen(self.height, self.width)
     cs = self.charString[:]
     if "right" in self.direction.lower():
         cs = reversed(cs)
     if self.height is 1:
         endCap = lambda x: self.width-1 if "left" in x.lower() else 0
         for i in range(0,self.iterations):
             for char in cs:
                 try:
                     color = next(self.color)
                 except TypeError:
                     color = self.color
                 colorMask = Colors.intToRGB(color)
                 charR = charG = charB = 0
                 (charR, charG, charB) = [char if i is not 0 else 0 for i in colorMask]
                 self.frame.edit(0, endCap(self.direction), (charR, charG, charB))
                 self.addFrame(self.frame.get())
                 self._pickShift()
             if True:
                 for i in range(0,self.width):
                     self.frame.edit(0, endCap(self.direction), (0, 0, 0))
                     self.addFrame(self.frame.get())
                     self._pickShift()
     else:
         raise NotImplementedError("height cannot be more than 1")
Пример #3
0
 def _addText(self, text, surface, pos):
     surfaceMeta = surface.get_rect()
     text = self.font.render(text, 1, Colors.intToRGB(Colors.WHITE))
     textMeta = text.get_rect()
     if str(pos[0]) == "center":
         pos = (surfaceMeta.width/2 - textMeta.width/2, pos[1])
     if str(pos[1]) == "center":
         pos = (pos[0], surfaceMeta.height/2 - textMeta.height/2)
     surface.blit(text, pos)
     return(surface)
Пример #4
0
 def _loadImage(self, tile):
     try:
         t = self._root.tiles[tile.row][tile.col].sensor
     except AttributeError:
         t = 0
     image = pygame.Surface((100, 100))
     if t is not 0:
         image = self._addText("{:d}%".format(int(t)), image, ("center",25))
     #    image = self._addText("{:d}%".format(int(t)), image, ("center",60))
     horizontal = (42,10)
     vertical = (10,30)
     segMap = [(29,10),(71,17),(71,52),(29,79),(19,52),(19,17),(29,45)]
     image.fill(Colors.intToRGB(tile.segments["a"]), pygame.Rect(segMap[0],horizontal))
     image.fill(Colors.intToRGB(tile.segments["b"]), pygame.Rect(segMap[1],vertical))
     image.fill(Colors.intToRGB(tile.segments["c"]), pygame.Rect(segMap[2],vertical))
     image.fill(Colors.intToRGB(tile.segments["d"]), pygame.Rect(segMap[3],horizontal))
     image.fill(Colors.intToRGB(tile.segments["e"]), pygame.Rect(segMap[4],vertical))
     image.fill(Colors.intToRGB(tile.segments["f"]), pygame.Rect(segMap[5],vertical))
     image.fill(Colors.intToRGB(tile.segments["g"]), pygame.Rect(segMap[6],horizontal))
     return image