daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from Tkinter import *
  2. from invaders import *
  3.  
  4. class App(object):
  5.   def __init__(self):
  6.     self.root = Tk()
  7.     self.root.title("Scalable Graphics Test")
  8.     self.root.minsize(144, 8)
  9.     self.root.aspect(144, 8, 144, 8)
  10.     self.cv = Canvas(self.root, width=576, height=32, bg="white", highlightthickness=0)
  11.     self.cv.pack(expand=True, fill=BOTH)
  12.     self.quantity = 12
  13.  
  14.     self.root.bind("<Configure>", self.redraw)
  15.     self.root.bind("q", lambda e: e.widget.quit())
  16.     self.root.mainloop()
  17.  
  18.   def draw_invader(self, x, y, width, height):
  19.     for coord in Invaders.front_invader:
  20.       cx = x + coord[1] * width
  21.       cy = y + coord[0] * height
  22.       self.cv.create_rectangle(cx, cy, cx + width, cy + height, fill="#8888ff", width="0")
  23.       self.cv.pack()
  24.  
  25.   def redraw(self, event):
  26.     self.cv.delete(ALL)
  27.     w, h = event.width, event.height
  28.     slot_width  = w / self.quantity
  29.     slot_height = h
  30.     invader_width  = floor(slot_width / 12)
  31.     invader_height = floor(slot_height / 8)
  32.     for i in range(0, self.quantity):
  33.       x = i * slot_width
  34.       self.draw_invader(x, 0, invader_width, invader_height)
  35.  
  36. App()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top