3D DNA Helix β JavaScript Canvas Animation with Source Code
The 3D DNA Helix is a visually striking particle animation that recreates the iconic biological double-helix structure. Built with high-performance Canvas rendering, it features two twisted strands of glowing nodes that rotate in a 3D-like space, complete with connecting βbridgesβ and atmospheric trails.
How It Works
The animation is powered by a sine-wave mathematical model. Two independent strands of particles are calculated using Math.sin(offset) for the X position and Math.cos(offset) for the particle size (which creates the illusion of Z-depth). The two strands are given a 180-degree phase shift (Math.PI) to ensure they perfectly intertwine. A background βtrailβ is created by filling the canvas with a mostly transparent black rectangle (rgba(0,0,0,0.08)) in every frame instead of clearing it entirely.
Use Cases
- Hero backgrounds for science, education, or healthcare websites
- Loading animations for biotech applications
- Abstract tech graphics for creative agency portfolios
- Interactive educational tools for biology students
How to Customize
- Change Helix Speed: Adjust the
angle += 0.02increment in thedraw()function. - Adjust Helix Width: Change the
80multiplier in thex1andx2calculations. - Strand Colors: Modify the
ctx.fillStylevalues (currently#00f2feand#4facfe). - Particle Density: Change the
particles = 40variable to make the helix more or less granular.
Frequently Asked Questions
Is this using a 3D library like Three.js?
No. This is pure vanilla JavaScript using basic 2D Canvas methods and trigonometric math. This makes it extremely lightweight compared to 3D frameworks.
Can I make it vertical?
The current implementation is vertical (mapping the loop to the Y-axis). You can swap the X and Y logic in the draw loop to make it a horizontally traveling helix.
Does it work on mobile?
Yes. The script includes a resize listener that automatically fits the canvas to the screen, providing a full-screen immersive experience on any device.