MouseX with cursor

<void setup(){
size(600,800);
background(0,0,80);

}
void draw() {
float x = mouseX;

background(0,0,80);
fill(150,100,0);
rect(width/2,height/2,150,150);
if(x<300){
fill(0,0,80);
rect(x,400,150,150);
} else if (x>300) {
fill(0,0,80);
ellipse(x,400,150,150);
}
else {
fill(150,100,0);
}
ellipse(300,400,150,150);
}

button * homework policy *
[I want to create two rect,one will be like another’s shadow One is orange and one is black Black will cover orange so I put mouseX but what I’m struggling is that I want the black will be on left if my cusor is right Can someone help me?]
(/t/2147)

not fully clear, but here is an example


void setup() {
  size(600, 800);
  background(0, 0, 80);
}

void draw() {
  background(0, 0, 80);

  //Left rec
  if (mouseX<300) {
    fill(150, 100, 0);
  } else {
    fill(0, 0, 0);
  }
  rect(33, 400, 150, 150);

  //Right rec
  if (mouseX>300) {
    fill(255);
  } else {
    fill(0, 0, 0);
  }
  rect(width/2, height/2, 150, 150);
  //
}
//
1 Like

Thanks for the answer and sorry for not being not so clear in question.
According to the homework, the rectangle must be in center. Implement a
“shadow” for the black rectangle that moves based on the mouse cursor position.
Note that the side of the rectangle closer to the cursor should
remain orange, while the side in shadow should be the same color as the background.

I see

You need to draw shadow first then rectangle I guess

1 Like

Hello,

Lots of resources here:

Take a look here:

:)

1 Like

the orange one doesn’t appear when cursor is on middle:

could you please make this <=

1 Like

Thanks
Finally I got it

1 Like

Thanks TwT
I made the distance +and - and
Finally got it ^=^

Would look nicer when shadow moves continually

Try

x = map(mouseX, 0, width, -60,60);