Example #1
0
class RandomLife(object):
    def __init__(self):
        self.life = Life(matrix_width, matrix_height, 1, color=BLACK)
        self.graphics = Graphics(matrix_width, matrix_height)

    def pickRandomColor(self):
        color = random.randint(0, len(COLORS) - 1)
        # make sure that that color isn't black
        while(COLORS[color] == BLACK):
            color = random.randint(0, len(COLORS) - 1)
        return COLORS[color]

    def drawRandomColor(self):
        life_matrix = self.graphics.toMatrix(self.life.field,
                                             self.graphics.getSurfaceWidth())
        for y in self.graphics.heightRange:
            for x in self.graphics.widthRange:
                if life_matrix[y][x]:
                    color = self.pickRandomColor()
                    # give every lifing cell a random color
                    self.graphics.drawPixel(x, y, color)
                else:
                    self.graphics.drawPixel(x, y, BLACK)

    def draw(self):
        self.drawRandomColor()

    def generate(self):
        self.life.process()
        self.draw()
        return self.graphics.getSurface()
Example #2
0
class BlueLife(object):
    def __init__(self):
        self.life = Life(matrix_width, matrix_height, 1, color=BLUE)
        self.graphics = Graphics(matrix_width, matrix_height)

    def draw(self):
        life_matrix = self.graphics.toMatrix(self.life.field, self.graphics.getSurfaceWidth())
        for y in self.graphics.heightRange:
            for x in self.graphics.widthRange:
                if life_matrix[y][x]:
                    color = BLUE
                else:
                    color = BLACK
                self.graphics.drawPixel(x, y, color)

    def generate(self):
        self.life.process()
        self.draw()
        return self.graphics.getSurface()
Example #3
0
 def __init__(self):
     self.life = Life(matrix_width, matrix_height, 1, color=BLACK)
     self.graphics = Graphics(matrix_width, matrix_height)