/*JOT Assignment 3 - 01 - #200024742 I have created an interactive pixellated mosaic from an uploaded image... ...press the mouse many times to reduce the size of the pixel blocks... ...until you see a regular image... ...this gradual de-pixellation mirrors the painting process... of the painter, Chuck Close. "Close To The Edge" - A tribute to Chuck Close. */ //This is the subclass img that extends the PImage class... //...PImage's class does not need to be declared since it is already a subclass... //...extending from the Object class. Chuxellation img; int blockSize=100; void setup() { size (400, 392); smooth(); img= new Chuxellation("Film_ChuckClose.jpg"); //from http://www.showbusinessweekly.com/images/468/Film_ChuckClose.jpg image(img, 0, 0); } void mousePressed(){ if (mouseX>=0 && mouseX<=400 && mouseY >=0 &&mouseY<=392){ blockSize = abs(blockSize- 1); } if (mouseX>=295 && mouseX<=315 && mouseY >=440 && mouseY<=460){ blockSize = blockSize+1; if (blockSize >= 40){ blockSize = blockSize; } } } /*I made this custom strokeControl() function to control the strokeWeight to prevent the block size from disappearing while allowing for nice filled edges to occur in the beginning... This still allows us to view the original image... at the end...*/ void strokeControl() { blockSize= blockSize; if (blockSize >=20 && blockSize <=100) { strokeWeight(10); } else { noStroke(); } } void draw(){ img.mosaic(blockSize); img.updatePixels(); strokeControl(); } class Chuxellation extends PImage{ //sublass for PImage Chuxellation(){ super(); //inheriting everything from the parent PImage class. } Chuxellation (String fileName){ PImage X = loadImage(fileName); this.width = X.width; this.height = X.height; this.pixels = X.pixels; } color closeColor (int x, int y){ x = constrain(x,10,width-10); y = constrain (y,10,height-10); return pixels[y*width+x]; } void mosaic(int blockSize){ if (blockSize <=1){ noFill(); blockSize= 1; } if(blockSize*8 > this.width){ noFill(); } for (int i =5; i<= this.width; i+= blockSize){ for (int j = 5; j<=this.height; j+=blockSize){ fill(closeColor(i + blockSize/2, j+blockSize/2)); rect(i,j,blockSize, blockSize); } } } }