xxxxxxxxxx
52
let radius = 200;
let total = 25;
let mesh = [];
let angleX = 0;
let angleY = 0;
function setup() {
createCanvas(600, 600, WEBGL);
colorMode(HSB);
strokeWeight(1);
}
function draw() {
background(20);
rotateX(angleX);
rotateY(angleY);
for (let i = 0; i < total + 1; i++) {
mesh[i] = [];
let lat = map(i, 0, total, 0, PI);
for (let j = 0; j < total + 1; j++) {
let lon = map(j, 0, total, 0, TWO_PI);
let x = radius * sin(lat) * cos(lon);
let y = radius * sin(lat) * sin(lon);
let z = radius * cos(lat);
mesh[i][j] = createVector(x, y, z);
}
}
for (let i = 0; i < total; i++) {
let h = map(i, 0, total, 0, 360);
fill(h % 360, 100, 100);
stroke(0, 0, 100);
beginShape(TRIANGLE_STRIP);
for (let j = 0; j < total + 1; j++) {
let v1 = mesh[i][j];
vertex(v1.x, v1.y, v1.z);
let v2 = mesh[i + 1][j];
vertex(v2.x, v2.y, v2.z);
}
endShape();
}
angleX += 0.005;
angleY += 0.01;
}