Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"plaintext": false,
"markdown": false,
"scminput": false,
"python": true
"python": false
}
}
Binary file modified geo/__pycache__/triangles.cpython-313.pyc
Binary file not shown.
47 changes: 24 additions & 23 deletions geo/triangles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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()
81 changes: 67 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#Setup
blk = (0, 0, 0)
root = Tk()
typeVal = ["Equilateral", "Isosceles", "Right"]
try:
root.iconbitmap("pencil.ico")
root.title("autoDraw")
Expand Down Expand Up @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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":
Expand All @@ -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
Expand All @@ -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)
Expand Down