Published
Edited
Apr 4, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
slice = new Array(volume.width * volume.height).fill(0)
Insert cell
canvasImageData = ctx.createImageData(volume.width, volume.height)
Insert cell
mutable eyeVector = [0, 0, 1]
Insert cell
mutable uniforms = 0
Insert cell
deg2rad = deg => (deg * Math.PI) / 180
Insert cell
ctx = myCanvas.getContext("2d")
Insert cell
md`### Volume data and related functions`
Insert cell
volume = volumes[volChoice]
Insert cell
volumes = ({
bucky: buckyVolume,
skull: skullVolume,
foot: footVolume,
//frog: frogVolume,
//brain: brainVolume
})
Insert cell
Insert cell
Insert cell
footVolume = getVolumeFromRawData(
await FileAttachment("Foot.vol").arrayBuffer(),
125,
255,
183
)
Insert cell
new Uint8Array(await FileAttachment("Foot.vol").arrayBuffer()).slice(0, 28)

Insert cell
getVolumeFromRawData = (data, width, height, depth, offset) => ({
width,
height,
depth,
data: new Uint8Array(data.slice(offset === 0 ? 0 : 28))
})
Insert cell
md`### Local Helper Functions`
Insert cell
hex2rgb = hex =>
(hex = hex.replace('#', ''))
.match(new RegExp('(.{' + hex.length / 3 + '})', 'g'))
.map(l => parseInt(hex.length % 2 ? l + l : l, 16) / 255)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more