{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import k3d\n", "import k3d.platonic as platonic\n", "import math\n", "\n", "plot = k3d.plot()\n", "\n", "meshes = [\n", " platonic.Dodecahedron().mesh,\n", " platonic.Cube().mesh,\n", " platonic.Icosahedron().mesh,\n", " platonic.Octahedron().mesh,\n", " platonic.Tetrahedron().mesh\n", "]\n", "\n", "colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff]\n", "\n", "for i, obj in enumerate(meshes): \n", " rad = math.radians(i / len(meshes) * 360)\n", " radius = 3.5\n", " obj.transform.translation = [math.sin(rad) * radius, math.cos(rad) * radius, 0]\n", " obj.color = colors[i]\n", " plot += obj \n", "\n", "plot.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Platonic with custom menu" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import k3d\n", "import k3d.platonic as platonic\n", "import math\n", "from ipywidgets import widgets, link\n", "\n", "plot2 = k3d.plot(menu_visibility=False)\n", "\n", "meshes = [\n", " platonic.Dodecahedron().mesh,\n", " platonic.Cube().mesh,\n", " platonic.Icosahedron().mesh,\n", " platonic.Octahedron().mesh,\n", " platonic.Tetrahedron().mesh\n", "]\n", "\n", "colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff]\n", "\n", "menu = []\n", "\n", "for i, obj in enumerate(meshes): \n", " rad = math.radians(i / len(meshes) * 360)\n", " radius = 3.5\n", " obj.transform.translation = [math.sin(rad) * radius, math.cos(rad) * radius, 0]\n", " obj.color = colors[i]\n", " plot2 += obj\n", " \n", " w = widgets.Checkbox(\n", " value=True,\n", " description='Object #' + str(i),\n", " disabled=False,\n", " indent=False\n", " )\n", " link((w, 'value'), (obj, 'visible'))\n", " menu.append(w)\n", "\n", "display(widgets.HBox(menu))\n", "plot2.display()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.12" } }, "nbformat": 4, "nbformat_minor": 2 }