Graphics(canvas) -> Graphics
| 37 | ################################################################################ |
| 38 | |
| 39 | class Graphics: |
| 40 | |
| 41 | "Graphics(canvas) -> Graphics" |
| 42 | |
| 43 | __slots__ = 'canvas' |
| 44 | |
| 45 | def __init__(self, canvas): |
| 46 | "Initializes graphics by wrapping a canvas." |
| 47 | self.canvas = canvas |
| 48 | |
| 49 | def draw(self, polygon, fill, outline): |
| 50 | "Draws a polygon on the underlying canvas." |
| 51 | self.canvas.create_polygon(*itertools.chain(*polygon.vertices), |
| 52 | fill=fill, outline=outline) |
| 53 | |
| 54 | def write(self, x, y, text, fill): |
| 55 | "Writes the text to bottom-left of location." |
| 56 | self.canvas.create_text(x, y, text=text, fill=fill, anchor=tkinter.NW) |
| 57 | |
| 58 | def clear(self): |
| 59 | "Clears canvas of all objects shown on it." |
| 60 | self.canvas.delete(tkinter.ALL) |
| 61 | |
| 62 | def fill(self, background): |
| 63 | "Fills in the canvas with the given color." |
| 64 | self.canvas.configure(background=background) |
| 65 | |
| 66 | ################################################################################ |
| 67 |