Skip to content

Commit

Permalink
Revert "gafo"
Browse files Browse the repository at this point in the history
This reverts commit 085715e.
  • Loading branch information
DualFennecFox committed Jul 17, 2024
1 parent 085715e commit 952e8fd
Showing 1 changed file with 34 additions and 133 deletions.
167 changes: 34 additions & 133 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tkinter
from tkinter import *
from tkinter import ttk
import math

import sv_ttk

entry_a = 0
Expand All @@ -13,132 +13,8 @@
Lista_a = 0
Lista_b = 0
matriz_binaria_R = []
ListaTuplasLista = []


W = 820
H = 650
scaled = 300

def scale(nodes):

negated_nodes = [(x, -y) for x, y in nodes]
scaled_nodes = [(x * scaled, y * scaled) for x, y in negated_nodes]
centered_nodes = [(x + W / 2, y + H / 2) for x, y in scaled_nodes]

return centered_nodes


def grafo():
for widget in frame2.winfo_children():
widget.destroy()

if len(ListaTuplasLista) == 0:

label2 = ttk.Label(frame2, text="Primero debe crear conjuntos para ver esta ventana.")
label2.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
return

canvas = Canvas(frame2, width=W, height=H, bg="#1C1C1C")

nver = 0
points = []

tuplas = Lista_a
for i in range(len(Lista_b)):
tuplas.append(Lista_b[i])

tuplas = list(set(tuplas))

reldict = {}
items = []

for i in range(len(tuplas)):

if tuplas[i] in reldict:
continue
nver = nver + 1
reldict.update({tuplas[i]: (0, 0)})
items.append(tuplas[i])

for i in range(nver):
ra = 360/nver
angle = math.radians(i * ra)

# Calcular las coordenadas del vértice
x = 1 * math.cos(angle)
y = 1 * math.sin(angle)

# Dibujar el vértice (puedes personalizar su apariencia)

given_nodes = (
(x, y),
(x, y)
)
nodes = scale(given_nodes)

points.append(nodes[0])

radius = 20
for i in range(nver):
x, y = points[i]

if i+1 != len(points):
x2, y2 = points[i+1]

else:
x2, y2 = points[0]

#given_nodes = (
# (x, y),
# (W/2, H/2),
# (x2, y2),
#)

canvas.create_oval(x - radius, y - radius, x + radius, y + radius, outline="white")


#canvas.create_polygon(given_nodes, fill="blue", outline="white")
#canvas.create_line(x, y, x2, y2, fill="white")
reldict.update({tuplas[i]: (x, y)})


#renderoutsides(canvas)

for i in range(len(ListaTuplasLista)):

a, b = ListaTuplasLista[i]
xa, ya = reldict[a]
xb, yb = reldict[b]

color = "blue"
offset = -5
operand = -1
if xa > xb:
color = "red"
offset = -offset
operand = 1

if a == b:
canvas.create_oval(xa - radius, ya - radius, xa + radius, ya + radius, outline="green", width=2)
else:
canvas.create_line(
xa - offset,
ya - offset,
xb - offset,
yb - offset,
fill=color, arrow="last", width= 2)



for i in range(len(items)):
x, y = points[i]
canvas.create_text(x, y, fill="white", text=items[i], font="Times 15 bold")

canvas.pack(expand=True, fill="both")


def RepresentarMatriz(Lista_a, Lista_b):
def RepresentarMatriz(Lista_a, Lista_b, ListasString_Union, RelacionStringFormat):
if Lista_a == 0 and Lista_b == 0:
ErrorNR = Toplevel()
ErrorNR.geometry("380x160")
Expand Down Expand Up @@ -176,13 +52,18 @@ def RepresentarMatriz(Lista_a, Lista_b):
print(matriz_binaria_R[j][i], end=' | ')
print()#Salto de linea

print()#Salto de linea
MatrizPlantilla = ttk.Label(frame2, text=MatrizString(Lista_a, Lista_b, matriz_binaria_R))
print()#Salto de linea
A_B_Label = ttk.Label(frame2, text=ListasString_Union, foreground="white", font=("Ariel", 13, "bold"))
RelacionLabel = ttk.Label(frame2, text=RelacionStringFormat, foreground="white", font=("Ariel", 13, "bold"))
A_B_Label.place(relx=0.5, rely=0.05, anchor="center")
RelacionLabel.place(relx=0.5, rely=0.1, anchor="center")
MatrizPlantilla = ttk.Label(frame2, text=MatrizString(Lista_a, Lista_b, matriz_binaria_R), font=("Consolas", 16, "bold"))
MatrizPlantilla.place(relx=0.5, rely=0.5, anchor="center")


