def test_drawrect_no_inner_space_ok(self): canvas = Canvas() canvas.create(8, 5) canvas.draw_rect(2, 2, 6, 3) expected = np.asarray([[32, 32, 32, 32, 32, 32, 32, 32], [32, 120, 120, 120, 120, 120, 32, 32], [32, 120, 120, 120, 120, 120, 32, 32], [32, 32, 32, 32, 32, 32, 32, 32], [32, 32, 32, 32, 32, 32, 32, 32]], dtype='uint8') self.assertTrue((canvas.data == expected).all())
def test_drawrect_cropped_ok(self): canvas = Canvas() canvas.create(8, 5) canvas.draw_rect(-4, -3, 6, 4) expected = np.asarray([[32, 32, 32, 32, 32, 120, 32, 32], [32, 32, 32, 32, 32, 120, 32, 32], [32, 32, 32, 32, 32, 120, 32, 32], [120, 120, 120, 120, 120, 120, 32, 32], [32, 32, 32, 32, 32, 32, 32, 32]], dtype='uint8') self.assertTrue((canvas.data == expected).all())
def test_fill_ok(self): canvas = Canvas() canvas.create(10, 8) # Fill all canvas area with 'o' (ord('o') == 111) canvas.fill(5, 2, 'o') expected = np.asarray( [[111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 111, 111, 111, 111, 111, 111, 111, 111]], dtype='uint8') self.assertTrue((canvas.data == expected).all()) # Attempt to place the base point outside of the canvas - no effect canvas.fill(-1, 2, '+') self.assertTrue((canvas.data == expected).all()) # Draw some shapes to complicate the picture canvas.draw_line(2, 4, 9, 4) canvas.draw_rect(3, 2, 8, 20) expected = np.asarray( [[111, 111, 111, 111, 111, 111, 111, 111, 111, 111], [111, 111, 120, 120, 120, 120, 120, 120, 111, 111], [111, 111, 120, 111, 111, 111, 111, 120, 111, 111], [111, 120, 120, 120, 120, 120, 120, 120, 120, 111], [111, 111, 120, 111, 111, 111, 111, 120, 111, 111], [111, 111, 120, 111, 111, 111, 111, 120, 111, 111], [111, 111, 120, 111, 111, 111, 111, 120, 111, 111], [111, 111, 120, 111, 111, 111, 111, 120, 111, 111]], dtype='uint8') self.assertTrue((canvas.data == expected).all()) # Fill regions with various symbols: '+' a.k.a. 43, '*' a.k.a. 42, '.' a.k.a. 46 canvas.fill(5, 3, '+') canvas.fill(6, 7, '*') canvas.fill(10, 8, '.') expected = np.asarray( [[46, 46, 46, 46, 46, 46, 46, 46, 46, 46], [46, 46, 120, 120, 120, 120, 120, 120, 46, 46], [46, 46, 120, 43, 43, 43, 43, 120, 46, 46], [46, 120, 120, 120, 120, 120, 120, 120, 120, 46], [46, 46, 120, 42, 42, 42, 42, 120, 46, 46], [46, 46, 120, 42, 42, 42, 42, 120, 46, 46], [46, 46, 120, 42, 42, 42, 42, 120, 46, 46], [46, 46, 120, 42, 42, 42, 42, 120, 46, 46]], dtype='uint8') self.assertTrue((canvas.data == expected).all())