From e8048865f911134819de9ba000d2f802d2f30785 Mon Sep 17 00:00:00 2001 From: Yassine EDDAFRY Date: Wed, 4 Jun 2025 15:18:02 +0000 Subject: [PATCH 1/3] finish implementing UI multiple triangle type logic --- .vscode/settings.json | 2 +- main.py | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a1af42c..555ce39 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,6 @@ "plaintext": false, "markdown": false, "scminput": false, - "python": true + "python": false } } \ No newline at end of file diff --git a/main.py b/main.py index c5cd7ba..3ded513 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,6 @@ #Setup blk = (0, 0, 0) root = Tk() -typeVal = ["Equilateral", "Isosceles", "Right"] try: root.iconbitmap("pencil.ico") root.title("autoDraw") @@ -42,21 +41,25 @@ def updateLabel(*args): type = comVarType.get() if shape == "Rectangle": en3.config(state="normal") + comType.config(state="disabled") lbl2Text.set("Length:") lbl3Text.set("Height:") elif shape == "Square": - lbl2Text.set("Side:") - lbl3Text.set("-") en3.config(state="disabled") - if shape == "Triangle" and type == "Equilateral": + comType.config(state="disabled") lbl2Text.set("Side:") lbl3Text.set("-") - en3.config(state="disabled") - elif shape == "Triangle" and type == "Isosceles" or type == "Right": - lbl2Text.set("Base:") - lbl3Text.set("Height:") - en3.config(state="normal") - if shape == None: + elif shape == "Triangle": + comType.config(state="normal") + if type == "Equilateral": + lbl2Text.set("Side:") + lbl3Text.set("-") + en3.config(state="disabled") + elif type in ("Isosceles", "Right"): + lbl2Text.set("Base:") + lbl3Text.set("Height:") + en3.config(state="normal") + elif shape is None or shape == "": lbl2Text.set("-") lbl3Text.set("-") en3.config(state="disabled") @@ -208,7 +211,7 @@ def cAsk(src: str): com.config(state="readonly") #ShapeType Dropdown lblType = ttk.Label(fr, text="Shape Type:") - comType = ttk.Combobox(fr, textvariable=comVarType, values=typeVal) + comType = ttk.Combobox(fr, textvariable=comVarType, values=["Equilateral", "Isosceles", "Right"]) com.current(0) comType.config(state="readonly") # Entry labels and boxes @@ -233,12 +236,14 @@ def cAsk(src: str): ebtn = ttk.Button(fr, text="⬇️ Export", command=lambda: msg.showinfo("Info", "This feature is not implemented yet.")) ########################Traces######################### comVar.trace_add("write", updateLabel) + comVarType.trace_add("write", updateLabel) chkvar3.trace_add("write", updateCheck) chkvar1.trace_add("write", updateCheck) ################ Layout ################ lbl.grid(row=0, column=0, sticky="w", padx=5, pady=5) com.grid(row=0, column=1, columnspan=2, sticky="ew", pady=5) comType.grid(row=1, column=1, columnspan=2, sticky="ew", pady=5) + lblType.grid(row=1, column=0, sticky="w", padx=5, pady=5) lbl2.grid(row=2, column=0, sticky="w", padx=5) en2.grid(row=2, column=1, columnspan=2, sticky="ew", pady=3) From aee4108678330e3275c2baf7a74ea15a0f354b73 Mon Sep 17 00:00:00 2001 From: Yassine EDDAFRY Date: Thu, 3 Jul 2025 22:19:00 +0000 Subject: [PATCH 2/3] feat: implement isosceles and right triangle drawing functions and stuff --- main.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 3ded513..dc03189 100644 --- a/main.py +++ b/main.py @@ -79,6 +79,8 @@ def __init__(self) -> None: self.rect = rect self.carr = carr self.tri_equi = tri_equi + self.tri_iso = tri_iso + self.tri_rect = tri_rect self.outColored = None self.outliner = turtle.Turtle() def cChooser(self, outline, fillcolor): @@ -162,9 +164,26 @@ def logic(self, filling, outlined): self.outDraw(self.tri_equi, self.outSize, None) turtle.done() case "Isosceles": - pass + window.deiconify() + if filling: + self.tri_iso(self.m1, self.m2, True, self.chosen_c) + elif not filling and not outlined: + self.tri_iso(self.m1, self.m2, False, None) + if outlined and self.outColored: + self.outDraw(self.tri_iso, self.outSize, self.outColor) + elif outlined and not self.outColored: + self.outDraw(self.tri_iso, self.outSize, None) + turtle.done() case "Right": - pass + if filling: + self.tri_rect(self.m1, self.m2, True, self.chosen_c) + elif not filling and not outlined: + self.tri_rect(self.m1,self.m2, False, None) + if outlined and self.outColored: + self.outDraw(self.tri_rect, self.outSize, self.outColor) + elif outlined and not self.outColored: + self.outDraw(self.tri_rect, self.outSize, None) + turtle.done() def outDraw(self, shape, size, src): self.outliner.pensize(size) self.outliner.penup() @@ -196,6 +215,17 @@ def outTriEqui(self, side): for _ in range(3): self.outliner.forward(side) self.outliner.left(120) + def outTrIso(self, side, base, fill): + height = (side ** 2 - (base / 2) ** 2) ** 0.5 + # Draw the isosceles triangle + angle = math.degrees(math.atan(height / (base / 2))) + self.outliner.forward(base) # Draw the base + self.outliner.left(180 - angle) # Turn to draw the first equal side + self.outliner.forward(side) # Draw the first equal side + self.outliner.left(2 * angle) # Turn to draw the second equal side + self.outliner.forward(side) + if fill == True: + self.outliner.end_fill() logic = Logic() def cAsk(src: str): From f907bf85b8358e0a1dd2f2bb384f1f05af15e731 Mon Sep 17 00:00:00 2001 From: Yassine EDDAFRY Date: Sun, 6 Jul 2025 15:29:58 +0000 Subject: [PATCH 3/3] fix: standardize turtle instance naming and improve triangle drawing functions --- geo/__pycache__/triangles.cpython-313.pyc | Bin 3209 -> 3237 bytes geo/triangles.py | 47 +++++++++++----------- main.py | 26 ++++++++++-- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/geo/__pycache__/triangles.cpython-313.pyc b/geo/__pycache__/triangles.cpython-313.pyc index b06f822b39cd433a218942ae8140bbea7dd3241b..0e16c8516abf5151a888aaa3ec5394908e4f36f1 100644 GIT binary patch delta 450 zcmeB_Tq?=?nU|M~0SNX?&C1By$a|NG(Pi^%rbW!GMWR5_$rIQNq*Q?naUd?f2P7I8 z?r;nC+jiM@+c&sOc4oGpEY5Bn#L@24=rcj&3X9kc7LIn$M$eAq39g;lS6HM#d~~_Q z396l$S6C!ae#|kAaq=rxen$Dp zjf^rP=?v)%nk;@HMKVAqy^I19ngWx%xkA;71VL<$Ta1af7?X;Gft(@{5CQT`krC$Smmr~xI#fw=f4kZ54I z!@<|j+r`_>-{5$Iop*vrbKMON&VKez_9@K0Jd@wCNeY2^6WDtAK@vQjJUx7qrP;0h zS=&7uJv&lb{BN+Zw!1aDbr??&?X0mn8*p>zgK7Qc`p8K6U7Mga*;{>jt0LKQVRZZRg_VoWL$ z28tDlfCyy}AqFIFF(wzOP8Q@=&@lw^bbz?{9grZxpR$<#L<*b9UEIcLtnKcN?k%1$ z4?A`kO%UufpAa~~X@=rN_bV(iQ2(`fKY)foVv7$un6r=IvQXW-q(a&0