Plot a circle in two planes and increment a third. Using Processing, draw a circle in 2D using the parametric equation (view the code running on OpenProcessing):

Screen Shot 2014-12-29 at 09.58.45


//Plotting a circle                                                                                        

int cx, cy;
int segmentCount = 100;
int step = 0;
float plotDiameter, plotRadius;

void setup(){
  size(500, 500);
  cx = width/2;
  cy = height/2;
  plotDiameter =  width * .75;
  plotRadius  = plotDiameter/2;
  frameRate(20);
  background(80);
  noStroke();
  fill(255);
}

void draw(){
  float theta = step * TWO_PI / segmentCount;
  float x = cx + cos(theta) * plotRadius;
  float y = cy + sin(theta) * plotRadius;
  ellipse(x, y, 10, 10);

  if(step == segmentCount){
    background(80);
    step = -1;
  }

  step++;
}

Now we have the maths to draw a circle all we need to do is to convert that sketch to 3D and change the height over time, add a second path and you have a double helix (view the code running on OpenProcessing):

Screen Shot 2014-12-29 at 09.57.41


int cx, cy;
int segmentCount = 70;
int stepHeight = 1000;
int step = 0;
float plotDiameter, plotRadius;

void setup(){
  size(500, 500, OPENGL);
  cx = width/2;
  cy = height/2;
  plotDiameter =  width * .75;
  plotRadius  = plotDiameter/2;
  frameRate(20);
  background(80);
  noStroke();
  fill(255);
  smooth();
}

void draw(){
  beginCamera();
  camera(width/2.0, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0);
  rotateX(-PI/1.5);
  endCamera();

  if(stepHeight == 30){
    //offscreen
    return;
  }

  float theta = step * TWO_PI / segmentCount;
  float x = cx + cos(theta) * plotRadius;
  float y = cy + sin(theta) * plotRadius;

  theta = (step + segmentCount/2) * TWO_PI / segmentCount;
  float x2 = cx + cos(theta) * plotRadius;
  float y2 = cy + sin(theta) * plotRadius;

  stepHeight = stepHeight - 5;

  pushMatrix();
  fill(255);
  translate(x2, y2, stepHeight);
  sphere(10);
  popMatrix();

  pushMatrix();
  fill(100);
  translate(x, y, stepHeight);
  sphere(10);
  popMatrix();

  if(step == segmentCount){
    step = -1;
  }

  step++;
}