xxxxxxxxxx
51
let angle = 0;
let helixRadius = 100;
let numSegments = 100;
let angleIncrement = 0.2;
let segmentLength = 25;
let speedIncrement = 0.01; // The amount by which the speed will be increased or decreased
let speed = 0.05; // Initial speed of rotation
function setup() {
createCanvas(400, 700);
angleMode(RADIANS);
noFill();
background(0);
}
function draw() {
background(0, 0, 0, 80);
translate(width / 2, 0);
if (mouseIsPressed && mouseY > 0 && mouseY < height) {
helixRadius = map(mouseX, 0, width, 50, 150);
segmentLength = map(mouseY, 0, height, 10, 40);
}
for (let i = 0; i < numSegments; i++) {
let angle1 = i * angleIncrement + angle;
let angle2 = angle1 + PI; // 180 degrees phase shift
let x1 = helixRadius * sin(angle1);
let y1 = i * segmentLength;
let x2 = helixRadius * sin(angle2);
let y2 = (i + 1) * segmentLength;
if (x1 < width / 2) {
ellipse(x1, y1, 10, 10);
ellipse(x2, y2, 10, 10);
stroke(random(150, 175), random(150, 255), random(150, 200));
line(x1, y1, x2, y2);
}
}
// Rotate the entire helix
angle += speed;
}
function keyPressed() {
if (keyCode === UP_ARROW) {
speed += speedIncrement; // Increase the speed
} else if (keyCode === DOWN_ARROW) {
speed = max(0, speed - speedIncrement); // Decrease the speed, but not less than 0
}
}