Skip to content

Commit f1fdde4

Browse files
authored
Merge pull request #69 from martinRenou/deprecate_size
Deprecate size and use width, height
2 parents 6f25c1e + c556322 commit f1fdde4

17 files changed

+159
-95
lines changed

docs/source/advanced.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A way to work around this is to perform your drawings in a callback that gets ca
1616
1717
from ipycanvas import Canvas
1818
19-
canvas = Canvas(size=(100, 50))
19+
canvas = Canvas(width=100, height=50)
2020
2121
def perform_drawings():
2222
canvas.font = '32px serif'

docs/source/basic_usage.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Basic usage
44
Create Canvas
55
-------------
66

7-
You need to provide the size of the ``Canvas`` (width, height) in the constructor.
7+
You can provide the width and height of the ``Canvas`` in pixels in the constructor.
88

99
.. code:: Python
1010
1111
from ipycanvas import Canvas
1212
13-
canvas = Canvas(size=(200, 200))
13+
canvas = Canvas(width=200, height=200)
1414
canvas
1515
1616
You can also create a multi-layer canvas. This is useful when you have a background
@@ -21,7 +21,7 @@ that does not need to update much while other objects moves a lot on the screen.
2121
from ipycanvas import MultiCanvas
2222
2323
# Create a multi-layer canvas with 4 layers
24-
multi_canvas = MultiCanvas(4, size=(200, 200))
24+
multi_canvas = MultiCanvas(4, width=200, height=200)
2525
multi_canvas[0] # Access first layer (background)
2626
multi_canvas[3] # Access last layer
2727
multi_canvas
@@ -33,6 +33,16 @@ that does not need to update much while other objects moves a lot on the screen.
3333
- observe some of its attributes and call functions when they change
3434
- link some of its attributes to other widget attributes
3535

36+
Resize Canvas
37+
-------------
38+
39+
You can dynamically resize the ``Canvas`` and ``MultiCanvas``, note that this will clear the canvas.
40+
41+
.. code:: Python
42+
43+
canvas.width = 300
44+
canvas.height = 600
45+
3646
Clear Canvas
3747
------------
3848

@@ -42,7 +52,7 @@ The ``Canvas`` and ``MultiCanvas`` classes have a ``clear`` method which allows
4252
4353
from ipycanvas import Canvas
4454
45-
canvas = Canvas(size=(200, 200))
55+
canvas = Canvas(width=200, height=200)
4656
4757
# Perform some drawings...
4858
@@ -65,7 +75,7 @@ send them in a single batch at the end.
6575
6676
from ipycanvas import Canvas, hold_canvas
6777
68-
canvas = Canvas(size=(200, 200))
78+
canvas = Canvas(width=200, height=200)
6979
7080
with hold_canvas(canvas):
7181
# Perform drawings...

