xxxxxxxxxx
// engineer: jWilliamDunn, 2024.1101
/*
When an annulus is split into several pieces along the radials,
the resulting segments are commonly referred to as annular sectors.
Each sector is formed by two radii extending from the center of the
annulus to the inner and outer circles, creating a wedge-shaped
piece of the annular region.
(like a piece of pie with the point bitten off)
quad() chosen over annulus() due to performance
*/
p5.disableFriendlyErrors = true;
var angle=Math.PI/4, t=0, u=100;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
pixelDensity(2);
setAttributes('antialias', true);
createEasyCam();
colorMode(HSB);
perspective(PI/3, width/height, 1, 8000);
document.oncontextmenu = () => false;
strokeWeight(1);
}
function draw() {
background(0,0,0);
t+=0.0005;
u+=0.01;
noStroke();
let n=1;
rotate(t);
for(let i=0; i<240; i++) { //240
n=Math.floor(noise(t,i)*50);
fill(240+n,100,70);
if(mouseIsPressed)
annulus(80,200+n, TAU*0.003,1); //200+50*n //540ms/60iter
//rect(80,0, 200,2); //264ms/60iter
//beginShape(); vertex(80,0); vertex(80+200,0); vertex(80+200,4); vertex(80,2); endShape(CLOSE);//539ms/60iter
//triangle(80,0, 280,0, 280,4); //262ms/60iter
else quad(80,0, 200+n,0, 200+n,4, 80,1.5); //266ms/60iter 640ms/240iter
//anomaly: when noise() is added back into the loop, the quad() perf suffers which does not happen with annulus()
rotate(TAU/240);
}
}
// increasing loop from 60 to 240 proportionally increases script time from 5% to 15%
// jWilliamDunn 20200803 handle fill and stroke separately
function annulus(inner, outer, angle, segs) {
if(segs===undefined)segs=20;
//if(segs<5)segs=5;
if(this._renderer._doStroke){
push();
noFill();
beginShape();
for(let i=0; i<=segs; i++)
vertex(outer*Math.cos(angle*i/segs), outer*Math.sin(angle*i/segs));
for(let i=segs; i>=0; i--)
vertex(inner*Math.cos(angle*i/segs), inner*Math.sin(angle*i/segs));
endShape(CLOSE);
pop();
}
if(this._renderer._doFill){
push();
noStroke();
beginShape(TRIANGLE_STRIP);
for(let i=0; i<=segs; i++){
vertex(outer*Math.cos(angle*i/segs), outer*Math.sin(angle*i/segs));
vertex(inner*Math.cos(angle*i/segs), inner*Math.sin(angle*i/segs));
}
endShape();
pop();
}
}