import streamlit as st import base64 import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Polygon, Circle def set_background(video_path): """Sets the background of the Streamlit app to a video.""" with open(video_path, "rb") as video_file: video_bytes = video_file.read() video_base64 = base64.b64encode(video_bytes).decode("utf-8") video_html = f""" """ st.markdown(video_html, unsafe_allow_html=True) # Set the background *before* any other Streamlit elements set_background("numbers moving background.mp4") # Replace with your video path # --- Triangle Calculation and Plotting Functions --- def calculate_distance(x1, y1, x2, y2): return np.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) def calculate_angle(a, b, c): try: angle = np.degrees(np.arccos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c))) except ValueError: angle = 0 return angle # ... (rest of your calculation functions: calculate_area, calculate_perimeter, # calculate_radius_inscribed_circle, calculate_radius_circumscribed_circle, # calculate_centroid, calculate_incenter, calculate_circumcenter, calculate_midpoints, format_zero) def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoints, a, b, c): # ... (your plot_triangle function - no changes needed here) def is_valid_triangle(a, b, c): return a + b > c and b + c > a and c + a > b # --- Main Streamlit App --- def main(): st.title("Advanced Triangle Solver") st.sidebar.header("Enter the coordinates of the three points:") x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f") y1 = st.sidebar.number_input("Y1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f") x2 = st.sidebar.number_input("X2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f") y2 = st.sidebar.number_input("Y2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f") x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f") y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f") if st.sidebar.button("Calculate"): a = calculate_distance(x2, y2, x3, y3) b = calculate_distance(x1, y1, x3, y3) c = calculate_distance(x1, y1, x2, y2) if not is_valid_triangle(a, b, c): st.error("The entered points do not form a valid triangle.") return A = calculate_angle(a, b, c) B = calculate_angle(b, a, c) C = calculate_angle(c, a, b) if abs(A + B + C - 180) > 1e-2: st.error("The sum of the angles is not 180 degrees.") return # ... (rest of your calculations for area, perimeter, radii, centroid, incenter, circumcenter) area = calculate_area(a, b, c) perimeter = calculate_perimeter(a, b, c) radius_in = calculate_radius_inscribed_circle(a, b, c) radius_circum = calculate_radius_circumscribed_circle(a, b, c) G_x, G_y = calculate_centroid(x1, y1, x2, y2, x3, y3) I_x, I_y = calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c) U_x, U_y = calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c) midpoints = calculate_midpoints(x1, y1, x2, y2, x3, y3) # Display results (no changes needed here) # ... (your existing display code using st.columns, st.subheader, st.markdown) # Plot the triangle plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoints, a, b, c) if __name__ == "__main__": main()