"""Preview module for generating SVG previews of patterns.""" import os import math from modules.core.pattern_manager import parse_theta_rho_file, THETA_RHO_DIR async def generate_preview_svg(pattern_file): """Generate an SVG preview for a pattern file.""" file_path = os.path.join(THETA_RHO_DIR, pattern_file) coordinates = parse_theta_rho_file(file_path) # Convert polar coordinates to SVG path svg_path = [] for i, (theta, rho) in enumerate(coordinates): x = 100 - rho * 90 * math.cos(theta) y = 100 - rho * 90 * math.sin(theta) if i == 0: svg_path.append(f"M {x:.2f} {y:.2f}") else: svg_path.append(f"L {x:.2f} {y:.2f}") svg = f''' ''' return svg