🧬

3D DNA Helix

A mesmerising 3D double helix made of glowing particle nodes, rotating endlessly in space using JavaScript math.

dnahelix3dparticlescanvas

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.02 increment in the draw() function.
  • Adjust Helix Width: Change the 80 multiplier in the x1 and x2 calculations.
  • Strand Colors: Modify the ctx.fillStyle values (currently #00f2fe and #4facfe).
  • Particle Density: Change the particles = 40 variable 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.

Related Animations

Built by

Lawanya Chaudhari - Software Developer

Lawanya Chaudhari

Software Developer

I'm a Software Developer specializing in Angular, JavaScript, and TypeScript. I have a strong passion for building performant, user-friendly applications and developer tools that enhance productivity.

Code is like humor. When you have to explain it, it’s bad.