June 2002
Beginner to intermediate
640 pages
14h 24m
English
We've covered all of the classes. At this point, you may want to run the Shapes and DrawShapes modules to see the drawing package in action. Here's the Shapes module.
class Shape: def __init__(self, x, y, width=0, height=0, color=None, fill=0): self.x=x self.y=y self.width=width self.height=height self.color=color self.fill=fill def paint(self, graphics): if not self.color is None: oldcolor = graphics.foregroundColor graphics.color = self.color if self.fill: self.draw_filled(graphics) else: self.draw_outline(graphics) if not self.color is None: graphics.color = oldcolor def draw_filled(self, graphics): pass def draw_outline(self, graphics): pass def getRect(self): return self.x, self.y, self.width, ...
Read now
Unlock full access