xxxxxxxxxx
98
let angle = 0;
let helixRadius = 100;
let helixHeight = 500;
let numRungs = 15;
let sparkles = [];
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
noStroke();
for (let i = 0; i < numRungs; i++) {
let t = map(i, 0, numRungs - 1, 0, TWO_PI);
let y = map(i, 0, numRungs - 1, -helixHeight / 2, helixHeight / 2);
let x1 = helixRadius * cos(t);
let z1 = helixRadius * sin(t);
let x2 = helixRadius * cos(t + PI);
let z2 = helixRadius * sin(t + PI);
for (let j = 0; j < 3; j++) {
sparkles.push(createSparkle(x1, y + random(-5, 5), z1));
sparkles.push(createSparkle(x2, y + random(-5, 5), z2));
}
for (let j = 0; j < 2; j++) {
let rx = lerp(x1, x2, random(0.3, 0.7));
let rz = lerp(z1, z2, random(0.3, 0.7));
sparkles.push(createSparkle(rx, y, rz));
}
}
}
function draw() {
background(0);
// Rotating light for shimmer effect
let lightX = 300 * cos(frameCount * 0.01);
let lightZ = 300 * sin(frameCount * 0.01);
pointLight(255, 255, 255, lightX, -200, lightZ);
ambientLight(100);
rotateY(angle);
for (let i = 0; i < numRungs - 1; i++) {
let t = map(i, 0, numRungs - 1, 0, TWO_PI);
let nextT = map(i + 1, 0, numRungs - 1, 0, TWO_PI);
let y1 = map(i, 0, numRungs - 1, -helixHeight / 2, helixHeight / 2);
let y2 = map(i + 1, 0, numRungs - 1, -helixHeight / 2, helixHeight / 2);
let x1 = helixRadius * cos(t), z1 = helixRadius * sin(t);
let x2 = helixRadius * cos(t + PI), z2 = helixRadius * sin(t + PI);
let nextX1 = helixRadius * cos(nextT), nextZ1 = helixRadius * sin(nextT);
let nextX2 = helixRadius * cos(nextT + PI), nextZ2 = helixRadius * sin(nextT + PI);
drawHelixStrand(x1, y1, z1, nextX1, y2, nextZ1);
drawHelixStrand(x2, y1, z2, nextX2, y2, nextZ2);
drawRung(x1, y1, z1, x2, y1, z2);
}
for (let p of sparkles) {
push();
translate(p.x, p.y, p.z);
let sparkleBrightness = p.brightness + sin(frameCount * p.flickerSpeed) * 100;
emissiveMaterial(255, 255, 255, sparkleBrightness);
sphere(p.size);
pop();
}
angle += 0.02;
}
function createSparkle(x, y, z) {
return {
x, y, z,
brightness: random(150, 255),
size: random(2, 6),
flickerSpeed: random(0.02, 0.08)
};
}
function drawHelixStrand(x1, y1, z1, x2, y2, z2) {
push();
translate((x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2);
specularMaterial(255);
shininess(200);
cylinder(3, dist(x1, y1, z1, x2, y2, z2));
pop();
}
function drawRung(x1, y1, z1, x2, y2, z2) {
push();
translate((x1 + x2) / 2, y1, (z1 + z2) / 2);
specularMaterial(255);
shininess(200);
box(10, 2, 2);
pop();
}