Skip to content

Instantly share code, notes, and snippets.

@fiskurgit
Last active February 7, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiskurgit/2fabdc3bca625f11caf6 to your computer and use it in GitHub Desktop.
Save fiskurgit/2fabdc3bca625f11caf6 to your computer and use it in GitHub Desktop.
Processing.org - double helix.
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++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment