Running a circle pattern inside a given shape

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

Like this:

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

3 Likes