xxxxxxxxxx
50
let spirals = 5; // Number of complete spirals
let pointsPerSpiral = 30; // Points per spiral
let maxRadius = 150; // Maximum radius
let height = 400; // Height of the spiral
let totalPoints = spirals * pointsPerSpiral;
function setup() {
createCanvas(600, 700, WEBGL);
angleMode(DEGREES);
}
function draw() {
background(0);
rotateX(60); // Rotate the view for better perspective
// Lighting setup for 3D visualization
ambientLight(50);
pointLight(255, 255, 255, 0, 0, 300);
pointLight(100, 100, 255, -300, 300, 200);
// Draw the triangle spiral
noFill();
beginShape(TRIANGLE_STRIP);
for (let i = 0; i <= totalPoints; i++) {
let angle = map(i, 0, totalPoints, 0, 360 * spirals);
let rad = map(i, 0, totalPoints, 20, maxRadius);
let z = map(i, 0, totalPoints, -height / 2, height / 2);
let x = rad * cos(angle);
let y = rad * sin(angle);
// Dynamic color mapping
let r = map(sin(frameCount + z), -1, 1, 100, 200);
let g = map(cos(frameCount + z), -1, 1, 100, 200);
let b = map(sin(frameCount + z), -1, 1, 200, 100);
stroke(r, g, b);
vertex(x, y, z);
// Calculate the next vertex for the triangle strip
let nextRad = rad * 0.95;
let nextZ = z + height / totalPoints;
let nextX = nextRad * cos(angle + 2);
let nextY = nextRad * sin(angle + 2);
vertex(nextX, nextY, nextZ);
}
endShape();
}