kolibril13 commited on
Commit
7e5c044
1 Parent(s): 04ad805

add start question

Browse files
Files changed (1) hide show
  1. pages/01_molecule.ipynb +50 -38
pages/01_molecule.ipynb CHANGED
@@ -12,46 +12,58 @@
12
  "\n",
13
  "light_position = solara.reactive(3)\n",
14
  "\n",
 
 
 
 
15
  "@solara.component\n",
16
  "def Page():\n",
17
- " solara.SliderInt(\"Pos:\", value=light_position, min=0, max=10)\n",
18
- " \n",
19
- " # Delete all mesh objects from the scene\n",
20
- " bpy.ops.object.select_all(action=\"DESELECT\")\n",
21
- " bpy.ops.object.select_by_type(type=\"MESH\")\n",
22
- " bpy.ops.object.delete()\n",
23
- " \n",
24
- " # Add a torus\n",
25
- " bpy.ops.mesh.primitive_torus_add(\n",
26
- " major_radius=1.5,\n",
27
- " minor_radius=0.75,\n",
28
- " major_segments=48 * 4,\n",
29
- " minor_segments=12 * 4,\n",
30
- " align=\"WORLD\",\n",
31
- " location=(0, 1, 1),\n",
32
- " )\n",
33
- " \n",
34
- " # # Light\n",
35
- " light = bpy.data.objects[\"Light\"]\n",
36
- " light.location = (light_position.value, 0, 2) # Position the light\n",
37
- " \n",
38
- " # # Camera\n",
39
- " camera = bpy.data.objects[\"Camera\"]\n",
40
- " camera.location = (5, -3, 4)\n",
41
- " camera.data.dof.use_dof = True\n",
42
- " camera.data.dof.focus_distance = 5\n",
43
- " camera.data.dof.aperture_fstop = 4\n",
44
- " \n",
45
- " # # Render\n",
46
- " path = \"test.png\"\n",
47
- " bpy.context.scene.render.resolution_x = 400\n",
48
- " bpy.context.scene.render.resolution_y = 200\n",
49
- " bpy.context.scene.render.image_settings.file_format = \"PNG\"\n",
50
- " bpy.context.scene.render.filepath = path\n",
51
- " bpy.ops.render.render(write_still=True)\n",
52
- " bpy.data.images[\"Render Result\"].save_render(filepath=bpy.context.scene.render.filepath)\n",
53
- " \n",
54
- " display(Image(path))\n",
 
 
 
 
 
 
 
 
55
  "\n",
56
  "Page()"
57
  ]
 
12
  "\n",
13
  "light_position = solara.reactive(3)\n",
14
  "\n",
15
+ "\n",
16
+ "\n",
17
+ "start_button = solara.reactive(False)\n",
18
+ "\n",
19
  "@solara.component\n",
20
  "def Page():\n",
21
+ " checkbox = solara.Checkbox(label=\"Start Rendering?\", value=start_button)\n",
22
+ " if not start_button.value:\n",
23
+ " solara.Warning(\"Rendering is off, you might want to turn it on\")\n",
24
+ " else:\n",
25
+ " solara.Success(\"Rendering started. Takes about 10 Seconds\")\n",
26
+ "\n",
27
+ "\n",
28
+ "\n",
29
+ " solara.SliderInt(\"Pos:\", value=light_position, min=0, max=10)\n",
30
+ " \n",
31
+ " # Delete all mesh objects from the scene\n",
32
+ " bpy.ops.object.select_all(action=\"DESELECT\")\n",
33
+ " bpy.ops.object.select_by_type(type=\"MESH\")\n",
34
+ " bpy.ops.object.delete()\n",
35
+ " \n",
36
+ " # Add a torus\n",
37
+ " bpy.ops.mesh.primitive_torus_add(\n",
38
+ " major_radius=1.5,\n",
39
+ " minor_radius=0.75,\n",
40
+ " major_segments=48 * 4,\n",
41
+ " minor_segments=12 * 4,\n",
42
+ " align=\"WORLD\",\n",
43
+ " location=(0, 1, 1),\n",
44
+ " )\n",
45
+ " \n",
46
+ " # # Light\n",
47
+ " light = bpy.data.objects[\"Light\"]\n",
48
+ " light.location = (light_position.value, 0, 2) # Position the light\n",
49
+ " \n",
50
+ " # # Camera\n",
51
+ " camera = bpy.data.objects[\"Camera\"]\n",
52
+ " camera.location = (5, -3, 4)\n",
53
+ " camera.data.dof.use_dof = True\n",
54
+ " camera.data.dof.focus_distance = 5\n",
55
+ " camera.data.dof.aperture_fstop = 4\n",
56
+ " \n",
57
+ " # # Render\n",
58
+ " path = \"test.png\"\n",
59
+ " bpy.context.scene.render.resolution_x = 400\n",
60
+ " bpy.context.scene.render.resolution_y = 200\n",
61
+ " bpy.context.scene.render.image_settings.file_format = \"PNG\"\n",
62
+ " bpy.context.scene.render.filepath = path\n",
63
+ " bpy.ops.render.render(write_still=True)\n",
64
+ " bpy.data.images[\"Render Result\"].save_render(filepath=bpy.context.scene.render.filepath)\n",
65
+ " \n",
66
+ " display(Image(path))\n",
67
  "\n",
68
  "Page()"
69
  ]