def PropiedadesRel(RelacionR, Lista_a, Lista_b):

global RelacionStringFormat
global ListasString_Union
if Lista_a == 0 and Lista_b == 0:
ErrorNR = Toplevel()
ErrorNR.geometry("380x160")
Expand All @@ -202,6 +83,17 @@ def PropiedadesRel(RelacionR, Lista_a, Lista_b):
simetria_R_Label = ttk.Label(frame2, text="Simetria: False", foreground="gray", font=("Ariel", 25))
asimetria_R_Label = ttk.Label(frame2, text="Asimetria: False", foreground="gray", font=("Ariel", 25))
antisimetria_R_Label = ttk.Label(frame2, text="Antisimetria: False", foreground="gray", font=("Ariel", 25))
ListasString_A = ",".join(Lista_a)
ListasString_B = ",".join(Lista_b)
RelacionSring = str(RelacionR).strip('[]').replace("'", "")
my_string_var = StringVar()
RelacionStringFormat = "R = {" + RelacionSring + "}"
ListasString_Union = "A = {" + ListasString_A + "}" + " " + " B = {" + ListasString_B + "}"
print("test: ", ListasString_Union)
A_B_Label = ttk.Label(frame2, text=ListasString_Union, foreground="white", font=("Ariel", 16, "bold"))
RelacionLabel = ttk.Label(frame2, text=RelacionStringFormat, foreground="white", font=("Ariel", 16, "bold"))
A_B_Label.place(relx=0.5, rely=0.05, anchor="center")
RelacionLabel.place(relx=0.5, rely=0.1, anchor="center")
reflexividad_R_Label.place(relx=0.5, rely=0.7, anchor="center")
irreflexivilidad_R_Label.place(relx=0.5, rely=0.6, anchor="center")
transitividad_R_Label.place(relx=0.5, rely=0.5, anchor="center")
Expand Down Expand Up @@ -367,6 +259,14 @@ def MatrizString(Lista_a, Lista_b, matriz_binaria_R):

def GenerarArreglo(ListaSeleccion_f, titulo_relaciones):
global RelacionR
global RelacionStringFormat
global ListasString_Union
ListasString_A = ",".join(Lista_a)
ListasString_B = ",".join(Lista_b)
RelacionSring = str(RelacionR).strip('[]').replace("'", "")
my_string_var = StringVar()
RelacionStringFormat = "R = {" + RelacionSring + "}"
ListasString_Union = "A = {" + ListasString_A + "}" + " " + " B = {" + ListasString_B + "}"
RelacionR = list(ListaSeleccion_f.get(0, "end"))

for i in range(len(RelacionR)):
Expand Down Expand Up @@ -417,7 +317,6 @@ def EnviarTodos(ListaTuplas, ListaSeleccion_f):
def relacionesLista(entry_a, entry_b, ListaTuplas):
global Lista_a
global Lista_b
global ListaTuplasLista
Lista_a = entry_a.get().split(",")
Lista_b = entry_b.get().split(",")
valor_a = entry_a.get()
Expand Down Expand Up @@ -459,6 +358,8 @@ def click_boton():

# VENTANA RELACIONES
def relaciones():
global RelacionStringFormat
global ListasString_Union
# se remueve el texto de bienvenida
for widget in frame2.winfo_children():
widget.destroy()
Expand Down Expand Up @@ -547,7 +448,7 @@ def relaciones():
# ventana principal
root = Tk()
root.title("Hecho por: Jonathan Salazar")
root.minsize(820, 650)
root.minsize(1280, 720)
root.maxsize(1280, 720)
root.resizable(False, False)

Expand All @@ -571,11 +472,11 @@ def relaciones():
rep_lab.grid(row=3, column=0, padx=10, pady=10)

# el resto de los botones
button = ttk.Button(frame1, text="Matriz", style="Button.TButton", command=lambda: RepresentarMatriz(Lista_a, Lista_b))
button = ttk.Button(frame1, text="Matriz", style="Button.TButton", command=lambda: RepresentarMatriz(Lista_a, Lista_b, RelacionStringFormat, ListasString_Union))
button.grid(row=4, column=0, padx=10, pady=10, sticky="ew")
button = ttk.Button(frame1, text="Sagital", style="Button.TButton", command=click_boton)
button.grid(row=5, column=0, padx=10, pady=10, sticky="ew")
button = ttk.Button(frame1, text="Grafo", style="Button.TButton", command=grafo)
button = ttk.Button(frame1, text="Grafo", style="Button.TButton", command=click_boton)
button.grid(row=6, column=0, padx=10, pady=10, sticky="ew")

# segundo frame
Expand Down

0 comments on commit 952e8fd

Please sign in to comment.