|
| 1 | +Rough Canvas |
| 2 | +============ |
| 3 | + |
| 4 | +ipycanvas provides a special canvas class that automatically gives a hand-drawn style to your drawings. |
| 5 | +The ``RoughCanvas`` API is the same as the ``Canvas`` one, except that it provides a few more options. |
| 6 | + |
| 7 | +Create a RoughCanvas |
| 8 | +-------------------- |
| 9 | + |
| 10 | +You create a ``RoughCanvas`` the same way you would create a normal ``Canvas``. |
| 11 | + |
| 12 | +.. code:: Python |
| 13 | +
|
| 14 | + from ipycanvas import RoughCanvas |
| 15 | +
|
| 16 | + canvas = RoughCanvas(width=200, height=200) |
| 17 | + canvas |
| 18 | +
|
| 19 | +Then your drawings will have an hand-drawn style: |
| 20 | + |
| 21 | + |
| 22 | +.. code:: Python |
| 23 | +
|
| 24 | + from ipycanvas import RoughCanvas |
| 25 | +
|
| 26 | + canvas = RoughCanvas() |
| 27 | +
|
| 28 | + canvas.stroke_style = 'red' |
| 29 | + canvas.fill_style = 'blue' |
| 30 | + canvas.stroke_rect(100, 100, 100, 100) |
| 31 | + canvas.fill_rect(50, 50, 100, 100) |
| 32 | +
|
| 33 | + canvas.stroke_style = 'purple' |
| 34 | + canvas.fill_style = 'green' |
| 35 | + canvas.stroke_circle(300, 300, 100) |
| 36 | + canvas.fill_circle(350, 350, 100) |
| 37 | +
|
| 38 | + canvas.stroke_line(200, 200, 300, 300) |
| 39 | +
|
| 40 | + canvas |
| 41 | +
|
| 42 | +.. image:: images/roughshapes.png |
| 43 | + |
| 44 | +.. note:: |
| 45 | + The ``RoughCanvas`` does not support yet applying the hand-drawn style to custom path commands (``begin_path``, ``arc_to``, etc) |
| 46 | + |
| 47 | +Fill style |
| 48 | +---------- |
| 49 | + |
| 50 | +The ``RoughCanvas`` provides a second fill style option ``rough_fill_style`` which changes the way shapes are filled. |
| 51 | + |
| 52 | +.. code:: Python |
| 53 | +
|
| 54 | + from ipycanvas import RoughCanvas |
| 55 | +
|
| 56 | + canvas = RoughCanvas(width=850, height=100) |
| 57 | +
|
| 58 | + canvas.fill_style = 'blue' |
| 59 | + canvas.line_width = 2. |
| 60 | +
|
| 61 | + rough_fill_style_values = ['hachure', 'solid', 'zigzag', 'cross-hatch', 'dots', 'sunburst', 'dashed', 'zigzag-line'] |
| 62 | +
|
| 63 | + for i in range(len(rough_fill_style_values)): |
| 64 | + canvas.rough_fill_style = rough_fill_style_values[i] |
| 65 | +
|
| 66 | + canvas.fill_rect(10 + i * 100, 10, 90, 80) |
| 67 | +
|
| 68 | + canvas |
| 69 | +
|
| 70 | +.. image:: images/roughfillstyle.png |
| 71 | + |
| 72 | + |
| 73 | +Roughness |
| 74 | +--------- |
| 75 | + |
| 76 | +You can change the roughness of your drawing changing the ``roughness`` attribute (float). |
| 77 | +A rectangle with the roughness of 0 would be a perfect rectangle. There is no upper limit to this value, but a value over 10 is mostly useless. |
| 78 | + |
| 79 | +.. code:: Python |
| 80 | +
|
| 81 | + from ipycanvas import RoughCanvas |
| 82 | +
|
| 83 | + canvas = RoughCanvas(width=850, height=100) |
| 84 | +
|
| 85 | + canvas.fill_style = 'green' |
| 86 | +
|
| 87 | + for i in range(8): |
| 88 | + canvas.roughness = i |
| 89 | +
|
| 90 | + canvas.fill_rect(10 + i * 100, 10, 90, 80) |
| 91 | +
|
| 92 | + canvas |
| 93 | +
|
| 94 | +.. image:: images/roughness.png |
| 95 | + |
| 96 | + |
| 97 | +Bowing |
| 98 | +------ |
| 99 | + |
| 100 | +You can change the curves of your drawing changing the ``bowing`` attribute (float). |
| 101 | +It's a numerical value indicating how curvy the lines are when drawing a sketch. A value of 0 will cause straight lines. |
| 102 | + |
| 103 | +.. code:: Python |
| 104 | +
|
| 105 | + from ipycanvas import RoughCanvas |
| 106 | +
|
| 107 | + canvas = RoughCanvas(width=850, height=150) |
| 108 | +
|
| 109 | + canvas.fill_style = 'green' |
| 110 | +
|
| 111 | + for i in range(8): |
| 112 | + canvas.bowing = i * 3. |
| 113 | +
|
| 114 | + canvas.stroke_rect(20 + i * 100, 20, 90, 110) |
| 115 | +
|
| 116 | + canvas |
| 117 | +
|
| 118 | +.. image:: images/bowing.png |
0 commit comments