Escalacion Traslacion y Rotacion

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 9

ESCALACION

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{

private static final long serialVersionUID = 1L;


private Scrollbar Zoom;
private int sc=1;
int auxx[]={0,0,0,0,0,0,0,0,0,0,0,0};
int auxy[]={0,0,0,0,0,0,0,0,0,0,0,0};
/*primer parte*/
int polx[]={25,85,85,155,155,205,205,25};
int poly[]={25,25,115,115,65,65,155,155};
/*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);
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{

private static final long serialVersionUID = 1L;


private Scrollbar Hor;
private Scrollbar Ver;
private int H=0;

private int V=0;


int auxx[]={0,0,0,0,0,0,0,0,0,0,0,0};
int auxy[]={0,0,0,0,0,0,0,0,0,0,0,0};
/*primer parte*/
int polx[]={25,85,85,155,155,205,205,25};
int poly[]={25,25,115,115,65,65,155,155};
/*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);
Hor=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,100);
add(Hor);
Hor.addAdjustmentListener(this);
Ver=new Scrollbar(Scrollbar.VERTICAL,0,1,0,100);
add(Ver);
Ver.addAdjustmentListener(this);
}
public void paint(Graphics g)
{
g.setColor(new Color(50,50,100));
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]+H;
auxy[c]=polyy[c]+V;
c++;
//System.out.println("asdad");
}
}
public void adjustmentValueChanged(AdjustmentEvent arg0) {
H=Hor.getValue()*10;
V=Ver.getValue()*10;
repaint();
}
}

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;

public class Rotacion extends Applet implements AdjustmentListener{

private static final long serialVersionUID = 1L;


private Scrollbar CCW;
private int sc=0;
private int rdd = (int) (3.1415926535 / 180);
float RAD =(float) (3.1415926535 / 180);
private int seg=0,x,y;
int auxx[]={0,0,0,0,0,0,0,0,0,0,0,0};
int auxy[]={0,0,0,0,0,0,0,0,0,0,0,0};
/*primer parte*/
int polx[]={25,85,85,155,155,205,205,25};
int poly[]={25,25,115,115,65,65,155,155};

/*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();
}
}

También podría gustarte