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 /*******************create the constructors********************/ PixelRect(){ //Constructor I setPosition(getPositionX(), getPositionY()); setColor(color((int)random(0,255))); } PixelRect(int x, int y, int ss, color q){ //Constructor II setPosition(x,y); setColor(q); sidesize= ss; } /*****************methods concering the position of a pixel*******************/ void setPosition(int px, int py){ posX = px; posY = py; } int getPositionX(){ return posX; } int getPositionY(){ return posY; } /*****************methods concering the color of a pixel*******************/ void setColor (color newColor){ pixelcolor = newColor; } color getColor(){ return pixelcolor; } /*********************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 color of a pixelrect is compared with 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].pixelcolor < pixrect[i][j+1].pixelcolor){ int tempcolor = pixrect[i][j+1].pixelcolor; pixrect[i][j+1].pixelcolor = pixrect[i][j].pixelcolor; pixrect[i][j].pixelcolor = tempcolor; } } } }