3D Voxels
3D Star Voxels
Six-pointed 3D star with coral-pink gradient coloring.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
n = 20
voxels = np.zeros((n, n, n), dtype=bool)
cx, cy = n // 2, n // 2
# Spiral pattern
for z in range(n):
angle = z * np.pi / 4
for da in np.linspace(0, np.pi/2, 3):
r = 3 + z * 0.15
xx = int(cx + r * np.cos(angle + da))
yy = int(cy + r * np.sin(angle + da))
if 0 <= xx < n and 0 <= yy < n:
voxels[xx, yy, z] = True
if xx + 1 < n:
voxels[xx+1, yy, z] = True
if yy + 1 < n:
voxels[xx, yy+1, z] = True
# Gradient from cyan #27D3F5 to blue #276CF5
z_idx = np.indices((n, n, n))[2]
colors = np.empty(voxels.shape + (4,), dtype=np.float32)
colors[..., 3] = 0
norm_z = z_idx / (n - 1)
# 27D3F5 -> 276CF5
colors[voxels, 0] = 0.15 # 27 (constant)
colors[voxels, 1] = 0.83 - 0.41 * norm_z[voxels] # D3 to 6C
colors[voxels, 2] = 0.96 # F5 (constant)
colors[voxels, 3] = 0.9
fig = plt.figure(figsize=(10, 8), facecolor='#020B14')
ax = fig.add_subplot(111, projection='3d', facecolor='#020B14')
ax.voxels(voxels, facecolors=colors, edgecolors='#1e293b', linewidth=0.3)
ax.set_xlabel('X', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_ylabel('Y', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_zlabel('Z', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_title('Spiral Tower Voxels', fontsize=14, color='white', fontweight='bold', pad=20)
ax.tick_params(colors='#64748b', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#1e293b')
ax.yaxis.pane.set_edgecolor('#1e293b')
ax.zaxis.pane.set_edgecolor('#1e293b')
ax.grid(True, alpha=0.2, color='#475569')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
3D Charts
More 3D Voxels examples
☕