check if cursor is within the area for many objects
in
Programming Questions
•
3 months ago
hi, noob-ish situation
i want to check if cursor is within ellipse and mouse pressed, then do something
easy to do for one instance using dist
but i cant figure out how to make it as class and then
choose different sizes of ellipse, locations and colours
right now touching one ellipse affects all ellipses
can anyone help me?
i want to check if cursor is within ellipse and mouse pressed, then do something
easy to do for one instance using dist
but i cant figure out how to make it as class and then
choose different sizes of ellipse, locations and colours
right now touching one ellipse affects all ellipses
can anyone help me?
- test t, u;
- void setup() {
- size(240, 120);
- smooth();
- ellipseMode(RADIUS);
- t= new test(50, 50);
- u= new test(200, 100);
- }
- void draw() {
- background(204);
- t.run();
- u.run();
- }
- class test {
- int x, y;
- int radius = 12;
- float d = dist(mouseX, mouseY, x, y);
- test(int _x, int _y) {
- x=_x;
- y=_y;
- }
- void run() {
- display();
- check();
- }
- void check () {
- if (d < radius && mousePressed) {
- fill(0);
- }
- else {
- fill(255);
- }
- }
- void display() {
- ellipse(x, y, radius, radius);
- }
- }
1