Created
September 9, 2011 21:12
-
-
Save basicxman/1207353 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Tkinter import * | |
| from invaders import * | |
| class App(object): | |
| def __init__(self): | |
| self.root = Tk() | |
| self.root.title("Scalable Graphics Test") | |
| self.root.minsize(144, 8) | |
| self.root.aspect(144, 8, 144, 8) | |
| self.cv = Canvas(self.root, width=576, height=32, bg="white", highlightthickness=0) | |
| self.cv.pack(expand=True, fill=BOTH) | |
| self.quantity = 12 | |
| self.root.bind("<Configure>", self.redraw) | |
| self.root.bind("q", lambda e: e.widget.quit()) | |
| self.root.mainloop() | |
| def draw_invader(self, x, y, width, height): | |
| for coord in Invaders.front_invader: | |
| cx = x + coord[1] * width | |
| cy = y + coord[0] * height | |
| self.cv.create_rectangle(cx, cy, cx + width, cy + height, fill="#8888ff", width="0") | |
| self.cv.pack() | |
| def redraw(self, event): | |
| self.cv.delete(ALL) | |
| w, h = event.width, event.height | |
| slot_width = w / self.quantity | |
| slot_height = h | |
| invader_width = floor(slot_width / 12) | |
| invader_height = floor(slot_height / 8) | |
| for i in range(0, self.quantity): | |
| x = i * slot_width | |
| self.draw_invader(x, 0, invader_width, invader_height) | |
| App() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment