Disco Ball
Wife needed a black and white PNG/SVG of a Disco Ball. Yep.
1function setup() {
2 let c = createCanvas(1024, 1024, WEBGL);
3 noStroke();
4 noLoop();
5
6 //background(0);
7 rotateY(HALF_PI * 0.1);
8 rotateX(HALF_PI);
9 emissiveMaterial(0);
10 sphere(399,24,24);
11 noStroke()
12
13 const bands = 24;
14 const maxFacets = 48;
15 const minFacets = 0;
16 const radius = 400;
17
18 emissiveMaterial(255);
19
20 for (let j = 0; j <= bands; j++) {
21 let normalizedBand = (j / bands) * PI - HALF_PI;
22 let interpolatedValue = sin(normalizedBand + HALF_PI);
23
24 let facets = floor(interpolatedValue * (maxFacets - minFacets) + minFacets);
25 print(j, normalizedBand, interpolatedValue, facets)
26
27 for (let i = 0; i < facets; i++) {
28 let lon = (i / facets) * TWO_PI;
29 let lat = (j / bands) * PI - HALF_PI;
30
31 let x = radius * cos(lat) * cos(lon);
32 let y = radius * cos(lat) * sin(lon);
33 let z = radius * sin(lat);
34
35 push();
36 translate(x, y, z);
37 rotateZ(lon);
38 rotateY(HALF_PI - lat);
39 plane(50,50);
40 pop();
41 }
42 }
43
44saveCanvas(c, 'myCanvas', 'png');
45
46
47}