Escalacion Traslacion y Rotacion
Escalacion Traslacion y Rotacion
Escalacion Traslacion y Rotacion
package mas;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
/**
*
* @author soul
*/
public class Escalacion extends Applet implements AdjustmentListener{
/*punto de la i*/
int pol2x[]={265,310,310,265};
int pol2y[]={25,25,60,60};
public void init()
{
this.resize(640,480);
Zoom=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,100);
add(Zoom);
Zoom.addAdjustmentListener(this);
Zoom.setValue(1);
}
public void paint(Graphics g)
{
g.setColor(new Color(50,50,100));
PolyScale(polx,poly,8,0,g);
PolyScale(pol1x,pol1y,12,0,g);
PolyScale(pol2x,pol2y,4,0,g);
}
public void PolyScale(int polyx[],int polyy[],int p,int L,Graphics g)
//points, Polygon, FillPolygon or Polyline,Graphics
{
int c=0;
while(c<=(p-1))
{
auxx[c]=polyx[c]*sc;
auxy[c]=polyy[c]*sc;
c++;
}
switch(L)
{
case 0:
g.drawPolygon(auxx,auxy,p);
break;
case 1:
g.fillPolygon(auxx,auxy,p);
break;
case 2:
g.drawPolyline(auxx,auxy,p);
break;
}
}
public void adjustmentValueChanged(AdjustmentEvent arg0) {
sc=Zoom.getValue();
/*event zoom+
case 1>scale>0 then scale+0.1
case scale>1 then scale+1*/
/*event zoomcase 1>scale>0 then scale-0.1
case scale>1 then scale-1*/
repaint();
}
}
TRASLACION
package mas;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
/**
*
* @author soul
*/
public class Traslacion extends Applet implements AdjustmentListener{
this.PolMove(pol1x,pol1y,12);
g.drawPolygon(auxx,auxy,12);
this.PolMove(pol2x,pol2y,4);
g.drawPolygon(auxx,auxy,4);
}
ROTACION
package mas;
import java.awt.Scrollbar;
import java.applet.Applet;
//import java.util.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
/*central*/
int pol1x[]={90,255,255,265,265,310,310,210,210,150,150,90};
int pol1y[]={25,25,115,115,65,65,155,155,60,60,110,110};
/*punto de la i*/
int pol2x[]={265,310,310,265};
int pol2y[]={25,25,60,60};
public void init()
{
this.resize(640,480);
CCW=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,100);
add(CCW);
CCW.addAdjustmentListener(this);
}
public void paint(Graphics g)
{
g.setColor(new Color(50,50,100));
seg++;
/*axis*/
/*radius*/
x = (int) (250 + Math.sin(seg * 6 * RAD)* 150);
y = (int) (250 - Math.cos(seg * 6 * RAD)* 150);
System.out.println("x="+x+"y="+y+"Seg="+seg);
//g.fillOval(x,y,10,10);
this.PolMove(polx,poly,8);
g.drawPolygon(auxx,auxy,8);
this.PolMove(pol1x,pol1y,12);
g.drawPolygon(auxx,auxy,12);
this.PolMove(pol2x,pol2y,4);
g.drawPolygon(auxx,auxy,4);
}
public void PolMove(int polyx[],int polyy[],int p)
{
int c=0;
while(c<=(p-1))
{
auxx[c]=polyx[c]+x-100;
auxy[c]=polyy[c]+y-100;
c++;
//System.out.println("asdad");
}
}
public void adjustmentValueChanged(AdjustmentEvent arg0)
{
seg=CCW.getValue();
repaint();
}
}