The following looks fine (using rect instead of box):
#import "@preview/cetz:0.4.2"
#set page(width: auto, height: auto, margin: .5cm)
#cetz.canvas({
import cetz.tree
import cetz.draw: *
set-style(content: (padding: .1))
tree.tree(
(([A]), ([B], [3], [12], [8]), ([C], [2], [16], [1]), ([D], [14], [0], [5])),
draw-node: (node, ..) => {
if node.depth == 0 {
polygon((), 3, angle: 90deg)
content((),node.content)
} else if node.depth == 1 {
polygon((), 3, angle: -90deg)
content((),node.content)
} else if node.depth == 2 {
rect((-0.5, -0.5), (0.5, 0.5))
content((0, 0), node.content)
}
})
})
