Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randrange as rnd
- from tkinter import *
- root = Tk()
- root.geometry('600x600')
- canv = Canvas(bg='white')
- canv.pack(fill=BOTH, expand=1)
- x1 = None
- y1 = None
- x2 = None
- y2 = None
- x3 = None
- y3 = None
- def geron(x1,y1,x2,y2,x3,y3):
- a12 = ((x2-x1)**2+ (y2-y1)**2)**0.5
- a23 = ((x2-x3)**2+ (y2-y3)**2)**0.5
- a13 = ((x3-x1)**2+ (y3-y1)**2)**0.5
- p = (a12 + a23 + a13)/2
- return (p*(p-a12)*(p-a23)*(p-a13))**0.5
- def click(event):
- global x1,x2,x3,y1,y2,y3
- r = 3
- x = event.x
- y = event.y
- if x1 is None:
- x1 = x
- y1 = y
- elif x2 is None:
- x2 = x
- y2 = y
- elif x3 is None:
- x3 = x
- y3 = y
- canv.create_polygon(x1,y1,x2,y2,x3,y3,x1,y1, fill='orange')
- s = geron(x1,y1,x2,y2,x3,y3)
- print(s)
- canv.create_text(300,300,text=s,fill='gray',font='Tahoma 30')
- else:
- canv.delete(ALL)
- x1 = x
- y1 = y
- x2 = None
- y2 = None
- x3 = None
- y3 = None
- canv.create_oval(x-r,y-r,x+r,y+r,fill='orange')
- root.bind('<1>',click)
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement