PImage img; int pixelSize = 3; int pixelThreshold = 150; void setup() { // load image img = loadImage("lincoln.png"); // set window size size(img.width, img.height); } void draw() { image(img, 0, 0); // iterate through whole picture for (int x = 0; x < img.width; x = x + (int)img.width*pixelSize/100) { for (int y = 0; y < img.height; y = y + (int)img.width*pixelSize/100) { color col = get(x,y); // get greyscale of colored pixel int grayScale = (int)((red(col) + green(col) + blue(col)) / 3.0) ; // iterate through pixel groups for (int sx = 0; sx < img.width*pixelSize/100; sx = sx + 1) { for (int sy = 0; sy < img.width*pixelSize/100; sy = sy + 1) { // check gray scale and set white or black if (grayScale > pixelThreshold) { set(x+sx, y+sy, color(255)); } else { set(x+sx, y+sy, color(0)); } } } } } } void keyPressed() { if (keyCode == DOWN) { if (pixelSize > 1) { pixelSize = pixelSize-1; } else { pixelSize = 1; } } if (keyCode == UP) { if (pixelSize <= img.width-1) { pixelSize = pixelSize+1; } else { pixelSize = img.width; } } if (keyCode == LEFT) { if (pixelThreshold <= 255) { pixelThreshold = pixelThreshold+1; System.out.println(pixelThreshold); } else { pixelSize = 255; } } if (keyCode == RIGHT) { if (pixelThreshold >= 0) { pixelThreshold = pixelThreshold-1; System.out.println(pixelThreshold); } else { pixelSize = 0; } } }