Automatic color blending
in
Programming Questions
•
1 year ago
Hi! I found this picture the other day and I thought it'd be nice to do some Processing applet similar to that. I defined a class for a grid of circles, and assigned a color, number, diameter and speed of rotation to each instance. The problem I find is that the colors do not blend as in the pic, as I thought they would by using the alpha function. Any ideas? Thanks!
PD: I don't know if it's necessary, but I'll just leave the code here in case someone is interested.
- // cmyk! (16/02/12)
Malla[] capa;
int lado = 400;
int nc = 3; // número de capas
void setup() {
size(600, 600);
smooth();
noStroke();
capa = new Malla[nc];
capa[0] = new Malla(6, 40, 5, 255, 255, 0);
capa[1] = new Malla(6, 60, 3, 0, 255, 255);
capa[2] = new Malla(6, 50, -2, 255, 0, 255);
}
void draw() {
translate(300, 300);
background(230);
for (int i=0; i < capa.length; i++) {
capa[i].paso();
}
}
class Malla {
int n, d, v, r, g, b;
float angle = 0;
Malla(int N, int D, int V, int R, int G, int B) {
n = N; // número de círculos por lado
d = D; // diámetro
v = V; // velocidad
r = R; // color en RGB
g = G;
b = B;
}
void paso() {
angle += v*PI/1000;
if (angle > TWO_PI) {angle -= TWO_PI; }
fill(r, g, b, 140);
float dl = lado/(n-1);
pushMatrix();
rotate(angle);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
ellipse(-lado/2 + i*dl, -lado/2 + j*dl, d, d);
}
}
popMatrix();
}
}
1