-
-
Save pstoica/8909410 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int cell = 35; // Individual cell size | |
int cols, rows; // Total number of columns and rows | |
float valueR = 50.0; | |
float valueG = 50.0; | |
float valueB = 50.0; | |
int count = 0; | |
int squareCount = 0; | |
sqProp[][] square; | |
void setup() { | |
size(800, 600); | |
reset(); | |
background(255); | |
} | |
void draw() { | |
for (int col = 0; col < cols; col++) { | |
for (int row = 0; row < rows; row++) { | |
square[col][row].show(); | |
} | |
} | |
} | |
void reset() { | |
cols = width/cell; | |
rows = height/cell; | |
square = new sqProp[cols][rows]; | |
for (int col = 0; col < cols; col++) { | |
int x = col*cell; | |
for (int row = 0; row < rows; row++) { | |
int y = row*cell; | |
println(x + " " + y); | |
square[col][row] = new sqProp(x, y); | |
} | |
} | |
} | |
void mouseMoved() { | |
int col = ((int) Math.floor(mouseX / cell)); | |
int row = ((int) Math.floor(mouseY / cell)); | |
square[col][row].updateColor(30, 40, 50); | |
} | |
class sqProp { | |
float sqRed = 50, sqGreen = 50, sqBlue = 50; | |
int sqX, sqY; | |
sqProp(int squX, int squY) { | |
sqX = squX; | |
sqY = squY; | |
} | |
void updateColor(float r2, float g2, float b2) { | |
sqRed += r2; | |
sqGreen += g2; | |
sqBlue += b2; | |
} | |
void show() { | |
strokeWeight(.5); | |
stroke(255); | |
fill(sqRed, sqGreen, sqBlue, 15); | |
rectMode(CENTER); | |
rect(sqX + (cell / 2), sqY + (cell / 2), cell, cell); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment