topical media & game development
graphic-processing-algorithm-Ch03-p83-p83.pde / pde
int numShapes = 12; //num on side of grid of shapes
MyShape[] shape = new MyShape[numShapes*numShapes];
MyGroup group;
//*****************************************
void setup(){
size(300,300);
for(int y=0; y<numShapes; y++){
for(int x=0; x<numShapes; x++){
shape[y*numShapes+x] = new MyShape(5,9.,x*20., y*20.);
}
}
group = new MyGroup(numShapes*numShapes, shape);
group.move(10.,10.);
}
//*****************************************
void draw( ){
background(255);
group.draw();
}
int xfirst, yfirst;
//*****************************************
void mousePressed(){
xfirst = mouseX; // remember this point
yfirst = mouseY;
// Pick a shape
for(int i=0; i<group.numShapes; i++)
if(group.shapes[i].select((float)mouseX, (float)mouseY, 5.) == true)
println("Selected = " + i);
}
//*****************************************
void mouseDragged(){
int xoff = mouseX - xfirst; // get the offset
int yoff = mouseY - yfirst;
for(int i=0; i<group.numShapes; i++)
if(group.shapes[i].isSelected)
group.shapes[i].move((float)xoff, (float)yoff);
xfirst = mouseX; //remember this point
yfirst = mouseY;
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.