Maybe this doesn’t help much, as it requires learning a new language (GLSL), but I couldn’t help myself
Instead of adding lots of vertices, this creates a rainbow-gradient shader. It’s rendered around the specified center and with a given radius (gradient center and radius are passed to the shader using .set()
.
Then you can draw any shapes you want (circles, squares or something else) and it will be painted with that gradient.
PShader gradient;
void setup() {
size(800, 800, P2D);
gradient = new PShader(this, new String[] {
"uniform mat4 transform; attribute vec4 position;",
"void main() { gl_Position = transform * position; }"
}, new String[] {
"uniform vec2 center;",
"uniform float radius;",
"void main() {",
" vec2 diff = gl_FragCoord.xy - center;",
" float d = clamp(length(diff) / radius, 0.0, 1.0);",
" float a = atan(diff.y, diff.x);",
" float r = sin(a) * 0.5 + 0.5;",
" float g = sin(a + 2.09) * 0.5 + 0.5;",
" float b = sin(a + 4.19) * 0.5 + 0.5;",
" gl_FragColor = vec4(r*d, g*d, b*d, 1.0);",
"}"
});
shader(gradient);
hint(DISABLE_OPTIMIZED_STROKE);
}
void gradientCircle(float x, float y, float diam) {
gradient.set("center", x, height-y);
gradient.set("radius", diam * 0.5);
circle(x, y, diam);
}
void draw() {
background(40);
for(int i=0; i<10; i++) {
float F = millis() * i * 0.0001;
gradientCircle(width*0.5 + 300*sin(i+F), height*0.5 + 300*cos(i+F), 300 - 20 * i);
}
}
I can try to explain how it works if anyone is curious.