{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import k3d\n", "\n", "vertices = [\n", " -10, 0, -1,\n", " 10, 0, -1,\n", " 10, 0, 1,\n", " -10, 0, 1,\n", "]\n", "\n", "indices = [\n", " 0, 1, 3,\n", " 1, 2, 3\n", "]\n", "\n", "plot = k3d.plot()\n", "plot += k3d.mesh(vertices, indices)\n", "plot.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "from ipywidgets import widgets,interact\n", "\n", "vertex_attribute = [0, 1, 1, 0]\n", "\n", "plot = k3d.plot()\n", "mesh = k3d.mesh(vertices, indices, attribute=vertex_attribute, color_map=k3d.basic_color_maps.CoolWarm, color_range=[0.0, 1.0])\n", "plot += mesh\n", "\n", "basic_color_maps = [attr for attr in dir(k3d.basic_color_maps) if not attr.startswith('__')]\n", "paraview_color_maps = [attr for attr in dir(k3d.paraview_color_maps) if not attr.startswith('__')]\n", "matplotlib_color_maps = [attr for attr in dir(k3d.matplotlib_color_maps) if not attr.startswith('__')]\n", "\n", "@interact(x=widgets.Dropdown(options=basic_color_maps, value=basic_color_maps[0], description='Basic ColorMap:'))\n", "def g(x):\n", " mesh.color_map = getattr(k3d.basic_color_maps, x)\n", "\n", "@interact(x=widgets.Dropdown(options=paraview_color_maps, value=paraview_color_maps[0], description='ParaView ColorMap:'))\n", "def g(x):\n", " mesh.color_map = getattr(k3d.paraview_color_maps, x)\n", " \n", "@interact(x=widgets.Dropdown(options=matplotlib_color_maps, value=matplotlib_color_maps[0], description='MatplolLib ColorMap:'))\n", "def g(x):\n", " mesh.color_map = getattr(k3d.matplotlib_color_maps, x)\n", "\n", "plot.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# show vertex numbers:\n", "import numpy as np\n", "v = np.array(vertices).reshape((len(vertices)//3, 3))\n", "for i, pos in enumerate(v):\n", " plot += k3d.text(text=str(i), position=pos, color=0, reference_point='cc')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.5" }, "nbTranslate": { "displayLangs": [ "en", "pl" ], "hotkey": "alt-t", "langInMainMenu": true, "sourceLang": "pl", "targetLang": "en", "useGoogleTranslate": true }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 2 }