#!/usr/bin/env python3
"""Draw a fixed, local SVG weather vane of twelve public adjectives."""
from math import cos, pi, sin
from pathlib import Path

OUT = Path(__file__).with_name("weather_vane.svg")
WORDS = [
    "URGENT", "CLEAR", "FRESH", "LASTING",
    "EFFICIENT", "HUMAN", "BOLD", "GENTLE",
    "ESSENTIAL", "READY", "HONEST", "SIMPLE",
]
CX, CY, R = 400, 400, 265


def point(angle: float, radius: float) -> tuple[float, float]:
    return (CX + cos(angle) * radius, CY + sin(angle) * radius)


def render() -> str:
    pieces = [
        '<svg xmlns="http://www.w3.org/2000/svg" width="800" height="800" viewBox="0 0 800 800">',
        '<rect width="800" height="800" fill="#f2eee5"/>',
        '<circle cx="400" cy="400" r="286" fill="none" stroke="#24211e" stroke-width="3"/>',
        '<circle cx="400" cy="400" r="92" fill="#d95d39" stroke="#24211e" stroke-width="4"/>',
        '<text x="400" y="394" text-anchor="middle" font-family="Georgia, serif" font-size="21" fill="#24211e">THE COURTESY</text>',
        '<text x="400" y="420" text-anchor="middle" font-family="Georgia, serif" font-size="21" fill="#24211e">OF DIRECTION</text>',
    ]
    for index, word in enumerate(WORDS):
        angle = -pi / 2 + index * (2 * pi / len(WORDS))
        x1, y1 = point(angle, 106)
        x2, y2 = point(angle, 235)
        tx, ty = point(angle, 322)
        degrees = angle * 180 / pi + 90
        pieces.append(f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" stroke="#24211e" stroke-width="3"/>')
        pieces.append(f'<path d="M {x2:.1f} {y2:.1f} l -12 -25 l 24 0 z" fill="#24211e" transform="rotate({degrees:.1f} {x2:.1f} {y2:.1f})"/>')
        pieces.append(f'<text x="{tx:.1f}" y="{ty:.1f}" text-anchor="middle" dominant-baseline="middle" font-family="Arial, sans-serif" font-weight="700" font-size="15" fill="#24211e" transform="rotate({degrees:.1f} {tx:.1f} {ty:.1f})">{word}</text>')
    pieces.append('<text x="400" y="760" text-anchor="middle" font-family="Arial, sans-serif" font-size="13" letter-spacing="2" fill="#615b54">ALL ARROWS, NO WEATHER</text>')
    pieces.append('</svg>')
    return "\n".join(pieces) + "\n"


if __name__ == "__main__":
    OUT.write_text(render(), encoding="utf-8")
    print(f"wrote {OUT.name}: {len(WORDS)} labels, 12 equally confident directions")
