boris-vlasenko

Площадь треугольника по формуле Герона

Jul 5th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. from random import randrange as rnd
  2. from tkinter import *
  3.  
  4. root = Tk()
  5. root.geometry('600x600')
  6. canv = Canvas(bg='white')
  7. canv.pack(fill=BOTH, expand=1)
  8.  
  9. x1 = None
  10. y1 = None
  11. x2 = None
  12. y2 = None
  13. x3 = None
  14. y3 = None
  15.  
  16.    
  17. def geron(x1,y1,x2,y2,x3,y3):
  18.     a12 = ((x2-x1)**2+ (y2-y1)**2)**0.5
  19.     a23 = ((x2-x3)**2+ (y2-y3)**2)**0.5
  20.     a13 = ((x3-x1)**2+ (y3-y1)**2)**0.5
  21.     p = (a12 + a23 + a13)/2
  22.     return (p*(p-a12)*(p-a23)*(p-a13))**0.5
  23.  
  24. def click(event):
  25.     global x1,x2,x3,y1,y2,y3
  26.     r = 3
  27.     x = event.x
  28.     y = event.y
  29.     if x1 is None:
  30.         x1 = x
  31.         y1 = y
  32.     elif x2 is None:
  33.         x2 = x
  34.         y2 = y
  35.     elif x3 is None:
  36.         x3 = x
  37.         y3 = y
  38.         canv.create_polygon(x1,y1,x2,y2,x3,y3,x1,y1, fill='orange')
  39.         s = geron(x1,y1,x2,y2,x3,y3)
  40.         print(s)
  41.         canv.create_text(300,300,text=s,fill='gray',font='Tahoma 30')
  42.     else:
  43.         canv.delete(ALL)
  44.         x1 = x
  45.         y1 = y
  46.         x2 = None
  47.         y2 = None
  48.         x3 = None
  49.         y3 = None
  50.        
  51.     canv.create_oval(x-r,y-r,x+r,y+r,fill='orange')
  52.    
  53. root.bind('<1>',click)
  54.  
  55. mainloop()
Add Comment
Please, Sign In to add comment