def test_drawline_inverted_ok(self): canvas = Canvas() canvas.create(8, 4) canvas.draw_line(5, 1, 5, 3) canvas2 = Canvas() canvas2.create(8, 4) canvas2.draw_line(5, 3, 5, 1) self.assertTrue((canvas.data == canvas2.data).all())
def test_drawline_vertical_cropped_ok(self): canvas = Canvas() canvas.create(8, 4) canvas.draw_line(5, -3, 5, 14) expected = np.asarray([[32, 32, 32, 32, 120, 32, 32, 32], [32, 32, 32, 32, 120, 32, 32, 32], [32, 32, 32, 32, 120, 32, 32, 32], [32, 32, 32, 32, 120, 32, 32, 32]], dtype='uint8') self.assertTrue((canvas.data == expected).all())
def test_drawline_horizontal_cropped_ok(self): canvas = Canvas() canvas.create(8, 4) canvas.draw_line(-2, 2, 10, 2) expected = np.asarray([[32, 32, 32, 32, 32, 32, 32, 32], [120, 120, 120, 120, 120, 120, 120, 120], [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_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())