Skip to content

Commit

Permalink
lecture 2
Browse files Browse the repository at this point in the history
  • Loading branch information
fcichos committed Apr 12, 2024
1 parent 54742dd commit 24aa817
Show file tree
Hide file tree
Showing 16 changed files with 1,083 additions and 372 deletions.
Binary file modified build/doctrees/environment.pickle
Binary file not shown.
165 changes: 127 additions & 38 deletions build/doctrees/nbsphinx/notebooks/L1/1_ray_optics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,48 @@
},
{
"cell_type": "code",
"execution_count": 89,
"execution_count": 102,
"id": "fbf42d2d-ba72-4d79-b251-bf343a9c054c",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<script src='https://d3js.org/d3.v6.min.js'></script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<script src='https://d3js.org/d3.v6.min.js'></script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<script src='https://d3js.org/d3.v6.min.js'></script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
Expand Down Expand Up @@ -184,7 +220,7 @@
},
{
"cell_type": "code",
"execution_count": 92,
"execution_count": 103,
"id": "a7043a8d-8a5a-4b0a-9ec3-3c61e77665b1",
"metadata": {
"tags": []
Expand Down Expand Up @@ -241,33 +277,70 @@
{
"data": {
"text/html": [
"<script src='https://d3js.org/d3.v6.min.js'></script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<script src='https://d3js.org/d3.v6.min.js'></script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<script src='https://d3js.org/d3.v6.min.js'></script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "81c9708e657a43299356d6d746905d25",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=50.0, continuous_update=False, description='Radius:', min=10.0, step=1…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<div id=\"d3-container\"></div>\n",
"<script src=\"https://d3js.org/d3.v6.min.js\"></script>\n",
"<script>\n",
"// Ensure D3.js is loaded\n",
"if (d3) {\n",
" // Select the container\n",
" var container = d3.select(\"#d3-container\");\n",
" \n",
" // Append an SVG element to the container\n",
" var svg = container.append(\"svg\")\n",
" .attr(\"width\", 400)\n",
" .attr(\"width\", 200)\n",
" .attr(\"height\", 200);\n",
" \n",
" // Append a circle to the SVG element\n",
" svg.append(\"circle\")\n",
" .attr(\"id\", \"d3-circle\")\n",
" .attr(\"cx\", 100)\n",
" .attr(\"cy\", 100)\n",
" .attr(\"r\", 50)\n",
" .style(\"fill\", \"blue\");\n",
" \n",
" circle.transition()\n",
" .duration(10000) // 2 seconds\n",
" .attr(\"cx\", 290) // End at the right side\n",
" .ease(d3.easeLinear); // Use a linear easing function\n",
" \n",
"} else {\n",
" console.error(\"D3.js is not loaded\");\n",
"}\n",
"</script>\n"
],
"text/plain": [
Expand All @@ -279,35 +352,51 @@
}
],
"source": [
"%%html\n",
"from ipywidgets import interact, FloatSlider\n",
"from IPython.display import display, HTML, Javascript\n",
"\n",
"# Define the function to update the circle radius\n",
"def update_circle_radius(radius):\n",
" display(Javascript(f\"\"\"\n",
" (function() {{\n",
" var circle = d3.select(\"#d3-circle\");\n",
" if(circle) circle.attr(\"r\", {radius});\n",
" }})();\n",
" \"\"\"))\n",
"\n",
"# Create the slider widget\n",
"slider = FloatSlider(\n",
" value=50,\n",
" min=10,\n",
" max=100,\n",
" step=1,\n",
" description='Radius:',\n",
" continuous_update=False\n",
")\n",
"\n",
"# Display the slider and pass the update function as the callback\n",
"interact(update_circle_radius, radius=slider)\n",
"\n",
"# Define the HTML and JavaScript code for the initial D3.js circle\n",
"html_code = \"\"\"\n",
"<div id=\"d3-container\"></div>\n",
"<script src=\"https://d3js.org/d3.v6.min.js\"></script>\n",
"<script>\n",
"// Ensure D3.js is loaded\n",
"if (d3) {\n",
" // Select the container\n",
" var container = d3.select(\"#d3-container\");\n",
" \n",
" // Append an SVG element to the container\n",
" var svg = container.append(\"svg\")\n",
" .attr(\"width\", 400)\n",
" .attr(\"width\", 200)\n",
" .attr(\"height\", 200);\n",
" \n",
" // Append a circle to the SVG element\n",
" svg.append(\"circle\")\n",
" .attr(\"id\", \"d3-circle\")\n",
" .attr(\"cx\", 100)\n",
" .attr(\"cy\", 100)\n",
" .attr(\"r\", 50)\n",
" .style(\"fill\", \"blue\");\n",
" \n",
" circle.transition()\n",
" .duration(10000) // 2 seconds\n",
" .attr(\"cx\", 290) // End at the right side\n",
" .ease(d3.easeLinear); // Use a linear easing function\n",
" \n",
"} else {\n",
" console.error(\"D3.js is not loaded\");\n",
"}\n",
"</script>"
"</script>\n",
"\"\"\"\n",
"\n",
"# Display the initial D3.js circle\n",
"display(HTML(html_code))"
]
},
{
Expand Down
Binary file modified build/doctrees/notebooks/L1/1_ray_optics.doctree
Binary file not shown.
Binary file modified build/doctrees/notebooks/L1/Lecture1.doctree
Binary file not shown.
Loading

0 comments on commit 24aa817

Please sign in to comment.