# Running a circle pattern inside a given shape

**URL:** <https://discourse.processing.org/t/running-a-circle-pattern-inside-a-given-shape/8108>\
**Category:** Coding Questions\
**Created:** [February 4, 2019, 4:47pm UTC](https://discourse.processing.org/t/running-a-circle-pattern-inside-a-given-shape/8108 "2019-02-04T16:47:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![companje](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/companje/32/2418_2.png) [@companje](https://discourse.processing.org/u/companje)\
**Post date:** [February 4, 2019, 8:37pm UTC](https://discourse.processing.org/t/running-a-circle-pattern-inside-a-given-shape/8108/2 "2019-02-04T20:37:33Z")

</div>

Hi TomMoto,

You can use the ‘get’ function to read the color of a pixel on the screen of the shape you draw on the screen. So what you can do is find the first non-white pixel from the left on the current line and start drawing circles there. Then on the next line search again. etc…

![fill-with-circles](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/ebad5033128cdb9d028e881399ffb06e97c71e16.gif)

Like this:

```auto
import processing.pdf.*;
PShape s;
int x = 0;
int y = 25;
int xsp = 25;

void setup () {
  size (600, 600);
  s = loadShape("test.svg");
  beginRecord(PDF, "test.pdf");
  background(255);
  smooth();
  noStroke();
  fill(0, 250);
  frameRate(5);
  shape(s, 0, 0, width, height);

  for (x=0; x<width; x++) { 
    if (get(x, y)!=-1) break; //exit loop on first non-white pixel and remember x value
  }
}

void draw () {
  ellipse (x + 15, y, 10, 10);
  fill (0, 255);

  x = x + xsp;
  if (x > width-28) {
    y += 30;
    for (x=0; x<width; x++) {
      if (get(x, y)!=-1) break; //exit loop on first non-white pixel and remember x value
    }
  }
}

void keyPressed() {
  if (key == 's') {
    endRecord();
    exit();
  }
}

```

Good luck!  
Rick

---

_[View the full topic](https://discourse.processing.org/t/running-a-circle-pattern-inside-a-given-shape/8108)._
