Last active
February 7, 2017 15:28
-
-
Save fiskurgit/2fabdc3bca625f11caf6 to your computer and use it in GitHub Desktop.
Processing.org - double helix.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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