Yeah this is a little urgent...project due tomorrow and I'm about half done. Well heres my roadblock...I keep getting a null pointer error when I run this code...
Code:int sizeTEEE = 15;
int lotsOfColor = 15;
int numRects = 15;
boolean[] isOver = new boolean[sizeTEEE];
madRects[] a = new madRects[numRects];
color[] rectColor = new color[lotsOfColor];
int[] xpos, ypos, xSize, ySize;
void setup(){
colorMode(HSB, 360);
background( 182, (.52 * 360) , (.50 * 360) );
size(500, 700);
noStroke();
int[] xpos = {100, 179, 348, 65, 131, 275, 277, 26, 390, 175, 44, 365, 404, 164, 260};
int[] ypos = {112, 77, 91, 214, 334, 280, 360, 497, 500, 643, 331, 210, 349, 504, 506};
int[] xSize = {65, 130, 90, 90, 130, 70, 120, 120, 90, 70, 50, 90, 85, 85, 115};
int[] ySize = {40, 180, 90, 90, 150, 70, 120, 130, 90, 50, 120, 90, 90, 50, 115};
for(int i = 0; i < sizeTEEE; i++){ //Setting the default val of isOver to false
isOver[i] = false;
}
for(int i = 0; i < 10; i++){ //Setting all the blue colors = to one thing.
rectColor[i] = color( 182, (.45 * 360) , (.25 * 360) );
}
for(int i = 10; i < 15; i++){ //Setting all the white colors = to one thing.
rectColor[i] = color( 182, (.50 * 360) , (.95 * 360) );
}
for(int i = 0; i < 15; i++){
a[i] = new madRects(xpos[i], ypos[i], xSize[i], ySize[i]);
}
}
void draw(){
// update(mouseX, mouseY);
for(int i = 0; i < 10; i++){
if(isOver[i])
rectColor[i] = color(117, (.89 * 360), (.98 * 360) );
else
rectColor[i] = color( 182, (.45 * 360) , (.25 * 360) );
}
for(int i = 10; i < 15; i++){
if(isOver[i])
rectColor[i] = color(117, (.89 * 360), (.98 * 360) );
else
rectColor[i] = color( 182, (.50 * 360) , (.95 * 360) );
}
//Blooish ones
for(int i = 0; i < 10; i++){
fill(rectColor[i]);
a[i].displayRect();
}
for(int i = 10; i < 15; i++){
fill(rectColor[i]);
a[i].displayRect();
}
update(mouseX, mouseY);
}
//Tells me if the mouse is hovering over the rectangle
boolean overRect(int x, int y, int rectWidth, int rectHeight)
{
if (mouseX >= x && mouseX <= x+rectWidth &&
mouseY >= y && mouseY <= y+rectHeight) {
return true;
} else {
return false;
}
}
void update(int x, int y){
for(int i = 0; i < 15; i++){
if ( overRect(xpos[i], ypos[i], xSize[i], ySize[i]) ){
isOver[i] = true;
}
else{
isOver[i] = false;
}
}
}
And this is the class...
Code:class madRects{
int xpos, ypos, xSize, ySize;
madRects(int x, int y, int xLength, int yLength){
xpos = x;
ypos = y;
xSize = xLength;
ySize = yLength;
}
void displayRect(){
rect(xpos, ypos, xSize, ySize);
}
}
Thanks to anyone who can resolve the problem, I'll keep trying though.