Skip to content

Commit ff37a4a

Browse files
authored
Merge pull request #157 from martinRenou/docs
Docs
2 parents 9af28f0 + 820e21a commit ff37a4a

14 files changed

+240
-59
lines changed

docs/source/canvas_state.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
Canvas state
22
============
33

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.
68

79
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:
810

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
'goatcounter.js'
3232
]
3333

34+
html_static_path = ['_static']
35+
3436
html_css_files = [
3537
'custom.css'
3638
]

docs/source/drawing_images.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ From an Image widget
66

77
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.
88

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.
9+
- ``draw_image(image, x=0, y=0, width=None, height=None)``:
10+
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.
1012

1113
.. code:: Python
1214
@@ -51,7 +53,9 @@ From a NumPy array
5153

5254
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``.
5355

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).
5559

5660
.. code:: python
5761

docs/source/drawing_paths.rst

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ extra steps:
5454

5555
Here are the functions used to perform these steps:
5656

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.
5859
- 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`.
6266

6367
.. code:: Python
6468
@@ -83,20 +87,28 @@ Path commands
8387

8488
Here are the available draw commands:
8589

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
8996
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
9097
``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``)
92100
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
94103
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.
96106
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.
107+
- ``bezier_curve_to(cp1x, cp1y, cp2x, cp2y, x, y)``:
108+
Add a cubic Bezier curve to the current path.
98109
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``.
100112

101113

102114
Examples

docs/source/drawing_shapes.rst

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@ Drawing rectangles
2222

2323
There are four methods that draw rectangles on the canvas:
2424

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``.
2935

3036
You can also clear a certain canvas rectangle area:
3137

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``.
3340

3441
.. code:: Python
3542
@@ -74,8 +81,10 @@ Drawing polygons
7481
You can draw a polygon by providing a list of points, either a Python list, or a NumPy array.
7582
It's the fastest way to draw a polygon with ipycanvas.
7683

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)]``.
7988

8089
.. code:: Python
8190
@@ -129,15 +138,23 @@ Drawing arcs and circles
129138

130139
There are methods that draw arcs/circles on the canvas:
131140

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.
141158

142159

143160
.. code:: Python
@@ -163,8 +180,10 @@ Drawing lines
163180

164181
There are two commands for drawing a straight line from one point to another:
165182

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)]``.
168187

169188
.. code:: Python
170189

docs/source/drawing_text.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ Drawing text
33

44
There are two methods that draw text on the canvas:
55

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.
810

911
.. code:: Python
1012
@@ -35,10 +37,14 @@ Styles and colors
3537

3638
You can change the text style by changing the following ``Canvas`` attributes:
3739

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"``.
4248

4349
.. note::
4450
You can still use ``fill_style``, ``stroke_style``, ``shadow_color`` etc for coloring text and applying shadows.
6.02 KB
Loading

docs/source/images/pattern.png

5.25 KB
Loading
912 Bytes
Loading
57.7 KB
Loading

0 commit comments

Comments
 (0)