docs/source/drawing_images.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can draw from an `Image <https://ipywidgets.readthedocs.io/en/stable/example
1717
sprite1 = Image.from_file('sprites/smoke_texture0.png')
1818
sprite2 = Image.from_file('sprites/smoke_texture1.png')
1919
20-
canvas = Canvas(size=(300, 300))
20+
canvas = Canvas(width=300, height=300)
2121
2222
canvas.fill_style = '#a9cafc'
2323
canvas.fill_rect(0, 0, 300, 300)
@@ -36,7 +36,7 @@ You can draw from another ``Canvas`` widget. This is the fastest way of drawing
3636

3737
.. code:: Python
3838
39-
canvas2 = Canvas(size=(600, 300))
39+
canvas2 = Canvas(width=600, height=300)
4040
4141
# Here ``canvas`` is the canvas from the previous example
4242
canvas2.draw_image(canvas, 0, 0)
@@ -70,7 +70,7 @@ You can directly draw a NumPy array of pixels on the ``Canvas``, it must be a 3-
7070
7171
image_data = np.stack((red_channel, blue_channel, green_channel), axis=2)
7272
73-
canvas = Canvas(size=(image_data.shape[0], image_data.shape[1]))
73+
canvas = Canvas(width=image_data.shape[0], height=image_data.shape[1])
7474
canvas.put_image_data(image_data, 0, 0)
7575
7676
canvas
@@ -92,13 +92,13 @@ Drawing from another ``Canvas`` is by far the fastest of the three solutions pre
9292
from ipycanvas import Canvas, hold_canvas
9393
9494
# Create temporary Canvases
95-
canvas_sprite1 = Canvas(size=(100, 100))
95+
canvas_sprite1 = Canvas(width=100, height=100)
9696
canvas_sprite1.draw_image(Image.from_file('sprites/smoke_texture0.png'), 0, 0)
9797
98-
canvas_sprite2 = Canvas(size=(100, 100))
98+
canvas_sprite2 = Canvas(width=100, height=100)
9999
canvas_sprite2.draw_image(Image.from_file('sprites/smoke_texture1.png'), 0, 0)
100100
101-
canvas_sprite3 = Canvas(size=(100, 100))
101+
canvas_sprite3 = Canvas(width=100, height=100)
102102
canvas_sprite3.draw_image(Image.from_file('sprites/smoke_texture2.png'), 0, 0)
103103
104104
sprites = [canvas_sprite1, canvas_sprite2, canvas_sprite3]
@@ -110,7 +110,7 @@ Drawing from another ``Canvas`` is by far the fastest of the three solutions pre
110110

111111
.. code:: Python
112112
113-
canvas = Canvas(size=(800, 600))
113+
canvas = Canvas(width=800, height=600)
114114
115115
with hold_canvas(canvas):
116116
for _ in range(2_000):

docs/source/drawing_shapes.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can also clear a certain canvas rectangle area:
3333
3434
from ipycanvas import Canvas
3535
36-
canvas = Canvas(size=(200, 200))
36+
canvas = Canvas(width=200, height=200)
3737
3838
canvas.fill_rect(25, 25, 100, 100)
3939
canvas.clear_rect(45, 45, 60, 60)
@@ -57,7 +57,7 @@ You can also clear a certain canvas rectangle area:
5757
y = np.array(np.random.rayleigh(250, n_particles), dtype=np.int32)
5858
size = np.random.randint(1, 3, n_particles)
5959
60-
canvas = Canvas(size=(800, 500))
60+
canvas = Canvas(width=800, height=500)
6161
6262
canvas.fill_style = 'green'
6363
canvas.fill_rects(x, y, size)
@@ -82,7 +82,7 @@ There are four methods that draw circles on the canvas:
8282
8383
from ipycanvas import Canvas
8484
85-
canvas = Canvas(size=(200, 200))
85+
canvas = Canvas(width=200, height=200)
8686
8787
canvas.fill_style = 'red'
8888
canvas.stroke_style = 'blue'
@@ -117,7 +117,7 @@ Here are the functions used to perform these steps:
117117
118118
from ipycanvas import Canvas
119119
120-
canvas = Canvas(size=(100, 100))
120+
canvas = Canvas(width=100, height=100)
121121
122122
# Draw simple triangle shape
123123
canvas.begin_path()
@@ -162,7 +162,7 @@ Stroke arcs
162162
163163
from ipycanvas import Canvas
164164
165-
canvas = Canvas(size=(200, 200))
165+
canvas = Canvas(width=200, height=200)
166166
167167
# Draw smiley face
168168
canvas.begin_path()
@@ -186,7 +186,7 @@ Fill bezier curves
186186
187187
from ipycanvas import Canvas
188188
189-
canvas = Canvas(size=(200, 200))
189+
canvas = Canvas(width=200, height=200)
190190
191191
# Cubic curves example
192192
canvas.begin_path()
@@ -211,7 +211,7 @@ Change the fill rule
211211
from math import pi
212212
from ipycanvas import Canvas
213213
214-
canvas = Canvas(size=(100, 100))
214+
canvas = Canvas(width=100, height=100)
215215
216216
canvas.begin_path()
217217
canvas.arc(50, 50, 30, 0, pi * 2, True)
@@ -239,7 +239,7 @@ You can also change the global transparency.
239239
240240
from ipycanvas import Canvas
241241
242-
canvas = Canvas(size=(200, 200))
242+
canvas = Canvas(width=200, height=200)
243243
244244
canvas.fill_style = 'red'
245245
canvas.stroke_style = 'blue'
@@ -266,7 +266,7 @@ You can easily draw shadows by tweaking the following attributes:
266266
267267
from ipycanvas import Canvas
268268
269-
canvas = Canvas(size=(200, 200))
269+
canvas = Canvas(width=200, height=200)
270270
271271
canvas.shadow_color = 'green'
272272
canvas.shadow_offset_x = 2
@@ -305,7 +305,7 @@ Sets the width of lines drawn in the future.
305305
306306
from ipycanvas import Canvas
307307
308-
canvas = Canvas(size=(400, 280))
308+
canvas = Canvas(width=400, height=280)
309309
canvas.scale(2)
310310
311311
for i in range(10):
@@ -332,7 +332,7 @@ Sets the appearance of the ends of lines.
332332
333333
from ipycanvas import Canvas
334334
335-
canvas = Canvas(size=(320, 360))
335+
canvas = Canvas(width=320, height=360)
336336
337337
# Possible line_cap values
338338
line_caps = ['butt', 'round', 'square']
@@ -377,7 +377,7 @@ Sets the appearance of the "corners" where lines meet.
377377
378378
from ipycanvas import Canvas
379379
380-
canvas = Canvas(size=(320, 360))
380+
canvas = Canvas(width=320, height=360)
381381
382382
# Possible line_join values
383383
line_joins = ['round', 'bevel', 'miter']
@@ -419,7 +419,7 @@ Sets the current line dash pattern.
419419
420420
from ipycanvas import Canvas
421421
422-
canvas = Canvas(size=(400, 280))
422+
canvas = Canvas(width=400, height=280)
423423
canvas.scale(2)
424424
425425
line_dashes = [

docs/source/drawing_text.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are two methods that draw text on the canvas:
1313
1414
from ipycanvas import Canvas
1515
16-
canvas = Canvas(size=(400, 50))
16+
canvas = Canvas(width=400, height=50)
1717
1818
canvas.font = '32px serif'
1919
canvas.fill_text('Drawing from Python is cool!', 10, 32)
@@ -25,7 +25,7 @@ There are two methods that draw text on the canvas:
2525
2626
from ipycanvas import Canvas
2727
28-
canvas = Canvas(size=(400, 50))
28+
canvas = Canvas(width=400, height=50)
2929
3030
canvas.font = '32px serif'
3131
canvas.stroke_text('Hello There!', 10, 32)

docs/source/retrieve_images.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can dump the current ``Canvas`` or ``MultiCanvas`` image to a PNG file using
1717
1818
from ipycanvas import Canvas
1919
20-
canvas = Canvas(size=(200, 200), sync_image_data=True)
20+
canvas = Canvas(width=200, height=200, sync_image_data=True)
2121
2222
# Perform some drawings...
2323
@@ -29,7 +29,7 @@ Note that this won't work if executed in the same Notebook cell. Because the Can
2929
3030
from ipycanvas import Canvas
3131
32-
canvas = Canvas(size=(200, 200), sync_image_data=True)
32+
canvas = Canvas(width=200, height=200, sync_image_data=True)
3333
3434
# Perform some drawings...
3535
@@ -48,7 +48,7 @@ You can get the image data of the ``Canvas`` or ``MultiCanvas`` using the ``get_
4848
4949
from ipycanvas import Canvas
5050
51-
canvas = Canvas(size=(200, 200), sync_image_data=True)
51+
canvas = Canvas(width=200, height=200, sync_image_data=True)
5252
5353
# Perform some drawings...
5454
@@ -61,7 +61,7 @@ Note that this won't work if executed in the same Notebook cell. Because the Can
6161
6262
from ipycanvas import Canvas
6363
64-
canvas = Canvas(size=(200, 200), sync_image_data=True)
64+
canvas = Canvas(width=200, height=200, sync_image_data=True)
6565
6666
# Perform some drawings...
6767

examples/MultiCanvas.ipynb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"m = MultiCanvas(n_canvases=3, size=(200, 200))"
27+
"m = MultiCanvas(n_canvases=3, width=200, height=200)"
2828
]
2929
},
3030
{
@@ -121,6 +121,13 @@
121121
"source": [
122122
"draw_square(m[0], 0, 200, 'orange')"
123123
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": null,
128+
"metadata": {},
129+
"outputs": [],
130+
"source": []
124131
}
125132
],
126133
"metadata": {
@@ -139,7 +146,7 @@
139146
"name": "python",
140147
"nbconvert_exporter": "python",
141148
"pygments_lexer": "ipython3",
142-
"version": "3.7.3"
149+
"version": "3.8.1"
143150
}
144151
},
145152
"nbformat": 4,

examples/binary_image.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"source": [
7979
"scale = 1.5\n",
8080
"\n",
81-
"canvas = Canvas(size=(scale * data.shape[0], scale * data.shape[1]))\n",
81+
"canvas = Canvas(width=scale*data.shape[0], height=scale*data.shape[1])\n",
8282
"canvas"
8383
]
8484
},
@@ -142,7 +142,7 @@
142142
"name": "python",
143143
"nbconvert_exporter": "python",
144144
"pygments_lexer": "ipython3",
145-
"version": "3.7.3"
145+
"version": "3.8.1"
146146
}
147147
},
148148
"nbformat": 4,

examples/conways_game_of_life.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"source": [
9494
"n_pixels = 10\n",
9595
"\n",
96-
"multi = MultiCanvas(2, size=(x.shape[1] * n_pixels, x.shape[0] * n_pixels))\n",
96+
"multi = MultiCanvas(2, width=x.shape[1]*n_pixels, height=x.shape[0]*n_pixels)\n",
9797
"multi[0].fill_style = '#FFF0C9'\n",
9898
"multi[0].fill_rect(0, 0, multi.size[0], multi.size[1])\n",
9999
"\n",
@@ -145,7 +145,7 @@
145145
"outputs": [],
146146
"source": [
147147
"multi[0].fill_style = '#D0FFB3'\n",
148-
"multi[0].fill_rect(0, 0, multi.size[0], multi.size[1])"
148+
"multi[0].fill_rect(0, 0, multi.width, multi.height)"
149149
]
150150
}
151151
],
@@ -165,7 +165,7 @@
165165
"name": "python",
166166
"nbconvert_exporter": "python",
167167
"pygments_lexer": "ipython3",
168-
"version": "3.7.3"
168+
"version": "3.8.1"
169169
}
170170
},
171171
"nbformat": 4,

0 commit comments

Comments
 (0)