You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/canvas_state.rst
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
1
Canvas state
2
2
============
3
3
4
-
- ``save()``: Saves the entire state of the canvas.
5
-
- ``restore()``: Restores the most recently saved canvas state.
4
+
- ``save()``:
5
+
Saves the entire state of the canvas.
6
+
- ``restore()``:
7
+
Restores the most recently saved canvas state.
6
8
7
9
Canvas states are stored on a stack. Every time the ``save()`` method is called, the current drawing state is pushed onto the stack. A drawing state consists of:
Copy file name to clipboardExpand all lines: docs/source/drawing_images.rst
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,9 @@ From an Image widget
6
6
7
7
You can draw from an `Image <https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html#Image>`_ widget directly, this is the less optimized solution but it works perfectly fine if you don't draw more than a hundred images at a time.
8
8
9
-
- ``draw_image(image, x=0, y=0, width=None, height=None)``: Draw an ``image`` on the Canvas at the coordinates (``x``, ``y``) and scale it to (``width``, ``height``). The ``image`` must be an ``Image`` widget or another ``Canvas``. If ``width``/``height`` is ``None``, the natural image ``width``/``height`` is used.
Draw an ``image`` on the Canvas at the coordinates (``x``, ``y``) and scale it to (``width``, ``height``).
11
+
The ``image`` must be an ``Image`` widget or another ``Canvas``. If ``width``/``height`` is ``None``, the natural image ``width``/``height`` is used.
10
12
11
13
.. code:: Python
12
14
@@ -51,7 +53,9 @@ From a NumPy array
51
53
52
54
You can directly draw a NumPy array of pixels on the ``Canvas``, it must be a 3-D array of integers and the last dimension must be 3 or 4 (rgb or rgba), with values going from ``0`` to ``255``.
53
55
54
-
- ``put_image_data(image_data, x=0, y=0)``: Draw an image on the Canvas. ``image_data`` should be a NumPy array containing the image to draw and ``x`` and ``y`` the pixel position where to draw (top left pixel of the image).
56
+
- ``put_image_data(image_data, x=0, y=0)``:
57
+
Draw an image on the Canvas. ``image_data`` should be a NumPy array containing the image to
58
+
draw and ``x`` and ``y`` the pixel position where to draw (top left pixel of the image).
Copy file name to clipboardExpand all lines: docs/source/drawing_paths.rst
+24-12Lines changed: 24 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,11 +54,15 @@ extra steps:
54
54
55
55
Here are the functions used to perform these steps:
56
56
57
-
- ``begin_path()``: Creates a new path. Once created, future drawing commands are directed into the path and used to build the path up.
57
+
- ``begin_path()``:
58
+
Creates a new path. Once created, future drawing commands are directed into the path and used to build the path up.
58
59
- Path commands like ``line_to`` and ``arc``
59
-
- ``close_path()``: Adds a straight line to the path, going to the start of the current path.
60
-
- ``stroke()``: Draws the shape by stroking its outline.
61
-
- ``fill(rule)``: Draws a solid shape by filling the path's content area. The given fill rule is applied, possible rules are `nonzero` and `evenodd`.
60
+
- ``close_path()``:
61
+
Adds a straight line to the path, going to the start of the current path.
62
+
- ``stroke()``:
63
+
Draws the shape by stroking its outline.
64
+
- ``fill(rule)``:
65
+
Draws a solid shape by filling the path's content area. The given fill rule is applied, possible rules are `nonzero` and `evenodd`.
62
66
63
67
.. code:: Python
64
68
@@ -83,20 +87,28 @@ Path commands
83
87
84
88
Here are the available draw commands:
85
89
86
-
- ``move_to(x, y)``: Moves the pen to the coordinates specified by x and y. This does not actually draw anything.
87
-
- ``line_to(x, y)``: Add a straight line to the current path by connecting the path’s last point to the specified (x, y) coordinates.
88
-
- ``arc(x, y, radius, start_angle, end_angle, anticlockwise=False)``: Add a circular arc centered at (x, y) with a radius
90
+
- ``move_to(x, y)``:
91
+
Moves the pen to the coordinates specified by x and y. This does not actually draw anything.
92
+
- ``line_to(x, y)``:
93
+
Add a straight line to the current path by connecting the path’s last point to the specified (x, y) coordinates.
94
+
- ``arc(x, y, radius, start_angle, end_angle, anticlockwise=False)``:
95
+
Add a circular arc centered at (x, y) with a radius
89
96
of ``radius`` to the current path. The path starts at ``start_angle`` and ends at ``end_angle`` in radians, and travels in the direction given by
90
97
``anticlockwise`` (defaulting to clockwise: False).
91
-
- ``arc_to(x1, y1, x2, y2, radius)``: Add a circular arc to the current path. Using the given control points (``x1``, ``y1``)
98
+
- ``arc_to(x1, y1, x2, y2, radius)``:
99
+
Add a circular arc to the current path. Using the given control points (``x1``, ``y1``)
92
100
and (``x2``, ``y2``) and the ``radius``.
93
-
- ``ellipse(x, y, radius_x, radius_y, rotation, start_angle, end_angle, anticlockwise=False)``: Add an ellipse centered at ``(x, y)`` with
101
+
- ``ellipse(x, y, radius_x, radius_y, rotation, start_angle, end_angle, anticlockwise=False)``:
102
+
Add an ellipse centered at ``(x, y)`` with
94
103
the radii ``radius_x`` and ``radius_y`` to the current path.
95
-
- ``quadratic_curve_to(cp1x, cp1y, x, y)``: Add a quadratic Bezier curve to the current path.
104
+
- ``quadratic_curve_to(cp1x, cp1y, x, y)``:
105
+
Add a quadratic Bezier curve to the current path.
96
106
It requires two points: the first one is a control point and the second one is the end point. The starting point is the latest point in the current path, which can be changed using ``move_to()`` before creating the quadratic Bezier curve.
97
-
- ``bezier_curve_to(cp1x, cp1y, cp2x, cp2y, x, y)``: Add a cubic Bezier curve to the current path.
It requires three points: the first two are control points and the third one is the end point. The starting point is the latest point in the current path, which can be changed using ``move_to()`` before creating the Bezier curve.
99
-
- ``rect(x, y, width, height)``: Draws a rectangle whose top-left corner is specified by (``x``, ``y``) with the specified ``width`` and ``height``.
110
+
- ``rect(x, y, width, height)``:
111
+
Draws a rectangle whose top-left corner is specified by (``x``, ``y``) with the specified ``width`` and ``height``.
Copy file name to clipboardExpand all lines: docs/source/drawing_shapes.rst
+37-18Lines changed: 37 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,14 +22,21 @@ Drawing rectangles
22
22
23
23
There are four methods that draw rectangles on the canvas:
24
24
25
-
- ``fill_rect(x, y, width, height=None)``: Draws a filled rectangle. If ``height`` is None, it is set to the same value as ``width``.
26
-
- ``stroke_rect(x, y, width, height=None)``: Draws a rectangular outline. If ``height`` is None, it is set to the same value as ``width``.
27
-
- ``fill_rects(x, y, width, height=None)``: Draws filled rectangles. Where ``x``, ``y``, ``width`` and ``height`` are either integers, lists of integers or NumPy arrays. If ``height`` is None, it is set to the same value as ``width``.
28
-
- ``stroke_rects(x, y, width, height=None)``: Draws rectangular outlines. Where ``x``, ``y``, ``width`` and ``height`` are either integers, lists of integers or NumPy arrays. If ``height`` is None, it is set to the same value as ``width``.
25
+
- ``fill_rect(x, y, width, height=None)``:
26
+
Draws a filled rectangle. If ``height`` is None, it is set to the same value as ``width``.
27
+
- ``stroke_rect(x, y, width, height=None)``:
28
+
Draws a rectangular outline. If ``height`` is None, it is set to the same value as ``width``.
29
+
- ``fill_rects(x, y, width, height=None)``:
30
+
Draws filled rectangles. Where ``x``, ``y``, ``width`` and ``height`` are either integers, lists of integers or NumPy arrays.
31
+
If ``height`` is None, it is set to the same value as ``width``.
32
+
- ``stroke_rects(x, y, width, height=None)``:
33
+
Draws rectangular outlines. Where ``x``, ``y``, ``width`` and ``height`` are either integers, lists of integers or NumPy arrays.
34
+
If ``height`` is None, it is set to the same value as ``width``.
29
35
30
36
You can also clear a certain canvas rectangle area:
31
37
32
-
- ``clear_rect(x, y, width, height=None)``: Clears the specified rectangular area, making it fully transparent. If ``height`` is None, it is set to the same value as ``width``.
38
+
- ``clear_rect(x, y, width, height=None)``:
39
+
Clears the specified rectangular area, making it fully transparent. If ``height`` is None, it is set to the same value as ``width``.
33
40
34
41
.. code:: Python
35
42
@@ -74,8 +81,10 @@ Drawing polygons
74
81
You can draw a polygon by providing a list of points, either a Python list, or a NumPy array.
75
82
It's the fastest way to draw a polygon with ipycanvas.
76
83
77
-
- ``fill_polygon(points)``: Fill a polygon from a list of points ``[(x1, y1), (x2, y2), ..., (xn, yn)]``.
78
-
- ``stroke_polygon(points)``: Draw polygon outline from a list of points ``[(x1, y1), (x2, y2), ..., (xn, yn)]``.
84
+
- ``fill_polygon(points)``:
85
+
Fill a polygon from a list of points ``[(x1, y1), (x2, y2), ..., (xn, yn)]``.
86
+
- ``stroke_polygon(points)``:
87
+
Draw polygon outline from a list of points ``[(x1, y1), (x2, y2), ..., (xn, yn)]``.
79
88
80
89
.. code:: Python
81
90
@@ -129,15 +138,23 @@ Drawing arcs and circles
129
138
130
139
There are methods that draw arcs/circles on the canvas:
131
140
132
-
- ``fill_arc(x, y, radius, start_angle, end_angle, anticlockwise=False)``: Draw a filled arc centered at ``(x, y)`` with a radius of ``radius``.
133
-
- ``stroke_arc(x, y, radius, start_angle, end_angle, anticlockwise=False)``: Draw an arc outline centered at ``(x, y)`` with a radius of ``radius``.
134
-
- ``fill_arcs(x, y, radius, start_angle, end_angle, anticlockwise=False)``: Draw filled arcs centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` and other arguments are NumPy arrays, lists or scalar values.
135
-
- ``stroke_arcs(x, y, radius, start_angle, end_angle, anticlockwise=False)``: Draw an arc outlines centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` and other arguments are NumPy arrays, lists or scalar values.
136
-
137
-
- ``fill_circle(x, y, radius)``: Draw a filled circle centered at ``(x, y)`` with a radius of ``radius``.
138
-
- ``stroke_circle(x, y, radius)``: Draw an circle outline centered at ``(x, y)`` with a radius of ``radius``.
139
-
- ``fill_circles(x, y, radius)``: Draw filled circles centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` are NumPy arrays, lists or scalar values.
140
-
- ``stroke_circles(x, y, radius)``: Draw a circle outlines centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` are NumPy arrays, lists or scalar values.
141
+
- ``fill_arc(x, y, radius, start_angle, end_angle, anticlockwise=False)``:
142
+
Draw a filled arc centered at ``(x, y)`` with a radius of ``radius``.
143
+
- ``stroke_arc(x, y, radius, start_angle, end_angle, anticlockwise=False)``:
144
+
Draw an arc outline centered at ``(x, y)`` with a radius of ``radius``.
145
+
- ``fill_arcs(x, y, radius, start_angle, end_angle, anticlockwise=False)``:
146
+
Draw filled arcs centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` and other arguments are NumPy arrays, lists or scalar values.
147
+
- ``stroke_arcs(x, y, radius, start_angle, end_angle, anticlockwise=False)``:
148
+
Draw an arc outlines centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` and other arguments are NumPy arrays, lists or scalar values.
149
+
150
+
- ``fill_circle(x, y, radius)``:
151
+
Draw a filled circle centered at ``(x, y)`` with a radius of ``radius``.
152
+
- ``stroke_circle(x, y, radius)``:
153
+
Draw an circle outline centered at ``(x, y)`` with a radius of ``radius``.
154
+
- ``fill_circles(x, y, radius)``:
155
+
Draw filled circles centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` are NumPy arrays, lists or scalar values.
156
+
- ``stroke_circles(x, y, radius)``:
157
+
Draw a circle outlines centered at ``(x, y)`` with a radius of ``radius``. Where ``x``, ``y``, ``radius`` are NumPy arrays, lists or scalar values.
141
158
142
159
143
160
.. code:: Python
@@ -163,8 +180,10 @@ Drawing lines
163
180
164
181
There are two commands for drawing a straight line from one point to another:
165
182
166
-
- ``stroke_line(x1, y1, x2, y2)``: Draw a line from ``(x1, y1)`` to ``(x2, y2)``.
167
-
- ``stroke_lines(points)``: Draw a path of consecutive lines from a list of points ``[(x1, y1), (x2, y2), ..., (xn, yn)]``.
183
+
- ``stroke_line(x1, y1, x2, y2)``:
184
+
Draw a line from ``(x1, y1)`` to ``(x2, y2)``.
185
+
- ``stroke_lines(points)``:
186
+
Draw a path of consecutive lines from a list of points ``[(x1, y1), (x2, y2), ..., (xn, yn)]``.
Copy file name to clipboardExpand all lines: docs/source/drawing_text.rst
+12-6Lines changed: 12 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,10 @@ Drawing text
3
3
4
4
There are two methods that draw text on the canvas:
5
5
6
-
- ``fill_text(text, x, y, max_width=None)``: Fills a given ``text`` at the given (``x``, ``y``) position. Optionally with a maximum width to draw.
7
-
- ``stroke_text(text, x, y, max_width=None)``: Strokes a given ``text`` at the given (``x``, ``y``) position. Optionally with a maximum width to draw.
6
+
- ``fill_text(text, x, y, max_width=None)``:
7
+
Fills a given ``text`` at the given (``x``, ``y``) position. Optionally with a maximum width to draw.
8
+
- ``stroke_text(text, x, y, max_width=None)``:
9
+
Strokes a given ``text`` at the given (``x``, ``y``) position. Optionally with a maximum width to draw.
8
10
9
11
.. code:: Python
10
12
@@ -35,10 +37,14 @@ Styles and colors
35
37
36
38
You can change the text style by changing the following ``Canvas`` attributes:
37
39
38
-
- ``font``: (str) The current text style being used when drawing text. This string uses the same syntax as the CSS font property. The default font is ``"12px sans-serif"``.
39
-
- ``text_align``: (str) Text alignment setting. Possible values: ``"start"``, ``"end"``, ``"left"``, ``"right"`` or ``"center"``. The default value is ``"start"``.
40
-
- ``text_baseline``: (str) Baseline alignment setting. Possible values: ``"top"``, ``"hanging"``, ``"middle"``, ``"alphabetic"``, ``"ideographic"``, ``"bottom"``. The default value is ``"alphabetic"``.
41
-
- ``direction``: (str) Directionality. Possible values: ``"ltr"``, ``"rtl"``, ``"inherit"``. The default value is ``"inherit"``.
40
+
- ``font``: (str)
41
+
The current text style being used when drawing text. This string uses the same syntax as the CSS font property. The default font is ``"12px sans-serif"``.
42
+
- ``text_align``: (str)
43
+
Text alignment setting. Possible values: ``"start"``, ``"end"``, ``"left"``, ``"right"`` or ``"center"``. The default value is ``"start"``.
44
+
- ``text_baseline``: (str)
45
+
Baseline alignment setting. Possible values: ``"top"``, ``"hanging"``, ``"middle"``, ``"alphabetic"``, ``"ideographic"``, ``"bottom"``. The default value is ``"alphabetic"``.
46
+
- ``direction``: (str)
47
+
Directionality. Possible values: ``"ltr"``, ``"rtl"``, ``"inherit"``. The default value is ``"inherit"``.
42
48
43
49
.. note::
44
50
You can still use ``fill_style``, ``stroke_style``, ``shadow_color`` etc for coloring text and applying shadows.
Get the image data as a NumPy array for a sub-portion of the Canvas.
8
10
9
11
By default, and in order to keep ipycanvas fast, the image state of the Canvas is not synchronized between the TypeScript front-end and the Python back-end. If you want to retrieve the image data from the Canvas, you first need to explicitly specify that you want the image to be synchronized by setting ``sync_image_data`` to ``True`` before doing any drawing, you can set ``sync_image_data`` back to ``False`` once you're done.
0 commit comments