Guest User

Untitled

a guest
Nov 24th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. from Tkinter import *
  2. from math import sqrt, ceil
  3. from tools import Painter
  4. class App():
  5.     def repaint(self, handler):
  6.        
  7.         #get a count of blocks in area
  8.         width=(handler.width-10)/10
  9.         height=(handler.height-10)/10
  10.        
  11.         #clear a canvas by tag
  12.         self.canvas.delete('block')
  13.         self.canvas.delete('line')
  14.        
  15.         #debug info
  16.         self.canvas.create_line(0, 0, handler.width, handler.height, tag='line')
  17.         self.canvas.create_line(handler.width, 0, 0, handler.height, tag='line')
  18.        
  19.         #important notice: using a round function not a +1
  20.         a=min( round((width-1)/sqrt(3)), (height-1)/2)
  21.         print a, width, height, 'Resize!'
  22.        
  23.         #only even are interesting for me
  24.         if a%2==1:
  25.             a-=1
  26.            
  27.         # too small ='(
  28.         if(a<6):
  29.             return
  30.        
  31.         self.hexPainter.drawHexagon(a, width, height)
  32.        
  33.        
  34.     def __init__(self, root):
  35.         'Constructor. It creates a child widgets of root and binds a resize event'
  36.         self.canvas=Canvas(root)
  37.         a=6
  38.         width=round( sqrt(3)*a +1)
  39.         height=a*2 + 1
  40.         self.canvas.configure({"bg":'white', "width": width*11, "height": height*11})
  41.         self.canvas.pack(fill="both", expand=True)
  42.         self.hexPainter=Painter(self.canvas, 10)  
  43.         self.canvas.bind('<Configure>', self.repaint)
  44.         self.hexPainter.drawHexagon(a, width, height)
  45.            
  46.            
  47.  
  48. #main program. Creates a root widget, class instance and runs a mainloop
  49. root=Tk()
  50. root.title("First Lab")
  51. app=App(root)
  52.  
  53. root.mainloop()
Add Comment
Please, Sign In to add comment