Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- from math import sqrt, ceil
- from tools import Painter
- class App():
- def repaint(self, handler):
- #get a count of blocks in area
- width=(handler.width-10)/10
- height=(handler.height-10)/10
- #clear a canvas by tag
- self.canvas.delete('block')
- self.canvas.delete('line')
- #debug info
- self.canvas.create_line(0, 0, handler.width, handler.height, tag='line')
- self.canvas.create_line(handler.width, 0, 0, handler.height, tag='line')
- #important notice: using a round function not a +1
- a=min( round((width-1)/sqrt(3)), (height-1)/2)
- print a, width, height, 'Resize!'
- #only even are interesting for me
- if a%2==1:
- a-=1
- # too small ='(
- if(a<6):
- return
- self.hexPainter.drawHexagon(a, width, height)
- def __init__(self, root):
- 'Constructor. It creates a child widgets of root and binds a resize event'
- self.canvas=Canvas(root)
- a=6
- width=round( sqrt(3)*a +1)
- height=a*2 + 1
- self.canvas.configure({"bg":'white', "width": width*11, "height": height*11})
- self.canvas.pack(fill="both", expand=True)
- self.hexPainter=Painter(self.canvas, 10)
- self.canvas.bind('<Configure>', self.repaint)
- self.hexPainter.drawHexagon(a, width, height)
- #main program. Creates a root widget, class instance and runs a mainloop
- root=Tk()
- root.title("First Lab")
- app=App(root)
- root.mainloop()
Add Comment
Please, Sign In to add comment