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

        frame_buffer = [[] for _ in range(self.font.height())]

        current_y = 0

        for char in self.text:
            current_y = 0
            for line in self.font[char].glyph():
                for pixel in line:
                    if pixel:
                        frame_buffer[current_y].append(self.color)
                    else:
                        frame_buffer[current_y].append(Color(0, 0, 0))
                current_y += 1

            for line in frame_buffer:
                line.append(Color(0, 0, 0))

        for line in frame_buffer:
            line.pop()

        size = [len(line) for line in frame_buffer]

        text = Drawable(size, Color(0, 0, 0))
        text.framebuffer = frame_buffer

        return text
Пример #2
0
    def test_draw_other_within_left_bottom_corner(self):
        sut = Drawable([4, 4, 4, 4])
        to_draw = Drawable([2, 2])

        to_draw.framebuffer = [[1, 1], [1, 1]]

        sut.draw(0, 2, to_draw)
        self.assertEqual(
            sut.framebuffer,
            [[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0], [1, 1, 0, 0]])
Пример #3
0
    def test_draw_other_partiali_within_top_right_corner(self):
        sut = Drawable([4, 4, 4, 4])
        to_draw = Drawable([2, 2])

        to_draw.framebuffer = [[1, 1], [1, 1]]

        sut.draw(3, -1, to_draw)
        self.assertEqual(
            sut.framebuffer,
            [[0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
Пример #4
0
    def test_draw_other_within_middle(self):
        sut = Drawable([4, 4, 4, 4])
        to_draw = Drawable([2, 2])

        to_draw.framebuffer = [[1, 1], [1, 1]]

        sut.draw(1, 1, to_draw)
        self.assertEqual(
            sut.framebuffer,
            [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]])
Пример #5
0
    def test_draw_other_outside(self):
        sut = Drawable([4, 4, 4, 4])
        to_draw = Drawable([2, 2])

        to_draw.framebuffer = [[1, 1], [1, 1]]

        sut.draw(-10, 10, to_draw)
        self.assertEqual(
            sut.framebuffer,
            [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
Пример #6
0
    def test_draw_other_partiali_within_left_edge(self):
        sut = Drawable([4, 4, 4, 4])
        to_draw = Drawable([2, 2])

        to_draw.framebuffer = [[1, 1], [1, 1]]

        sut.draw(-1, 1, to_draw)
        self.assertEqual(
            sut.framebuffer,
            [[0, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0]])
Пример #7
0
    def test_draw_other_bigger(self):
        sut = Drawable([4, 4, 4, 4])
        to_draw = Drawable([6, 6, 6, 6, 6, 6])

        to_draw.framebuffer = [[1, 1, 1, 1, 1, 1], [1, 1, 0, 0, 1, 1],
                               [1, 0, 1, 1, 0, 1], [1, 1, 0, 1, 0, 1],
                               [1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1]]

        sut.draw(-1, -1, to_draw)
        self.assertEqual(
            sut.framebuffer,
            [[1, 0, 0, 1], [0, 1, 1, 0], [1, 0, 1, 0], [0, 1, 0, 1]])
Пример #8
0
    def test_clear(self):
        sut = Drawable([2, 2])
        sut.framebuffer = [[1, 1], [1, 1]]

        sut.clear()
        self.assertEqual(sut.framebuffer, [[0, 0], [0, 0]])