@@ -16,3 +16,53 @@ class Canvas(DOMWidget):
1616 _view_name = Unicode ('CanvasView' ).tag (sync = True )
1717 _view_module = Unicode (module_name ).tag (sync = True )
1818 _view_module_version = Unicode (module_version ).tag (sync = True )
19+
20+ # Rectangles methods
21+ def fill_rect (self , x , y , width , height ):
22+ """Draw a filled rectangle."""
23+ self ._send_canvas_msg ('fillRect' , x , y , width , height )
24+
25+ def stroke_rect (self , x , y , width , height ):
26+ """Draw a rectangular outline."""
27+ self ._send_canvas_msg ('strokeRect' , x , y , width , height )
28+
29+ def clear_rect (self , x , y , width , height ):
30+ """Clear the specified rectangular area, making it fully transparent."""
31+ self ._send_canvas_msg ('clearRect' , x , y , width , height )
32+
33+ # Paths methods
34+ def begin_path (self ):
35+ self ._send_canvas_msg ('beginPath' )
36+
37+ def close_path (self ):
38+ self ._send_canvas_msg ('closePath' )
39+
40+ def stroke (self ):
41+ self ._send_canvas_msg ('stroke' )
42+
43+ def fill (self ):
44+ self ._send_canvas_msg ('fill' )
45+
46+ def move_to (self , x , y ):
47+ self ._send_canvas_msg ('moveTo' , x , y )
48+
49+ def line_to (self , x , y ):
50+ self ._send_canvas_msg ('lineTo' , x , y )
51+
52+ def arc (self , x , y , radius , start_angle , end_angle , anticlockwise ):
53+ self ._send_canvas_msg ('arc' , x , y , radius , start_angle , end_angle , anticlockwise )
54+
55+ def arc_to (self , x1 , y1 , x2 , y2 , radius ):
56+ self ._send_canvas_msg ('arcTo' , x1 , y1 , x2 , y2 , radius )
57+
58+ def quadratic_curve_to (self , cp1x , cp1y , x , y ):
59+ self ._send_canvas_msg ('quadraticCurveTo' , cp1x , cp1y , x , y )
60+
61+ def bezier_curve_to (self , cp1x , cp1y , cp2x , cp2y , x , y ):
62+ self ._send_canvas_msg ('bezierCurveTo' , cp1x , cp1y , cp2x , cp2y , x , y )
63+
64+ def rect (self , x , y , width , height ):
65+ self ._send_canvas_msg ('rect' , x , y , width , height )
66+
67+ def _send_canvas_msg (self , msg_name , * args ):
68+ self .send ({'msg' : msg_name , 'args' : args })
0 commit comments