3D Voxels

DNA Double Helix Voxels

Voxelized DNA double helix structure with cyan and coral strands.

Output
DNA Double Helix Voxels
Python
import matplotlib.pyplot as plt
import numpy as np

n = 16
x, y, z = np.indices((n, n, n))

# Double helix parameters
center = n // 2
radius = 3
helix = np.zeros((n, n, n), dtype=bool)
colors = np.zeros((n, n, n, 4), dtype=np.float32)

for level in range(n):
    angle1 = level * np.pi / 4
    angle2 = angle1 + np.pi
    
    # First strand - coral #F5276C
    px1 = int(center + radius * np.cos(angle1))
    py1 = int(center + radius * np.sin(angle1))
    if 0 <= px1 < n and 0 <= py1 < n:
        helix[px1, py1, level] = True
        colors[px1, py1, level] = [0.96, 0.15, 0.42, 0.9]
    
    # Second strand - cyan #27D3F5
    px2 = int(center + radius * np.cos(angle2))
    py2 = int(center + radius * np.sin(angle2))
    if 0 <= px2 < n and 0 <= py2 < n:
        helix[px2, py2, level] = True
        colors[px2, py2, level] = [0.15, 0.83, 0.96, 0.9]
    
    # Connecting rungs - yellow_lime #D3F527
    if level % 4 == 0:
        for t in np.linspace(0, 1, 5):
            rx = int(px1 + t * (px2 - px1))
            ry = int(py1 + t * (py2 - py1))
            if 0 <= rx < n and 0 <= ry < n:
                helix[rx, ry, level] = True
                colors[rx, ry, level] = [0.83, 0.96, 0.15, 0.9]

fig = plt.figure(figsize=(10, 8), facecolor='#020B14')
ax = fig.add_subplot(111, projection='3d', facecolor='#020B14')

ax.voxels(helix, facecolors=colors, edgecolor='#ffffff15', linewidth=0.2)

ax.set_xlabel('X', fontsize=10, color='#94a3b8', labelpad=10)
ax.set_ylabel('Y', fontsize=10, color='#94a3b8', labelpad=10)
ax.set_zlabel('Z', fontsize=10, color='#94a3b8', labelpad=10)
ax.set_title("DNA Double Helix 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.view_init(elev=20, azim=45)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support