Hong-Phuc Bui
9 days ago 13963abe51def347a3829174efe64b8dd68b1fbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()