Actually, I am working on an already written code but I have to add additional features. It is a grid system where you can draw shapes by mouse clicks and apply transformations like translation, rotation and so on. If i get the idea of how to do for one transformation, I think I will be able to manage for the other transformations. For e.g the existing code now just outputs the final transformation on a shape but I have to demonstrate that by an animation to the final output. How do I do that? bRotate is a Jbutton for Rotation
bRotate.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
Panel.Translate=false;
Panel.Rotate=true;
Panel.Scale=false;
Panel.Shear=false;
Panel.Reflect=false;
Panel.Fill=false;
Panel.draw=false;
double angle = Integer.parseInt(tAngle.getText())*-1;
int ptsNum = Panel.poly.X.length;
if( Panel.R==null){
Panel.R = new double[ptsNum][2];
for(int i=0;i<ptsNum;i++){
Panel.R[i][0]= Panel.poly.X[i];
Panel.R[i][1]= Panel.poly.Y[i];
}
}
ActionListener listener = new ActionListener(){
public void actionPerformed(ActionEvent e){
Panel.R = Transformation.rotate( Panel.R, angle);
double [] xpts = new double[ptsNum];
double [] ypts = new double[ptsNum];
for(int i=0;i<ptsNum;i++){
xpts[i]=(int) Panel.R[i][0];
ypts[i]=(int) Panel.R[i][1];
}
Panel.poly= new Polygon(xpts,ypts,xpts.length);
Panel.undoPoly.add(Panel.poly);
Panel.currentPolygon=null;
Panel.enable=true;
Main.enabled();
repaint();
}
};
Timer timer = new Timer(10, listener);
timer.start();
}
}
);