
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import anywidget
from traitlets import Any
from pathlib import Path
import numpy as np
size = 20
def f(i,j):
return (1+np.sin(i*j*0.1))*0.5
voxelarray = np.fromfunction(f, (size, size))
voxelarray_int = np.uint8(voxelarray * 255)
class HelloWidget(anywidget.AnyWidget):
_esm = Path("widget.js")
_css = Path("widget.css")
voxel_data = Any().tag(sync=True)
three_viewer = HelloWidget()
three_viewer.voxel_data = voxelarray_int.tolist()
page = three_viewer