Created
February 10, 2014 01:52
-
-
Save ohmygodwin/8909018 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 = new sqProp[400]; | |
void setup() { | |
size(800, 600); | |
reset(); | |
background(255); | |
for (int col = 0; col < cols; col++) { | |
int x = col*40; | |
for (int row = 0; row < rows; row++) { | |
int y = row*40; | |
square[squareCount] = new sqProp(x, y); | |
squareCount++; | |
} | |
} | |
} | |
void draw() { | |
int f = 0; | |
while (f < squareCount) { | |
square[f].show(); | |
f++; | |
} | |
} | |
void reset() { | |
cols = width/cell; | |
rows = height/cell; | |
} | |
void mouseMoved() { | |
//for (int count = 0; count <= 373; count++) { | |
for (int col = 0; col < cols; col++) { | |
int x = col*40; | |
for (int row = 0; row < rows; row++) { | |
int y = col*40; | |
if ((mouseX > x) && (mouseX < x + 40) && (mouseY > y) && (mouseY < y + 40)) { | |
square[count].updateColor(30, 40, 50); | |
count++; | |
if (count > 373) { | |
count = 0; | |
} | |
println(count, x, mouseX, y, mouseY); | |
} | |
} | |
//} | |
} | |
} | |
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, sqY, 40, 40); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment