from tkinter import *
import random
def Pole(xA, yA, xB, yB, xC, yC):
s1 = xA*yB - yA*xB
s2 = xB*yC - yB*xC
s3 = xC*yA - yC*xA
return (s1+s2+s3)/2
def Losuj():
print("--- Losuj ----------------------------------------------")
plotno.delete('all')
plotno.create_window(10, 10, anchor=NW, window=przycisk)
x1 = random.randrange(0, width)
y1 = random.randrange(0, height)
x2 = random.randrange(0, width)
y2 = random.randrange(0, height)
x3 = random.randrange(0, width)
y3 = random.randrange(0, height)
x4 = random.randrange(0, width)
y4 = random.randrange(0, height)
print("P1 : x =",x1,"y =",y1)
print("P2 : x =",x2,"y =",y2)
print("P3 : x =",x3,"y =",y3)
print("P4 : x =",x4,"y =",y4)
p1 = Pole(x3, y3, x4, y4, x1, y1)
p2 = Pole(x3, y3, x4, y4, x2, y2)
p3 = Pole(x1, y1, x2, y2, x3, y3)
p4 = Pole(x1, y1, x2, y2, x4, y4)
print("Pole 1 =",p1)
print("Pole 2 =",p2)
print("Pole 3 =",p3)
print("Pole 4 =",p4)
if ((p1 * p2 > 0) or (p3 * p4 > 0)):
kolor = 'black'
else:
kolor = 'red'
plotno.create_line(x1, y1, x2, y2, fill=kolor, width=3)
plotno.create_line(x3, y3, x4, y4, fill=kolor, width=3)
return
okno = Tk()
width=500
height=500
plotno = Canvas(okno, width=width, height=height, background='white')
plotno.grid(row=1,column=1)
przycisk = Button(okno,text='Losuj', command = Losuj, anchor=W)
przycisk.configure(width =10, activebackground = 'grey', relief = FLAT)
plotno.create_window(10,10, anchor=NW, window=przycisk)
okno.mainloop()