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/geo/__pycache__/triangles.cpython-313.pyc b/geo/__pycache__/triangles.cpython-313.pyc index b06f822..0e16c85 100644 Binary files a/geo/__pycache__/triangles.cpython-313.pyc and b/geo/__pycache__/triangles.cpython-313.pyc differ diff --git a/geo/triangles.py b/geo/triangles.py index 8055d92..1f07577 100644 --- a/geo/triangles.py +++ b/geo/triangles.py @@ -21,45 +21,46 @@ def tri_equi(cote, fill, source): trit.end_fill() def tri_iso(side, base, fill, source): - t = turtle.Turtle() + trit = turtle.Turtle() if source == None: - t.color(blk) + trit.color(blk) elif fill == True and bool(source) == True: fcolor = source - t.color(fcolor) - t.begin_fill() + trit.color(fcolor) + trit.begin_fill() height = (side ** 2 - (base / 2) ** 2) ** 0.5 # Draw the isosceles triangle angle = math.degrees(math.atan(height / (base / 2))) # Draw the isosceles triangle - t.forward(base) # Draw the base - t.left(180 - angle) # Turn to draw the first equal side - t.forward(side) # Draw the first equal side - t.left(2 * angle) # Turn to draw the second equal side - t.forward(side) + trit.forward(base) # Draw the base + trit.left(180 - angle) # Turn to draw the first equal side + trit.forward(side) # Draw the first equal side + trit.left(2 * angle) # Turn to draw the second equal side + trit.forward(side) if fill == True: - t.end_fill() + trit.end_fill() def tri_rect(a, b, fill, source): - t = turtle.Turtle() + trit = turtle.Turtle() if source == None: - t.color(blk) + trit.color(blk) elif fill == True and bool(source) == True: fcolor = source - t.color(fcolor) - t.begin_fill() - t = turtle.Turtle() + trit.color(fcolor) + trit.begin_fill() # Calculate hypotenuse c = math.sqrt(a ** 2 + b ** 2) angle = math.degrees(math.atan2(b, a)) # Move to starting position (optional) - t.penup() - t.goto(-a // 2, -b // 2) # Centering the triangle - t.pendown() + trit.penup() + trit.goto(-a // 2, -b // 2) # Centering the triangle + trit.pendown() # Draw the triangle correctly - t.forward(a) # Base - t.left(90) - t.forward(b) # Height - t.left(90 + angle) - t.forward(c) # Hypotenuse \ No newline at end of file + trit.forward(a) # Base + trit.left(90) + trit.forward(b) # Height + trit.left(90 + angle) + trit.forward(c) # Hypotenuse + if fill == True: + trit.end_fill() \ No newline at end of file diff --git a/main.py b/main.py index c5cd7ba..0958dcd 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") @@ -76,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): @@ -159,9 +164,27 @@ 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 + window.deiconify() + 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() @@ -179,6 +202,12 @@ def outDraw(self, shape, size, src): self.outRect(self.m1, self.m2) elif shape == self.carr: self.outSq(self.m1) + elif shape == self.tri_rect: + self.outTriRect(self.m1, self.m2) + elif shape == self.tri_iso: + self.outTrIso(self.m1, self.m2) + elif shape == self.tri_equi: + self.outTriEqui(self.m1) def outSq(self, size): for x in range(4): self.outliner.forward(size) @@ -193,7 +222,29 @@ def outTriEqui(self, side): for _ in range(3): self.outliner.forward(side) self.outliner.left(120) - + def outTrIso(self, side, base): + 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) + def outTriRect(self, a, b): + # Calculate hypotenuse + c = math.sqrt(a ** 2 + b ** 2) + angle = math.degrees(math.atan2(b, a)) + # Move to starting position (optional) + self.outliner.penup() + self.outliner.goto(-a // 2, -b // 2) # Centering the triangle + self.outliner.pendown() + # Draw the triangle correctly + self.outliner.forward(a) # Base + self.outliner.left(90) + self.outliner.forward(b) # Height + self.outliner.left(90 + angle) + self.outliner.forward(c) # Hypotenuse logic = Logic() def cAsk(src: str): if src == "outline": @@ -208,7 +259,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 +284,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)