from campy.graphics.gtypes import GPoint from campy.graphics.gwindow import GWindow # Width of the rectangle (in pixels). RECTANGLE_WIDTH = 350 # Height of the rectangle (in pixels). RECTANGLE_HEIGHT = 270 # Radius of each constructed arc. For the illusion to look interesting, this # should be no more than half the minimum of the rectangle's height and width. ARC_RADIUS = 50 if __name__ == '__main__': window = GWindow(title='Illusion') center = GPoint(window.width / 2, window.height / 2) corners = ( GPoint(center.x - RECTANGLE_WIDTH / 2, center.y - RECTANGLE_HEIGHT / 2), # Upper-left GPoint(center.x - RECTANGLE_WIDTH / 2, center.y + RECTANGLE_HEIGHT / 2), # Lower-left GPoint(center.x + RECTANGLE_WIDTH / 2, center.y + RECTANGLE_HEIGHT / 2), # Lower-right GPoint(center.x + RECTANGLE_WIDTH / 2, center.y - RECTANGLE_HEIGHT / 2), # Upper-right ) for corner, start in zip(corners, range(0, 360, 90)): arc = GArc(ARC_RADIUS * 2, ARC_RADIUS * 2, start=start,
def test_create_gpoint_with_default_values(): point = GPoint() assert True
height of 270 pixels in the center of the screen. """ from campy.graphics.gcolor import GColor from campy.graphics.gobjects import GRect from campy.graphics.gtypes import GPoint from campy.graphics.gwindow import GWindow # Width of the rectangle (in pixels). RECTANGLE_WIDTH = 350 # Height of the rectangle (in pixels). RECTANGLE_HEIGHT = 270 # Color of the rectangle. RECTANGLE_COLOR = GColor.BLUE if __name__ == '__main__': window = GWindow(title='Centered Rectangle') center = GPoint(window.width / 2, window.height / 2) rect = GRect(RECTANGLE_WIDTH, RECTANGLE_HEIGHT, x=center.x - RECTANGLE_WIDTH / 2, y=center.y - RECTANGLE_HEIGHT / 2) rect.filled = True rect.fill_color = RECTANGLE_COLOR window.add(rect) # Alternatively, don't set the rect's location at initialization and instead set it here. # window.add(rect, center.x - rect.width / 2, center.y - rect.height / 2)
def test_point_equality(): point = GPoint() empty = GPoint() assert point == empty assert not point != empty
def test_string(): point = GPoint() assert str(point) == "GPoint(x=0.0, y=0.0)"
def test_unpack_gpoint(): point = GPoint(4, 1) x, y = point assert x == 4 assert y == 1
def test_access_gpoint_components_by_index(): point = GPoint(4, 1) x, y = point[0], point[1] assert x == 4 assert y == 1
def test_access_gpoint_components_by_name(): point = GPoint(4, 1) x, y = point.x, point.y assert x == 4 assert y == 1