Skip to content

Commit 10d1896

Browse files
committed
Format example Notebooks with black
1 parent eecd039 commit 10d1896

21 files changed

+950
-398
lines changed

examples/3d_monkey.ipynb

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
32-
"with open('monkey.obj', 'r') as fobj:\n",
32+
"with open(\"monkey.obj\", \"r\") as fobj:\n",
3333
" lines = [line.strip() for line in fobj.readlines()]"
3434
]
3535
},
@@ -53,32 +53,32 @@
5353
"source": [
5454
"# Extract vertices\n",
5555
"for line in lines:\n",
56-
" splitted = line.split(' ')\n",
56+
" splitted = line.split(\" \")\n",
5757
"\n",
5858
" # Vertex\n",
59-
" if splitted[0] == 'v':\n",
59+
" if splitted[0] == \"v\":\n",
6060
" _, v1, v2, v3 = splitted\n",
6161
" vertices.append([float(v1), float(v2), float(v3)])\n",
6262
"\n",
6363
" # Normal\n",
64-
" if splitted[0] == 'vn':\n",
64+
" if splitted[0] == \"vn\":\n",
6565
" _, v1, v2, v3 = splitted\n",
6666
" vertex_normals.append([float(v1), float(v2), float(v3)])\n",
6767
"\n",
6868
"# Extract faces\n",
6969
"for line in lines:\n",
70-
" splitted = line.split(' ')\n",
70+
" splitted = line.split(\" \")\n",
7171
"\n",
7272
" # Face\n",
73-
" if splitted[0] == 'f':\n",
73+
" if splitted[0] == \"f\":\n",
7474
" # This file is triangulated, so this is fine\n",
7575
" _, v1, v2, v3 = splitted\n",
7676
"\n",
77-
" # It happens that this mesh is flat-shaded, so the normal is \n",
77+
" # It happens that this mesh is flat-shaded, so the normal is\n",
7878
" # the same on all vertices\n",
79-
" v1_index, _, v1_normal = v1.split('/')\n",
80-
" v2_index, _, _ = v2.split('/')\n",
81-
" v3_index, _, _ = v3.split('/')\n",
79+
" v1_index, _, v1_normal = v1.split(\"/\")\n",
80+
" v2_index, _, _ = v2.split(\"/\")\n",
81+
" v3_index, _, _ = v3.split(\"/\")\n",
8282
"\n",
8383
" faces.append([int(v1_index) - 1, int(v2_index) - 1, int(v3_index) - 1])\n",
8484
" faces_normals.append(int(v1_normal) - 1)"
@@ -152,17 +152,19 @@
152152
" super(MonkeyCloud, self).__init__(width=500, height=500)\n",
153153
"\n",
154154
" self.dragging = False\n",
155-
" \n",
156-
" self.x = vertices[:,0]\n",
157-
" self.y = vertices[:,1]\n",
158-
" self.z = vertices[:,2]\n",
159-
" \n",
155+
"\n",
156+
" self.x = vertices[:, 0]\n",
157+
" self.y = vertices[:, 1]\n",
158+
" self.z = vertices[:, 2]\n",
159+
"\n",
160160
" self.dx = 0\n",
161161
" self.dy = 0\n",
162162
" self.radius = 10\n",
163163
"\n",
164-
" self.camera = OrbitCamera(self.radius, [0, 0, 0], self.width/self.height)\n",
165-
" self.x2, self.y2, self.z2 = project_vector(self.x, self.y, self.z, self.camera.matrix)\n",
164+
" self.camera = OrbitCamera(self.radius, [0, 0, 0], self.width / self.height)\n",
165+
" self.x2, self.y2, self.z2 = project_vector(\n",
166+
" self.x, self.y, self.z, self.camera.matrix\n",
167+
" )\n",
166168
" self.draw()\n",
167169
"\n",
168170
" self.on_mouse_down(self.mouse_down_handler)\n",
@@ -173,9 +175,11 @@
173175
" def update_matrix(self, dx=None, dy=None):\n",
174176
" dx = dx if dx is not None else self.dx\n",
175177
" dy = dy if dy is not None else self.dy\n",
176-
" \n",
178+
"\n",
177179
" self.camera.update_position(dy, dx)\n",
178-
" self.x2, self.y2, self.z2 = project_vector(self.x, self.y, self.z, self.camera.matrix)\n",
180+
" self.x2, self.y2, self.z2 = project_vector(\n",
181+
" self.x, self.y, self.z, self.camera.matrix\n",
182+
" )\n",
179183
" self.draw()\n",
180184
"\n",
181185
" def draw(self):\n",
@@ -194,15 +198,15 @@
194198
" if self.dragging:\n",
195199
" self.dx_new = self.dx + pixel_x - self.x_mouse\n",
196200
" self.dy_new = self.dy + pixel_y - self.y_mouse\n",
197-
" \n",
201+
"\n",
198202
" self.update_matrix(self.dx_new, self.dy_new)\n",
199-
" \n",
203+
"\n",
200204
" def mouse_up_handler(self, pixel_x, pixel_y):\n",
201205
" if self.dragging:\n",
202206
" self.dragging = False\n",
203207
" self.dx = self.dx_new\n",
204208
" self.dy = self.dy_new\n",
205-
" \n",
209+
"\n",
206210
" def mouse_out_handler(self, pixel_x, pixel_y):\n",
207211
" if self.dragging:\n",
208212
" self.dragging = False\n",
@@ -258,16 +262,16 @@
258262
" super(Monkey, self).__init__(width=500, height=500)\n",
259263
"\n",
260264
" self.dragging = False\n",
261-
" \n",
262-
" self.x = vertices[:,0]\n",
263-
" self.y = vertices[:,1]\n",
264-
" self.z = vertices[:,2]\n",
265-
" \n",
265+
"\n",
266+
" self.x = vertices[:, 0]\n",
267+
" self.y = vertices[:, 1]\n",
268+
" self.z = vertices[:, 2]\n",
269+
"\n",
266270
" self.dx = 0\n",
267271
" self.dy = 0\n",
268272
" self.radius = 10\n",
269273
"\n",
270-
" self.camera = OrbitCamera(self.radius, [0, 0, 0], self.width/self.height)\n",
274+
" self.camera = OrbitCamera(self.radius, [0, 0, 0], self.width / self.height)\n",
271275
" self.update_matrix()\n",
272276
"\n",
273277
" self.on_mouse_down(self.mouse_down_handler)\n",
@@ -282,24 +286,33 @@
282286
" self.camera.update_position(dy, dx)\n",
283287
"\n",
284288
" dist = np.linalg.norm(self.camera.position - triangles_positions, axis=1)\n",
285-
" \n",
289+
"\n",
286290
" # Face culling: Get rid of the triangles that are not facing the camera\n",
287291
" triangles_facing_camera = np.dot(triangles_normals, self.camera.front) < 0\n",
288292
"\n",
289293
" self.triangles = triangles[triangles_facing_camera]\n",
290294
" self.triangles_normals = triangles_normals[triangles_facing_camera]\n",
291295
" self.dist = dist[triangles_facing_camera]\n",
292-
" \n",
296+
"\n",
293297
" # Face sorting: Sort triangle by depth (distance to camera) so we can draw further triangles first\n",
294298
" self.order = np.flip(np.argsort(self.dist))\n",
295-
" \n",
299+
"\n",
296300
" # Project triangles\n",
297-
" triangle_vertices = self.triangles.reshape(self.triangles.shape[0] * self.triangles.shape[1], 3)\n",
298-
" proj_x, proj_y, _ = project_vector(triangle_vertices[:,0], triangle_vertices[:,1], triangle_vertices[:,2], self.camera.matrix)\n",
301+
" triangle_vertices = self.triangles.reshape(\n",
302+
" self.triangles.shape[0] * self.triangles.shape[1], 3\n",
303+
" )\n",
304+
" proj_x, proj_y, _ = project_vector(\n",
305+
" triangle_vertices[:, 0],\n",
306+
" triangle_vertices[:, 1],\n",
307+
" triangle_vertices[:, 2],\n",
308+
" self.camera.matrix,\n",
309+
" )\n",
299310
" proj_x = proj_x * self.width + self.width / 2\n",
300311
" proj_y = proj_y * self.height + self.height / 2\n",
301312
"\n",
302-
" self.proj_triangles = np.stack((proj_x, proj_y), axis=1).reshape(self.triangles.shape[0], self.triangles.shape[1], 2)\n",
313+
" self.proj_triangles = np.stack((proj_x, proj_y), axis=1).reshape(\n",
314+
" self.triangles.shape[0], self.triangles.shape[1], 2\n",
315+
" )\n",
303316
"\n",
304317
" self.draw()\n",
305318
"\n",
@@ -311,16 +324,16 @@
311324
" for i in self.order:\n",
312325
" triangle = self.proj_triangles[i]\n",
313326
" normal = self.triangles_normals[i]\n",
314-
" \n",
327+
"\n",
315328
" # Shading depending on light direction and face normal\n",
316329
" light = np.dot(light_direction, normal)\n",
317330
" if light < 0.4:\n",
318331
" light = 0.4\n",
319332
" elif light > 1:\n",
320333
" light = 1\n",
321334
" r, g, b = int(214 * light), int(224 * light), int(125 * light)\n",
322-
" self.fill_style = 'rgb({}, {}, {})'.format(r, g, b)\n",
323-
" \n",
335+
" self.fill_style = \"rgb({}, {}, {})\".format(r, g, b)\n",
336+
"\n",
324337
" self.fill_polygon(triangle)\n",
325338
"\n",
326339
" def mouse_down_handler(self, pixel_x, pixel_y):\n",
@@ -332,15 +345,15 @@
332345
" if self.dragging:\n",
333346
" self.dx_new = self.dx + pixel_x - self.x_mouse\n",
334347
" self.dy_new = self.dy + pixel_y - self.y_mouse\n",
335-
" \n",
348+
"\n",
336349
" self.update_matrix(self.dx_new, self.dy_new)\n",
337-
" \n",
350+
"\n",
338351
" def mouse_up_handler(self, pixel_x, pixel_y):\n",
339352
" if self.dragging:\n",
340353
" self.dragging = False\n",
341354
" self.dx = self.dx_new\n",
342355
" self.dy = self.dy_new\n",
343-
" \n",
356+
"\n",
344357
" def mouse_out_handler(self, pixel_x, pixel_y):\n",
345358
" if self.dragging:\n",
346359
" self.dragging = False\n",

examples/Gradients.ipynb

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@
3737
"outputs": [],
3838
"source": [
3939
"gradient = canvas.create_linear_gradient(\n",
40-
" 0, 0, # Start position (x0, y0)\n",
41-
" 700, 0, # End position (x1, y1)\n",
40+
" 0,\n",
41+
" 0, # Start position (x0, y0)\n",
42+
" 700,\n",
43+
" 0, # End position (x1, y1)\n",
4244
" # List of color stops\n",
4345
" [\n",
44-
" (0, 'red'),\n",
45-
" (1 / 6, 'orange'), \n",
46-
" (2 / 6, 'yellow'),\n",
47-
" (3 / 6, 'green'),\n",
48-
" (4 / 6, 'blue'),\n",
49-
" (5 / 6, '#4B0082'),\n",
50-
" (1, 'violet')\n",
51-
" ]\n",
46+
" (0, \"red\"),\n",
47+
" (1 / 6, \"orange\"),\n",
48+
" (2 / 6, \"yellow\"),\n",
49+
" (3 / 6, \"green\"),\n",
50+
" (4 / 6, \"blue\"),\n",
51+
" (5 / 6, \"#4B0082\"),\n",
52+
" (1, \"violet\"),\n",
53+
" ],\n",
5254
")"
5355
]
5456
},
@@ -102,12 +104,16 @@
102104
"outputs": [],
103105
"source": [
104106
"radial_gradient = canvas2.create_radial_gradient(\n",
105-
" 238, 50, 10, # Start circle (x0, y0, r0)\n",
106-
" 238, 50, 300, # End circle (x1, y1, r1)\n",
107+
" 238,\n",
108+
" 50,\n",
109+
" 10, # Start circle (x0, y0, r0)\n",
110+
" 238,\n",
111+
" 50,\n",
112+
" 300, # End circle (x1, y1, r1)\n",
107113
" [\n",
108-
" (0, '#8ED6FF'),\n",
109-
" (1, '#004CB3'),\n",
110-
" ]\n",
114+
" (0, \"#8ED6FF\"),\n",
115+
" (1, \"#004CB3\"),\n",
116+
" ],\n",
111117
")"
112118
]
113119
},

0 commit comments

Comments
 (0)