In [ ]:
import k3d
import numpy as np

iteration = 4
size = 3**iteration

voxels = np.ones((size, size, size));

def iterate(length, x, y, z):
    
    nl = length // 3    
    
    if nl < 1:
        return
    
    margin = (nl-1) // 2

    voxels[z-margin:z+margin+1, y-margin:y+margin+1, :] = 0
    voxels[z-margin:z+margin+1, :, x-margin:x+margin+1] = 0
    voxels[:, y-margin:y+margin+1, x-margin:x+margin+1] = 0    
    
    for ix,iy,iz in np.ndindex((3,3,3)):
        if (1 if ix !=1 else 0) + (1 if iy != 1 else 0) + (1 if iz != 1 else 0) !=2:
            iterate(nl, x + (ix-1) * nl, y + (iy-1) * nl , z + (iz-1) * nl)

iterate(size, size//2, size//2, size//2)

color_map = (0xffff00)
plot = k3d.plot()
plot += k3d.voxels(voxels.astype(np.uint8), color_map)
plot.display()
In [ ]:
plot.camera = [49.74392405695982,
 -2.9524769249925455,
 27.185488598217045,
 43.65220601477353,
 19.109636932275787,
 9.719259554462269,
 -0.19179675209811095,
 0.5291470859180342,
 0.8265696385357213]
In [ ]:
plot.clipping_planes = [[0, 0, -1, 0.15]]
In [ ]:
plot.clipping_planes = [
    [0, 0, -1, 0.15],
    [-0.5931578442826305,
    0.6811078258641979,
    -0.42925039465622833,
    0.09701107626276362]
]
In [ ]:
plot.clipping_planes
In [ ]: