Skip to content

Commit 2d5ad02

Browse files
author
Zerline
committed
Better naming (for the flipping dominos example).
1 parent 2d2f17f commit 2d5ad02

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

examples/FlippingDominos.ipynb

+30-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"source": [
2626
"%%html\n",
2727
"<style>\n",
28+
".b0 {}\n",
2829
".b1 {background-color: green}\n",
2930
".b2 {background-color: blue}\n",
3031
".b3 {background-color: red}\n",
@@ -38,7 +39,7 @@
3839
"metadata": {},
3940
"outputs": [],
4041
"source": [
41-
"from dominos.flipping_dominos import FlippingAztecDiamond, DominosWidget"
42+
"from dominos.flipping_dominos import FlippingAztecDiamond, FlippingDominosWidget"
4243
]
4344
},
4445
{
@@ -65,7 +66,7 @@
6566
"metadata": {},
6667
"outputs": [],
6768
"source": [
68-
"w = DominosWidget(g)\n",
69+
"w = FlippingDominosWidget(g)\n",
6970
"w"
7071
]
7172
},
@@ -80,7 +81,7 @@
8081
"cell_type": "markdown",
8182
"metadata": {},
8283
"source": [
83-
"## Example algorithm"
84+
"## An example algorithm"
8485
]
8586
},
8687
{
@@ -96,6 +97,15 @@
9697
"w.update()"
9798
]
9899
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"#[(k,d.geometry) for (k,d) in w.dominos.items() if k[0] in [4,5]]"
107+
]
108+
},
99109
{
100110
"cell_type": "code",
101111
"execution_count": null,
@@ -105,6 +115,7 @@
105115
"for k in w.dominos:\n",
106116
" if k[0] == 4 and k[1] % 2 and k[1] < 9:\n",
107117
" d1, d2 = w.value.domino_for_position(k), w.value.domino_for_position((k[0], k[1]+1))\n",
118+
" #print(d1, d2, d1.direction, d2.direction)\n",
108119
" w.value.flip(d1, d2)\n",
109120
"w.update()"
110121
]
@@ -266,6 +277,15 @@
266277
"w.update()"
267278
]
268279
},
280+
{
281+
"cell_type": "code",
282+
"execution_count": null,
283+
"metadata": {},
284+
"outputs": [],
285+
"source": [
286+
"[(k,d.geometry) for k,d in w.dominos.items()]"
287+
]
288+
},
269289
{
270290
"cell_type": "code",
271291
"execution_count": null,
@@ -279,6 +299,13 @@
279299
" w.value.flip(d1, d2)\n",
280300
"w.update()"
281301
]
302+
},
303+
{
304+
"cell_type": "code",
305+
"execution_count": null,
306+
"metadata": {},
307+
"outputs": [],
308+
"source": []
282309
}
283310
],
284311
"metadata": {

examples/dominos/flipping_dominos.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
smallblyt = Layout(width='12px',height='12px', margin='0', padding='0')
1212

1313

14-
class DominosAdapter(GraphGridViewAdapter):
14+
class FlippingDominosAdapter(GraphGridViewAdapter):
1515

1616
remove_cell = None
1717

18-
def set_cell(self, obj, pos, val=True, dirty={}):
18+
def set_cell(self, obj, pos, val, dirty={}):
1919
r"""
2020
When we click on a graph cell,
2121
we prepare a possible flip
@@ -234,15 +234,15 @@ def cell_widget_class_index(pos):
234234
return cell_widget_class_index
235235

236236

237-
class DominosWidget(GridViewWidget):
237+
class FlippingDominosWidget(GridViewWidget):
238238
"""A widget with dominos"""
239239

240240
def __init__(self, g):
241241
r"""
242242
Init a flipping dominos widget
243243
with flipping aztec diamond graph `g`
244244
"""
245-
super(DominosWidget, self).__init__(g, adapter = DominosAdapter(),
245+
super(FlippingDominosWidget, self).__init__(g, adapter = FlippingDominosAdapter(),
246246
cell_layout = smallblyt,
247247
cell_widget_classes=[styled_button_cell(),
248248
styled_button_cell(style_name='b1'),
@@ -256,7 +256,7 @@ def __init__(self, g):
256256

257257
def draw(self):
258258
self.dominos = {}
259-
super(DominosWidget, self).draw()
259+
super(FlippingDominosWidget, self).draw()
260260
self.apply_matching(self.value.matching)
261261

262262
def update(self):

0 commit comments

Comments
 (0)