xxxxxxxxxx
60
let angle = 0;
let helixRadius = 100;
let helixHeight = 500; // Increased height for a longer helix
let numStrands = 2;
let numRungs = 15; // More rungs for a longer helix
function setup() {
createCanvas(800, 800, WEBGL);
}
function draw() {
background(255, 213, 182);
// Set the stroke weight for thicker strands
strokeWeight(4); // Adjust this value to make the strands thicker
// Rotate the entire scene around the Y-axis for a 360-degree rotation effect
rotateY(angle); // This makes the helix rotate left to right
// Draw the DNA helix
for (let i = 0; i < numRungs; i++) {
let t = map(i, 0, numRungs - 1, 0, TWO_PI);
// Create positions for the left and right strands (on the Z-axis)
let x1 = helixRadius * cos(t);
let y1 = map(i, 0, numRungs - 1, -helixHeight / 2, helixHeight / 2); // Keep the helix vertical
let z1 = helixRadius * sin(t);
let x2 = helixRadius * cos(t + PI); // Second strand offset by PI (opposite direction)
let y2 = y1;
let z2 = helixRadius * sin(t + PI);
// Draw the strands (lines between the two strands)
if (i < numRungs - 1) {
let nextT = map(i + 1, 0, numRungs - 1, 0, TWO_PI);
let nextX1 = helixRadius * cos(nextT);
let nextY1 = map(i + 1, 0, numRungs - 1, -helixHeight / 2, helixHeight / 2);
let nextZ1 = helixRadius * sin(nextT);
let nextX2 = helixRadius * cos(nextT + PI);
let nextY2 = nextY1;
let nextZ2 = helixRadius * sin(nextT + PI);
// Draw the strands connecting consecutive points
line(x1, y1, z1, nextX1, nextY1, nextZ1);
line(x2, y2, z2, nextX2, nextY2, nextZ2);
// Draw the "ladders" (connecting rungs between the two strands)
line(x1, y1, z1, x2, y2, z2); // Rung between the two strands
}
}
// Increase the angle to rotate 360 degrees over time
angle += 0.02; // Adjust this value for the speed of rotation
if (angle > TWO_PI) {
angle = 0; // Reset angle to loop through 360 degrees
}
}