{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import k3d\n", "import k3d.platonic as platonic\n", "import math\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = k3d.plot(auto_rendering=False, grid_auto_fit=False, grid_visible=False)\n", "plot.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff]\n", "\n", "for j in range(5):\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", " for i, obj in enumerate(meshes):\n", " obj.color = colors[i]\n", " plot += obj\n", " \n", "for time in np.linspace(0, 4 * np.pi, 120): \n", " k = 0\n", " for j in range(5):\n", " for i in range(len(meshes)):\n", " rad = math.radians(i / len(meshes) * 360)\n", " radius = 3.5\n", " \n", " t = k3d.transform()\n", " t.translation = [math.sin(rad + time) * radius, math.cos(rad + time) * radius, 2.5*j]\n", " t.rotation = [j + time, 0, 0, 1]\n", " \n", " plot.objects[k].model_matrix = t.model_matrix\n", " \n", " k += 1\n", " \n", " plot.render()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = k3d.plot()\n", "plot.display()\n", "\n", "colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff]\n", "\n", "for j in range(5):\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", " for i, obj in enumerate(meshes):\n", " rad = math.radians(i / len(meshes) * 360)\n", " radius = 3.5\n", " \n", " model_matrix = {}\n", " \n", " for time in np.linspace(0, 2 * np.pi, 60):\n", " t = k3d.transform()\n", " t.translation = [math.sin(rad + time) * radius, math.cos(rad + time) * radius, 2.5*j]\n", " t.rotation = [time - j, 0, 0, 1]\n", "\n", " model_matrix[str(time)] = t.model_matrix\n", " \n", " obj.model_matrix = model_matrix\n", " obj.color = colors[i]\n", " plot += obj" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.grid_auto_fit = False\n", "plot.camera_auto_fit = False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.start_auto_play()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.stop_auto_play()" ] }, { "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": 4 }