Skip to content

Commit 9b8cd22

Browse files
committed
Opacity example + missing import
1 parent 3d020f7 commit 9b8cd22

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

examples/introduction.ipynb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"outputs": [],
5252
"source": [
5353
"c = ipycanvas.Canvas(stroke_style='red', size=(700, 200))\n",
54+
"c.layout.width = '700px'\n",
5455
"c.layout.height = '200px'\n",
5556
"\n",
5657
"c"
@@ -207,7 +208,40 @@
207208
"execution_count": null,
208209
"metadata": {},
209210
"outputs": [],
210-
"source": []
211+
"source": [
212+
"c = ipycanvas.Canvas(size=(150, 150))\n",
213+
"c.layout.width = '150px'\n",
214+
"c.layout.height = '150px'\n",
215+
"\n",
216+
"c"
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": null,
222+
"metadata": {},
223+
"outputs": [],
224+
"source": [
225+
"# Draw background\n",
226+
"c.fill_style = '#FD0'\n",
227+
"c.fill_rect(0, 0, 75, 75)\n",
228+
"c.fill_style = '#6C0'\n",
229+
"c.fill_rect(75, 0, 75, 75)\n",
230+
"c.fill_style = '#09F'\n",
231+
"c.fill_rect(0, 75, 75, 75)\n",
232+
"c.fill_style = '#F30'\n",
233+
"c.fill_rect(75, 75, 75, 75)\n",
234+
"c.fill_style = '#FFF'\n",
235+
"\n",
236+
"# Set transparency value\n",
237+
"c.global_alpha = 0.2;\n",
238+
"\n",
239+
"# Draw semi transparent circles\n",
240+
"for i in range(7):\n",
241+
" c.begin_path();\n",
242+
" c.arc(75, 75, 10 + 10 * i, 0, pi * 2, True);\n",
243+
" c.fill();"
244+
]
211245
}
212246
],
213247
"metadata": {

ipycanvas/canvas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ipywidgets import Color, DOMWidget
88

9-
from traitlets import Tuple, Unicode
9+
from traitlets import Float, Tuple, Unicode
1010

1111
from ._frontend import module_name, module_version
1212

0 commit comments

Comments
 (0)