For that you would want to use objects. You create objects by making a mould called a class and then punch objects out of that mould (like a cookie cutter).
It's easier at first to think of an object as a program within a program. So with an array of objects you could have hundreds of little programs running around.
As you get used to using objects you should start thinking of them the same way you use int, float and String. They all have methods and properties you can call upon. If you're not au fait with this then there's plenty of tutorials out there which will cover it and help you get your head round it.
http://www.processing.org/learning/examples/arrayobjects.html
And here's another example:
Code:
Draggable [] example;
void setup(){
size(400,400);
example = new Draggable[10];
for (int i = 0; i < example.length; i++){
example[i] = new Draggable (i*20,i*20,20,color(100,100,200),color(100,200,200),"rect");
}
}
void draw(){
background(144,130,140);
for (int i = 0; i < example.length; i++){
example[i].draw();
example[i].update();
}
}
class Draggable {
//properties
int x,y,z,size,c1,c2;
String mode;
boolean locked = false;
//setup - called a constructor
Draggable (int x, int y, int size, color c1, color c2, String mode) {
this.x = x;
this.y = y;
this.size = size;
this.c1 = c1;
this.c2 = c2;
this.mode = mode;
}
//methods
void draw(){
noStroke();
if (locked || over()){
fill(c1);
}
else{
fill(c2);
}
if (mode == "rect"){
rect(x,y,size,size);
}
if (mode == "ellipse"){
ellipse(x,y,size,size);
}
}
void update(){
if (over() && mousePressed){
locked = true;
}
if (locked){
x = mouseX;
y = mouseY;
}
if (!mousePressed){
locked = false;
}
}
boolean over(){
if (mouseX <= x+size && mouseX >= x && mouseY <= y+size && mouseY >= y){
return true;
}
else{
return false;
}
}
}