# Moving ellipse stop on black color

**URL:** <https://discourse.processing.org/t/moving-ellipse-stop-on-black-color/6572>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 13, 2018, 4:09pm UTC](https://discourse.processing.org/t/moving-ellipse-stop-on-black-color/6572 "2018-12-13T16:09:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legate](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Legate](https://discourse.processing.org/u/Legate)\
**Post date:** [December 13, 2018, 4:09pm UTC](https://discourse.processing.org/t/moving-ellipse-stop-on-black-color/6572/1 "2018-12-13T16:09:06Z")

</div>

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.

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![bryan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bryan/32/2538_2.png) [@bryan](https://discourse.processing.org/u/bryan)\
**Post date:** [December 13, 2018, 5:09pm UTC](https://discourse.processing.org/t/moving-ellipse-stop-on-black-color/6572/2 "2018-12-13T17:09:02Z")

</div>

to access to each pixel color of your image, check the description of the PImage data structure ([https://processing.org/reference/PImage.html](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.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [December 17, 2018, 6:14pm UTC](https://discourse.processing.org/t/moving-ellipse-stop-on-black-color/6572/3 "2018-12-17T18:14:19Z")

</div>

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

> **[get() / Reference](https://processing.org/reference/get_.html)**
>
> Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. Use the x and y parameters to get the value of one pixel. Get a…

> [@Legate](#):
>
> We need to create ellipse/dot that automatically stops if it’s registers black color in it’s way.

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).

> **[Collision Detection](http://www.jeffreythompson.org/collision-detection/line-circle.php)**
>
> An online book about collision detection using Processing.

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