{ "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", "\n", "def r(x, y, z):\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", " return r\n", "\n", "def f(x, y, z):\n", " return 0 if r(x, y, z) > width / 2 else 1 if y + sin(x / 20) * 10 > height / 2 else 2\n", "\n", "color_map = (0xffff00, 0xff0000)\n", "voxels = [[[f(x, y, z) for z in range(length)] for y in range(height)] for x in range(width)]\n", "\n", "plot = K3D()\n", "plot += K3D.voxels(voxels, color_map)\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 }