Hello!! I have made a figure with a for loop inside a class, and I want to make each element made in the loop have different colors. Here is my code. Any help would be great…
float x;
float y;
Madre c;
//MadreLider d;
PGraphics lider, trazo;
String estado = "";
//paleta p;
color aColor = color( random(255),random(255),random(255) );
void setup() {
//size (1000,600);
fullScreen();
//background(200, 50, 255);
trazo = createGraphics(width, height);
lider = createGraphics(width, height);
//d = new MadreLider();
c = new Madre();
estado = "recto";
}
void draw() {
noStroke();
//rect(0, 0, width, height);
//translate(500,700);
//lider.beginDraw();
//d.actualizar();
//d.dibujar();
c.dibujar(trazo, color(aColor));
lider.beginDraw();
lider.clear();
lider.endDraw();
c.dibujar(lider, color(0,255,0));
image(trazo, 0, 0);
image(lider, 0, 0);
c.mover();
c.dibujar(trazo, color(aColor));
lider.beginDraw();
lider.clear();
lider.endDraw();
c.dibujar(lider, color(255, 0, 0));
}
class Madre {
//atributos
float x, y;
float diametro;
color colorRelleno;
float velocidad;
float rotacion;
float r;
int b = int( random(0,4) );
int a = int( random(1,4) );
String[] colores = {};
color aColor = (int) random(#000000);
//constructor
Madre() {
x = width / 2;
y = height + 200;
diametro = 70;
colorRelleno = (50);
r = random (0,5);
velocidad = 1;
//int(random(a, b));
//int a = (int) random(80, 420), b = (int) random(20, 495);
;
}
void mover()
{
y -= velocidad;
rotacion = 0.03*(frameCount);
}
//métodos
void dibujar(PGraphics capa, color miColor) {
capa.beginDraw();
float modulo = 40+20*cos(frameCount/14.0);
capa.pushStyle();
capa.noStroke();
capa.fill(miColor);
capa.pushMatrix();
capa.translate(x, y);
//se mueve para arriba
//translate(x,y--);
capa.rotate(rotacion);
//rotate(radians(frameCount));
for (int i = -b; i <= b; i++) {
for (int j = -a; j <= a; j++) {
//capa[i].dibujar;
capa.ellipse(i*modulo, j*modulo, 20, 20);
}
}
capa.popMatrix();
capa.popStyle();
capa.endDraw();
}
}