ArrayList mCenters; int black = color(0); PImage source; void setup() { size(640, 480); mCenters = new ArrayList(); } void draw() { loadPixels(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float minDist = width * height; int minCol = -1; int count = mCenters.size(); for (int i = 0; i < count; i++) { VoronoiCenter c = (VoronoiCenter) mCenters.get(i); if (c != null) { float d = c.distance(x, y); if (d < minDist) { minDist = d; minCol = c.mColor; } } } pixels[(y*width) + x] = minCol; } } updatePixels(); source = get(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { color c = source.get(x,y); for (int i = -1; i<=1; i++){ for (int j = -1; j<=1; j++){ if (source.get(x+i,y+j)!=c){ pixels[(y*width) + x] = black; } } } } } updatePixels(); //filter(BLUR); noLoop(); } public void mousePressed(MouseEvent e) { if (mCenters.size()>20) mCenters.clear(); int col = color(random(255), random(255), random(255)); VoronoiCenter c = new VoronoiCenter(e.getX(), e.getY(), col, random( 0.5f, 1.25f) ); mCenters.add(c); redraw(); }