-
Notifications
You must be signed in to change notification settings - Fork 0
/
visuel.py
54 lines (46 loc) · 1.98 KB
/
visuel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import tkinter as tk
from Structures.Vertex import Vertex
class Visuel:
def __init__(self, points: list[Vertex]):
self.points = points
self.wnd = tk.Tk()
self.wnd.title("Voronoi")
self.longeur = 200
self.hauteur = 200
self.offset = 50
self.wnd.geometry(str(self.longeur) + "x" + str(self.hauteur))
self.wnd.resizable(width=False, height=False)
self.cnv = tk.Canvas(self.wnd)
self.cnv.place(relx=0, rely=0, relwidth=1, relheight=1)
# on affiche tous les points dans le canva
self.affichage_point()
def affichage_point(self):
for i in self.points:
self.cnv.create_oval(i.x - 5 + self.offset,
i.y - 5 + self.offset,
i.x + 5 + self.offset,
i.y + 5 + self.offset,
fill="red")
def trace(self, p1: Vertex, p2: Vertex):
print("Trace")
self.cnv.create_line(p1.x, p1.y, p2.x, p2.y, width=3)
def trace1(self, p1: Vertex, p2: Vertex):
self.cnv.create_line(p1.x, p1.y, p2.x, p2.y, width=3, fill="red")
def hyperbola(self, focus: Vertex, directrix: float):
hyperbola = []
if focus.y == directrix:
return
for x in range(0, 100, 5):
y = (((focus.x - x) ** 2 + focus.y ** 2 - directrix ** 2) /
(2 * (focus.y - directrix)))
hyperbola.append((x + self.offset, y + self.offset))
self.cnv.create_line(hyperbola, tags="hyperbola")
self.cnv.update()
def reset_hyperbolas(self):
self.cnv.delete("hyperbola")
# pointtriangle est sous la forme d'une double liste qui contient trois
# point ex: [[4.2, 530.4], [61.8, 48.6], [82.2, 22.2]]
def triangle(self, pointtriangle):
for i in range(-1, 2):
self.trace(pointtriangle[i][0], pointtriangle[i][1],
pointtriangle[i + 1][0], pointtriangle[i + 1][1])