Esempio n. 1
0
    def test_scroll_animation_horizontally_from_right_to_left(self):
        text_height = 10
        font = Font()
        font.auto_adjust_font_size_to_height(text_height)
        background_color = Color.Red()
        effect = TextEffect(Color.Blue(), background_color)
        text = "KeesWare"
        effect.draw_text(text, font)
        effect.crop()
        self.image = effect.get_image()

        animation_size = (30, 10)
        animation = ScrollAnimation(animation_size, self.image,
                                    background_color)
        start_point = [animation_size[0], 0]
        image_size = self.image.size
        end_point = [-image_size[0], 0]
        # move by one pixel per frame
        frames_amount = image_size[0] + animation_size[0]

        animation.pre_render(start_point, end_point, frames_amount)
        first_frame = animation[0]
        middle_frame = animation[len(animation) / 2]
        animation.save("2.gif")

        self.assertEqual(first_frame.getpixel((0, 0)),
                         background_color.get_as_tuple())
        self.assertEqual(middle_frame.size, animation_size)
        self.assertEqual(middle_frame.getpixel((0, 0)),
                         background_color.get_as_tuple())
        self.assertEqual(middle_frame.getpixel((1, 5)), (0, 0, 255))
        self.assertEqual(len(animation), frames_amount)
Esempio n. 2
0
    def test_paint_square(self):
        widget_size = (500, 1000)
        display_size = (50, 100)
        points = [[100, 100], [100, 900], [400, 900], [400, 100], [100, 100]]
        brush_color = Color.Red()
        point_size = 3
        effect = PaintEffect(display_size, widget_size)

        effect.set_point_size(point_size)
        effect.set_line_color(brush_color)
        effect.draw_lines(points)

        image = effect.get_image()
        self.assertEqual(image.size, display_size)
        self.assertEqual(image.getpixel((10, 10)), brush_color.get_as_tuple())
        self.assertEqual(image.getpixel((10, 90)), brush_color.get_as_tuple())
        self.assertEqual(image.getpixel((40, 90)), brush_color.get_as_tuple())
        self.assertEqual(image.getpixel((40, 10)), brush_color.get_as_tuple())