xxxxxxxxxx
28
function setup() {
createCanvas(400, 400, WEBGL);
}
function draw() {
background(200, 200, 0);
squircle(20, 30, 4); // (w,h,r)
}
//__________________________________________________________ SQUIRCLE
function squircle( wx, wy, r) {
beginShape();
stroke(0, 0, 200);
strokeWeight(5);
fill(0, 200, 0);
for (let t = 0; t < TWO_PI; t += TWO_PI / 160) { // 160 vertex points is too much
let x1 = pow(abs(cos(t)), 0.5) * r * wx * sign(cos(t));
let y1 = pow(abs(sin(t)), 0.5) * r * wy * sign(sin(t));
vertex(x1, y1);
}
endShape(CLOSE);
}
function sign(input) {
if (input < 0) return -1.0;
if (input > 0) return 1.0;
return 0.0;
}