Skip to content

Commit 0dbdb99

Browse files
authored
Merge pull request #135 from martinRenou/examples
Improve examples
2 parents 4d83898 + 6e3ca97 commit 0dbdb99

File tree

7 files changed

+25
-34
lines changed

7 files changed

+25
-34
lines changed

examples/RoughCanvas.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
"name": "python",
251251
"nbconvert_exporter": "python",
252252
"pygments_lexer": "ipython3",
253-
"version": "3.8.5"
253+
"version": "3.9.0"
254254
}
255255
},
256256
"nbformat": 4,

examples/conways_game_of_life.ipynb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,13 @@
5858
" canvas.fill_style = color\n",
5959
" canvas.stroke_style = color\n",
6060
"\n",
61-
" r = 0\n",
62-
" for row in x:\n",
63-
" c = 0\n",
64-
" for value in row:\n",
65-
" if value:\n",
66-
" canvas.fill_rect(r * n_pixels, c * n_pixels, n_pixels, n_pixels)\n",
67-
" canvas.stroke_rect(r * n_pixels, c * n_pixels, n_pixels, n_pixels)\n",
61+
" living_cells = np.where(x)\n",
62+
" \n",
63+
" rects_x = living_cells[0] * n_pixels\n",
64+
" rects_y = living_cells[1] * n_pixels\n",
6865
"\n",
69-
" c += 1\n",
70-
" r += 1"
66+
" canvas.fill_rects(rects_x, rects_y, n_pixels)\n",
67+
" canvas.stroke_rects(rects_x, rects_y, n_pixels)"
7168
]
7269
},
7370
{
@@ -155,7 +152,7 @@
155152
"name": "python",
156153
"nbconvert_exporter": "python",
157154
"pygments_lexer": "ipython3",
158-
"version": "3.8.5"
155+
"version": "3.9.0"
159156
}
160157
},
161158
"nbformat": 4,

examples/drag_and_drop_example.ipynb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@
105105
"\n",
106106
"canvas"
107107
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"metadata": {},
113+
"outputs": [],
114+
"source": []
108115
}
109116
],
110117
"metadata": {
@@ -123,7 +130,7 @@
123130
"name": "python",
124131
"nbconvert_exporter": "python",
125132
"pygments_lexer": "ipython3",
126-
"version": "3.8.3"
133+
"version": "3.9.0"
127134
}
128135
},
129136
"nbformat": 4,

examples/hand_drawing.ipynb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@
4040
"drawing = False\n",
4141
"start = None\n",
4242
"\n",
43-
"def draw_line(canvas, start, end):\n",
44-
" canvas.begin_path()\n",
45-
" canvas.move_to(start[0], start[1])\n",
46-
" canvas.line_to(end[0], end[1])\n",
47-
" canvas.stroke()\n",
48-
" canvas.close_path()\n",
49-
"\n",
5043
"def on_mouse_down(x, y):\n",
5144
" global drawing\n",
5245
" global start\n",
@@ -55,7 +48,7 @@
5548
" start = (x, y)\n",
5649
" else:\n",
5750
" with hold_canvas(canvas):\n",
58-
" draw_line(drawing_layer, start, (x, y))\n",
51+
" drawing_layer.stroke_line(start[0], start[1], x, y)\n",
5952
"\n",
6053
" interaction_layer.clear()\n",
6154
"\n",
@@ -70,7 +63,7 @@
7063
" with hold_canvas(canvas):\n",
7164
" interaction_layer.clear()\n",
7265
"\n",
73-
" draw_line(interaction_layer, start, (x, y))\n",
66+
" interaction_layer.stroke_line(start[0], start[1], x, y)\n",
7467
"\n",
7568
"interaction_layer.on_mouse_down(on_mouse_down)\n",
7669
"interaction_layer.on_mouse_move(on_mouse_move)\n",
@@ -117,7 +110,7 @@
117110
"name": "python",
118111
"nbconvert_exporter": "python",
119112
"pygments_lexer": "ipython3",
120-
"version": "3.8.1"
113+
"version": "3.9.0"
121114
}
122115
},
123116
"nbformat": 4,

examples/mapping.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
"name": "python",
263263
"nbconvert_exporter": "python",
264264
"pygments_lexer": "ipython3",
265-
"version": "3.8.1"
265+
"version": "3.9.0"
266266
}
267267
},
268268
"nbformat": 4,

examples/particle_system.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
"name": "python",
206206
"nbconvert_exporter": "python",
207207
"pygments_lexer": "ipython3",
208-
"version": "3.8.1"
208+
"version": "3.9.0"
209209
}
210210
},
211211
"nbformat": 4,

examples/plotting.ipynb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,17 @@
8787
" background.fill_style = 'black'\n",
8888
" background.stroke_style = '#8c8c8c'\n",
8989
" background.line_width = 1\n",
90-
" background.begin_path()\n",
9190
"\n",
9291
" for i in range(n_lines):\n",
9392
" j = i / (n_lines - 1)\n",
9493
" line_x = drawarea_max_x * j + drawarea_min_x\n",
9594
" line_y = drawarea_max_y * j + drawarea_min_y\n",
9695
"\n",
9796
" # Line on the y axis\n",
98-
" background.move_to(line_x, drawarea_min_y)\n",
99-
" background.line_to(line_x, drawarea_max_y + drawarea_min_y)\n",
97+
" background.stroke_line(line_x, drawarea_min_y, line_x, drawarea_max_y + drawarea_min_y)\n",
10098
"\n",
10199
" # Line on the x axis\n",
102-
" background.move_to(drawarea_min_x, line_y)\n",
103-
" background.line_to(drawarea_max_x + drawarea_min_x, line_y)\n",
100+
" background.stroke_line(drawarea_min_x, line_y, drawarea_max_x + drawarea_min_x, line_y)\n",
104101
"\n",
105102
" # Draw y tick\n",
106103
" background.text_align = 'right'\n",
@@ -110,10 +107,7 @@
110107
" # Draw x tick\n",
111108
" background.text_align = 'center'\n",
112109
" background.text_baseline = 'top'\n",
113-
" background.fill_text('{0:.2e}'.format(self.unscale_x(line_x)), line_x, drawarea_max_y + drawarea_min_y + drawarea_min_y * 0.05)\n",
114-
"\n",
115-
" background.stroke()\n",
116-
" background.close_path()"
110+
" background.fill_text('{0:.2e}'.format(self.unscale_x(line_x)), line_x, drawarea_max_y + drawarea_min_y + drawarea_min_y * 0.05)"
117111
]
118112
},
119113
{
@@ -502,7 +496,7 @@
502496
"name": "python",
503497
"nbconvert_exporter": "python",
504498
"pygments_lexer": "ipython3",
505-
"version": "3.8.3"
499+
"version": "3.9.0"
506500
}
507501
},
508502
"nbformat": 4,

0 commit comments

Comments
 (0)