It was just quick pseudo-code to put you on the track...
An issue was the lack of setup(), another was his use of array index on ArrayList...
To keep the idea of extensible list, I give a corrected code:
Code:class MyRect{ // class for storing rect co-ordinates
float x,y,w,h;
MyRect(float _x, float _y, float _w, float _h){
x = _x;
y = _y;
w = _w;
h = _h;
}
void draw(){
rect(x, y, w, h);
}
}
ArrayList myRectangles;
color backgr;
void setup()
{
size (500,500);
smooth();
noFill();
myRectangles = new ArrayList();
// add some rectangles to the list here:
myRectangles.add(new MyRect(1,1,100,100));
myRectangles.add(new MyRect(100,100,100,100));
}
void draw(){
background(backgr); // this clear background each time
stroke(255);
for (int i = 0; i < myRectangles.size(); i++)
((MyRect)myRectangles.get(i)).draw();
}
void keyPressed() {
if (key == '+') {
backgr += 10;
}
if (backgr > 255) {
backgr = 255;
}
if (key == '-') {
backgr -= 10;
}
if (backgr < 0) {
backgr = 0;
}
}
Note I delegated the drawing to the object itself: thus it is a little more than a simple structure.