{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import k3d\n", "import base64" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Produce a plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "iteration = 4\n", "size = 3**iteration\n", "\n", "voxels = np.ones((size, size, size));\n", "\n", "def iterate(length, x, y, z):\n", "\n", " nl = length // 3 \n", "\n", " if nl < 1:\n", " return\n", "\n", " margin = (nl-1) // 2\n", "\n", " voxels[z-margin:z+margin+1, y-margin:y+margin+1, :] = 0\n", " voxels[z-margin:z+margin+1, :, x-margin:x+margin+1] = 0\n", " voxels[:, y-margin:y+margin+1, x-margin:x+margin+1] = 0 \n", "\n", " for ix,iy,iz in np.ndindex((3,3,3)):\n", " if (1 if ix !=1 else 0) + (1 if iy != 1 else 0) + (1 if iz != 1 else 0) !=2:\n", " iterate(nl, x + (ix-1) * nl, y + (iy-1) * nl , z + (iz-1) * nl)\n", "\n", "iterate(size, size//2, size//2, size//2)\n", "\n", "plot = k3d.plot()\n", "plot += k3d.voxels(voxels.astype(np.uint8), compression_level=9)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Create and save to *.k3d file" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "template = \"\"\"\n", "\n", "\n", "
\n", " \n", "