2D Arrays with lerpColor
Diagonal Patterns using k
Example Code
//the following code is in the Procesing Setup function
//colorMode(HSB, 360, 100,100); //corresponds to the color selector
void setup(){
size(600, 600);
colorMode(HSB, 360, 100, 100);
int rows = 6;
int cols = 6;
int cellSize = width/cols;
int[][] intMatrix = new int[rows][cols];//2D array of ints
int xPos=0; //variables to control where rectangle is drawn
int yPos = 0;
color c1=color(157, 83, 56); //gradient color1
color c2 = color(258, 66, 96); //gradient color2
//nested for loops to calculate color gradient
//and to draw shape in grid-layout
for( int i=0; i< rows; i++){ //outer loop
for( int j=0; j< cols; j++){ //inner loop
int k = i + j; //calculate k using i,j index values
intMatrix[i][j]= k;
//calculate color and set fill
float kFraction = map( k, 0, (rows-1) + (cols-1),0.0, 1.0);
color c3 = lerpColor(c1, c2, kFraction);
fill( c3 ); ///use map? max of k is 10
//draw shape
rect(xPos, yPos, cellSize, cellSize);
//move to next column's x Position
xPos += cellSize; //increment for drawing the next column
} //end of inner loop (cols)
yPos +=cellSize; //move yPos for drawing next row
xPos = 0;
} //end of outer loop (rows)Grid Gradient using lerpColor( ) and map( )

Last updated