from nicegui import ui

from bezier import make_cubic_bezier, make_svg_polyline

control_points = []
svg = ""

def get_point(event):
    global control_points
    global svg
    x = event.image_x
    y = event.image_y
    control_points.append((x,y))
    svg += f'<circle cx="{x}" cy="{y}" r="1" fill="orange" />'
    ui.notification(f"(x,y) = ({x},{y})")
    if len(control_points) == 4:
        bezier_points = make_cubic_bezier(control_points, n = 50)
        svg += make_svg_polyline(bezier_points)
        control_points.clear()
    event.sender.set_content(svg)

ui.interactive_image(
    size=(900, 400), cross=True,
    on_mouse=get_point,
).classes('w-full bg-blue-50')

ui.run()