Moving ellipse stop on black color

Hello friends,

i need help with my school programming problem. We need to create ellipse/dot that automatically stops if it’s registers black color in it’s way. And starts following it’s path. Something like robots find path trajectory using black color on ground. This is what i got. I’m stuck. All i have is a moving dot and circle in img. file in data (just a plain circle using paint). What do i need to do next? All help appreciated.

PImage img;
int a;
int b;
int x = 100;

void setup() {
  frameRate(60);
  size(800, 800);
  img = loadImage("circle.png");
}
void draw() {
  image(img, 0, 0);
  ellipse(x, 400, 10, 10); 
  fill(180, 0, 180);
  x = x + 1;
}
1 Like

to access to each pixel color of your image, check the description of the PImage data structure (https://processing.org/reference/PImage.html). In that way, you can access to the color of every pixel. Then, you’ll compare the x, and y position of your dot with his 8 pixel neighbors.

1 Like

Were you able to figure out how to sample the current color with get()?

Checking a moving dot for the color under it is easy – you just get(x, y).

Checking for a rectangle or a circle is harder – you could a) check points around the perimeter, or b) use a mask and check the contents of the mask, or c) define or black areas geometrically and use collision detection to check for touching (e.g. line-circle or point-circle collision detection).

Don’t try to do collision detection with a non-circle ellipse (one with different w and h). That is hard math.