Hi everyone, I need a hand, on how I can make my static rectangles () inside my moving rectangles () change color:
I have three squares: static green, purple and orange
I have three moving rectangles (): yellow, red and blue
I have to make sure that by moving the squares (one at a time) my moving rectangles () take their color:
if I move the purple square on the moving yellow rectangle (), it turns purple while if I move it on the red rectangle () it does not make me do it because it is wrong.
if I move the orange square on the moving blue rectangle () my rectangle (blue) becomes orange ect.
color red = #FF0004;
color yellow = #F2F700;
color blue = #0A30FF;
color black = #000000;
color white = #FFFFFF;
int w = 600;
int h = 600;
int min = 0+100;
int max = w-100;
float x_move = random (min, max);
float x_moveNext = random(min, max);
float y_move1 = random (min, max);
float y_moveNext1 = random (min, max);
float y_move2 = random (min, max);
float y_moveNext2 = random (min, max);
float velocitaX = 1.5;
float velocitaY = 1.5;
void settings() {
size(w, h);
}
void setup() {
background(black);
frameRate(50);
surface.setTitle("Mondrian");
}
void draw() {
background(black);
disegnaX();
disegnaY();
quadrati();
}
void disegnaX() {
if (x_move < x_moveNext) {
x_move += velocitaX;
if (x_move >= x_moveNext) {
x_move = x_moveNext;
x_moveNext = random (min, max);
}
}
if (x_move > x_moveNext) {
x_move -= velocitaX;
if (x_move <= x_moveNext) {
x_move = x_moveNext;
x_moveNext = random(min, max);
}
}
noStroke();
fill(red);
rect(0, y_move1+100, x_move, h);
fill(blue);
rect(x_move, y_move2, w, h);
fill(yellow);
rect(0, 0, x_move, y_move1+100);
stroke(white);
strokeWeight(13);
line(x_move, 0, x_move, h); //mezzeria
}
void disegnaY() {
if (y_move1 < y_moveNext1) {
y_move1 += velocitaY;
if (y_move1 >= y_moveNext1) {
y_move1 = y_moveNext1;
y_moveNext1 = random (min, max);
}
}
if (y_move1 > y_moveNext1) {
y_move1 -= velocitaY;
if (y_move1 <= y_moveNext1) {
y_move1 = y_moveNext1;
y_moveNext1 = random(min, max);
}
}
if (y_move2 < y_moveNext2) {
y_move2 += velocitaY;
if (y_move2 >= y_moveNext2) {
y_move2 = y_moveNext2;
y_moveNext2 = random (min, max);
}
}
if (y_move2 > y_moveNext2) {
y_move2 -= velocitaY;
if (y_move2 <= y_moveNext2) {
y_move2 = y_moveNext2;
y_moveNext2 = random(min, max);
}
}
stroke(white);
strokeWeight(13);
line(x_move, y_move2, w, y_move2); //blu
line(0, y_move1+100, x_move, y_move1+100); //giallo rosso
}
color green = #08FF79;
color purple = #E108FF;
color orange = #FFA908;
void quadrati() {
fill(black);
noStroke();
rect(0, 0, 600, 120);
fill (green);
noStroke();
rect (160, 20, 80, 80);
fill (purple);
noStroke();
rect (260, 20, 80, 80);
fill (orange);
noStroke();
rect (360, 20, 80, 80);
}
Thanks