def draw(self): '''Draws all objects that are in the gameobjects list to the screen''' self.screen.fill((0, 0, 0)) yaxis = Line(WHITE, 5) yaxis.draw(self.screen, [ Vector2(0, -(SCREEN_HEIGHT / 2)), Vector2(0, (SCREEN_HEIGHT / 2)) ]) xaxis = Line(WHITE, 5) xaxis.draw( self.screen, [Vector2(-(SCREEN_WIDTH / 2), 0), Vector2(SCREEN_WIDTH / 2, 0)]) mxpos, mypos = pygame.mouse.get_pos() mouse = Rectangle(WHITE, Vector2(25, 25)) mpos = worldtoscreen(Vector2(mxpos, mypos)) mpos = mpos.scale(-1) mouse.draw(self.screen, mpos) for gameobject in self.gameobjects: gameobject.draw(self.screen)
# This program tests several of the geometric shape classes. # from ezgraphics import GraphicsWindow from shapes import Rectangle, Line # Create the window. win = GraphicsWindow() canvas = win.canvas() # Draw a rectangle. rect = Rectangle(10, 10, 90, 60) rect.setFill("light yellow") rect.draw(canvas) # Draw another rectangle. rect.moveBy(rect.getWidth(), rect.getHeight()) rect.draw(canvas) # Draw six lines of different colors. colors = ["red", "green", "blue", "yellow", "magenta", "cyan"] line = Line(10, 150, 300, 150) for i in range(6): line.setColor(colors[i]) line.draw(canvas) line.moveBy(10, 40) win.wait()