Can you try generating concentric ellipses outlines and see if this works for your case? The trick would be to draw them with noFill
and only stroke()
set to the color at the level of transparency based on how close it is to the geometrical center of the ellipse. There is this previous attempt with circles:
https://forum.processing.org/one/topic/circle-gradient.html
My attempt below. There is some “ringing” but this would be a good start.
For the mask task, you need to use a separate PGraphics to draw your closed “irregular shape” outline with PShape and then apply it to your color sketch. If you have any issues, please share your attempt. Check this post in addition to the docs:
- https://forum.processing.org/two/discussion/23886/masking-a-shape-with-another-shape
- How to create a clipping mask that preserves transparency?
Kf
//REFERENCE: https://courses.lumenlearning.com/boundless-algebra/chapter/the-circle-and-the-ellipse/
void setup() {
size(800, 800);
background(200);
smooth(8);
noLoop();
}
void draw() {
background(200);
translate(width/2, height/2);
createGradient(0, 0, width/2,
color(225),
color(5));
}
void createGradient (float x,
float y,
float radius,
color c1,
color c2) {
//1=((x-h)/a)^2 +((y-k)/b)^2
//y = k + b * sqrt( 1-((x-h)/a)^2 ) where hk,k is the center of the ellipse
float a=radius;
float b=1.2*radius;
float cx=x; //Ellipse center
float cy=y; //Ellipse center
noFill();
strokeWeight(5); // 2 for Circle, 5 for Ellipse
for (int i=0; i<radius; i++) {
float ratio=i/radius;
color mainColor=lerpColor(c1, c2, ratio);
color gradc=color(red(mainColor), green(mainColor), blue(mainColor), 2*ratio*255);
stroke(gradc);
//circle(cx, cy, i*2); //Use strokeWeight(2);
ellipse(cx,cy,i*2,i*2*1.2); //Use strokeWeight(5);
}
// adds smooth edge
// hack anti-aliasing
noFill();
stroke(150);
strokeWeight(2);
ellipse(x, y, width, width*1.2); //Outline border
}