New To Processing
              in 
             Share your Work 
              •  
              3 years ago    
            
 
           
             Hey guys! New to Processing and just implementing the basics.  This is actually for a project.  Nothing spectacular just, an array of colors that change in a loop.  The mouse when rolled over a coordinate in the array will reset the color to black.  Comments are welcome...go easy on me.  Processing is pretty neat.
            
            
            
            
[Moderator's note: moved from General Discussion to Exhibition]
 
           
 
            
           - /*
 *File: MyGrid
 *Author: Robert Castro
 *Date: 10/ 27 / 2010
 *Description: An array of changing colors.
 */
 Grid[][] myGrid;
 int cols = 15;
 int rows = 15;
 void setup() {
 size(cols * 20, rows * 20);
 myGrid = new Grid[cols][rows];
 for (int i = 0; i < cols; i++) {
 for (int j = 0; j < rows; j++) {
 myGrid[i][j] = new Grid(i*20, j*20, 20, 20, i+j, (int)random(0,255), (int)random(0,255));
 }
 }
 }
 void draw() {
 background(0);
 for (int i = 0; i < cols; i++) {
 for (int j = 0; j < rows; j++) {
 myGrid[i][j].changeColor();
 myGrid[i][j].display();
 }
 }
 
 int mx = mouseX/20;
 int my = mouseY/20;
 
 myGrid[mx][my].run();
 if ((mx + 1) < cols) {
 myGrid[mx + 1][my].run();
 }else {
 myGrid[0][my].run();
 }
 
 if ((mx - 1) >= 0) {
 myGrid[mx - 1][my].run();
 }else {
 myGrid[cols-1][my].run();
 }
 
 if ((my + 1) < rows) {
 myGrid[mx][my + 1].run();
 }else {
 myGrid[mx][0].run();
 }
 
 if ((my - 1) >= 0) {
 myGrid[mx][my - 1].run();
 }else {
 myGrid[mx][rows-1].run();
 }
 }
 class Grid {
 float x, y;
 float w, h;
 int col1;
 int col2;
 int col3;
 
 Grid(float tempx, float tempy, float tempw, float temph, int tempc1, int tempc2, int tempc3) {
 x = tempx;
 y = tempy;
 w = tempw;
 h = temph;
 col1 = tempc1;
 col2 = tempc2;
 col3 = tempc3;
 }
 
 void changeColor() {
 col1 += 1;
 col2 -= col1;
 col3 = col1 + col2;
 
 if (col1 > 255) {
 col1 = 0;
 }if (col2 < 0) {
 col2 = 255;
 }if (col3 > 255) {
 col3 = 0;
 }
 }
 
 void run() {
 col1 = 0;
 col2 = 0;
 col3 = 0;
 }
 
 void display() {
 color myColor = color(col1,col2, col3);
 stroke(255, 100);
 fill(myColor);
 rect(x,y,w,h);
 }
 }
[Moderator's note: moved from General Discussion to Exhibition]

 
 
           
 
             
 
            