{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from k3d import K3D\n", "from math import sqrt, sin, cos\n", "\n", "width = height = length = 100\n", "voxels = []\n", "color_map = (\n", " (0.7, 0.5, 0.0),\n", " (1.0, 0.0, 0.0)\n", ")\n", "\n", "for z in range(length):\n", " for y in range(height):\n", " for x in range(width):\n", " r = sqrt((x - width / 2) * (x - width / 2) + (y - height / 2) * (y - height / 2) + (z - length / 2) * (z - length / 2))\n", " r += sin(x / 2) * 3\n", " r += cos(y / 10) * 5\n", " \n", " if r > width / 2:\n", " voxels.append(0)\n", " elif y + sin(x / 20) * 10 > height / 2:\n", " voxels.append(1)\n", " else:\n", " voxels.append(2)\n", " \n", "plot = K3D()\n", "plot += K3D.voxels(voxels, color_map, width, height, length)\n", "plot.display()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }