float dx,dy,delta; int space=10; myObj[][]objArray; int x1, y1, x2, y2; void setup(){ size(200,200); background(0); } void draw(){ objArray=new myObj[400][400]; for (int x=0; x<20; x++){ for (int y=0; y<20; y++){ objArray[x][y]=new myObj((x*space), (y*space)+1); } } } class myObj{ myObj(int x, int y){ pushMatrix(); translate(x, y); //create variables for distance formula x1 = mouseX; y1 = mouseY; x2 = x; y2 = y; dx = x2-x1; // X distance between the two points dy = y2-y1; // Y distance between the two points delta = sqrt(dx*dx+dy*dy); // math for calculating the distance between two points. fill(delta*2); rotate(atan2(dx, dy)); rect(0,0, 8,8); popMatrix(); } }