xxxxxxxxxx
42
let angle = 0;
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(200);
orbitControl(1, 1, 0.01);
ambientLight(150);
noStroke();
ambientMaterial(250);
seashell(200, 360, 0.1, 0.15);
angle += 0.01;
}
function seashell(radius, totalPoints, a, b) {
beginShape(TRIANGLE_STRIP);
for (let i = 0; i <= totalPoints; i++) {
let lat = map(i, 0, totalPoints, 0, PI);
for (let j = 0; j <= totalPoints; j++) {
let lon = map(j, 0, totalPoints, 0, TWO_PI);
let r = radius * (1 - sin(lat) + cos(lon) * a + sin(angle + lat * 8) * b);
let x = r * sin(lat) * cos(lon);
let y = r * sin(lat) * sin(lon);
let z = r * cos(lat);
vertex(x, y, z);
lat += 0.01;
r = radius * (1 - sin(lat) + cos(lon) * a + sin(angle + lat * 8) * b);
x = r * sin(lat) * cos(lon);
y = r * sin(lat) * sin(lon);
z = r * cos(lat);
vertex(x, y, z);
}
}
endShape();
}