class PixelRect { int sidesize; // the variable for the size of the pixels int posX; // the variable for the X position of the pixels int posY; // the variable for the Y position of the pixels color pixelcolor; // the variable for the color of the pixels color graycolor; // the variable for the gray value of the color of the pixels /****************************Constructor********************************/ PixelRect(int x, int y, int ss, color q){ setPosition(x,y); setColor(q); sidesize = ss; } /****************************method - set Position**************************/ void setPosition(int px, int py){ posX = px; posY = py; } /*************************method - return PositionX**********************/ int getPositionX(){ return posX; } /**************************method - return PositionX***********************/ int getPositionY(){ return posY; } /*****************method - to set the color of a pixel*******************/ void setColor (color newColor){ // newColor = pic.pixels[] pixelcolor = newColor; } /***************method - to return the color of a pixel*****************/ color getColor(){ return pixelcolor; // pic.pixels[] = pixelcolor } /***************method - to return the grayscale value of a pixel*****************/ int calcBrightness(color oldColor){ float r = red(oldColor); float g = green(oldColor); float b = blue(oldColor); int grayValue = round (0.299*(r) + 0.587*(g) + 0.114*(b) ); return grayValue; } /*********************method to draw the pixelrects***********************/ void drawPixelRect(){ fill(getColor()); rect(getPositionX()*sidesize, getPositionY()*sidesize, sidesize, sidesize); } /**************method to swap the colors of the pixelrects*****************/ // in this method the brightness of a color of a pixelrect is compared with the brigthness of the color of the // next pixelrect beneath it, and, if it is darker, then they swap colors void swapColors(){ int i = getPositionX(); int j = getPositionY(); if(j < pixrect[0].length-1){ if( pixrect[i][j].calcBrightness(pixrect[i][j].getColor()) < pixrect[i][j+1].calcBrightness(pixrect[i][j+1].getColor())){ int tempcolor = pixrect[i][j+1].pixelcolor; pixrect[i][j+1].pixelcolor = pixrect[i][j].pixelcolor; pixrect[i][j].pixelcolor = tempcolor; } } } }