<jupyter_start><jupyter_text>Regular (dense) voxels<jupyter_code>import k3d
from math import sqrt, sin, cos

width = 100
height = 100
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)]

# add red voxels in the corners, just for 
for x in [0, -1]:
    for y in [0, -1]:
        for z in [0, -1]:
            voxels[z][y][x] = 2

plot = k3d.plot()
obj = k3d.voxels(voxels, color_map, compression_level=1)
plot += obj
plot.display()
plot.objects[0].wireframe=True
plot.objects[0].wireframe=False
plot.objects[0].outlines=True
plot.objects[0].outlines_color=255
plot.screenshot_scale = 3.0
plot.objects[0].opacity = 0.5<jupyter_output><empty_output><jupyter_text>Sparse voxels<jupyter_code>import k3d
import numpy as np
N = 20

sparse_voxels = np.random.randint(0, 5, size=(N, 4), dtype=np.uint16)
sparse_voxels[:, 3] = np.random.randint(1, 3, size=(N,))
sparse_voxels[:5]
# default color_map used
plot = k3d.plot()
obj = k3d.sparse_voxels(sparse_voxels, [10, 10, 10], compression_level=1)
plot += obj
plot.display()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1642512077294686, 'fraction_numerical': 0.055900621118012424, 'mean_word_length': 3.559748427672956, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '89452', 'license': 'MIT', 'n_tokens_mistral': 665, 'n_tokens_neox': 608, 'n_words': 167, 'path': 'examples/voxels.ipynb', 'repo_name': 'Eccsx/K3D-jupyter', 'size': '1449'}