In [ ]:
import k3d
from math import sqrt, sin, cos

width = height = length = 100

def r(x, y, z):
    r = sqrt((x - width / 2) * (x - width / 2) + (y - height / 2) * (y - height / 2) + (z - length / 2) * (z - length / 2))
    r += sin(x / 2) * 3
    r += cos(y / 10) * 5
    
    return r

def f(x, y, z):
    return 0 if r(x, y, z) > width / 2 else (1 if y + sin(x / 20) * 10 > height / 2 else 2)

color_map = (0xffff00, 0xff0000)
voxels = [[[f(x, y, z) for x in range(width)] for y in range(height)] for z in range(length)]

plot = k3d.plot()
obj = k3d.voxels(voxels, color_map, compression_level=1)
plot += obj
plot.display()
In [ ]:
plot.objects[0].wireframe=True
In [ ]:
plot.objects[0].wireframe=False
plot.objects[0].outlines=True
In [ ]:
plot.objects[0].outlines_color=255
In [ ]:
plot.screenshot_scale = 3.0
In [ ]:
plot.objects[0].opacity = 0.5
In [ ]: