import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*
  <applet code="affine" width=350 height=400>
  </applet>
*/


public class affine03 extends Applet
implements ActionListener, TextListener {
	TextField t1,t2,t3,t4,t5,t6;
	Label l1,l2,l3,l4,l5,l6;
	Button b;
	Dimension d;
	int xc;
	int yc;
	int p[][] = new int[29][3];
	int p_new[][] = new int[29][3];
	double a[][] = new double[3][3];
	int WIDTH = 800;
	int HEIGHT = 600;
	int re;

	public void init( ) {
		t1 = new TextField("1",4); t2 = new TextField("0",4); t3 = new TextField("0",4);
		t4 = new TextField("0",4); t5 = new TextField("1",4); t6 = new TextField("0", 4);

		l1=new Label("a_11"); l2=new Label("a_12"); l3=new Label("a_13");
		l4=new Label("a_21"); l5=new Label("a_22"); l6=new Label("a_23");
		add(l1); add(t1); add(l2); add(t2); add(l3); add(t3);
		add(l4); add(t4); add(l5); add(t5); add(l6); add(t6);

		b = new Button("calc");
		b.addActionListener(this);
		add(b);

		p[0][0] = -24; p[0][1] = 43;
		p[1][0] = 0; p[1][1] = 43;
		p[2][0] = 0; p[2][1] = 28;
		p[3][0] = 0; p[3][1] = 43;
		p[4][0] = 24; p[4][1] = 43;
		p[5][0] = 32; p[5][1] = 25;
		p[6][0] = 18; p[6][1] = 18;
		p[7][0] = 32; p[7][1] = 25;
		p[8][0] = 39; p[8][1] = 11;
		p[9][0] = 17; p[9][1] = 0;
		p[10][0] = 31; p[10][1] = -65;
		p[11][0] = 12; p[11][1] = 0;
		p[12][0] = 8; p[12][1] = 0;
		p[13][0] = 17; p[13][1] = -70;
		p[14][0] = 4; p[14][1] = 0;
		p[15][0] = 2; p[15][1] = 0;
		p[16][0] = 0; p[16][1] = -73;
		p[17][0] = -2; p[17][1] = 0;
		p[18][0] = -4; p[18][1] = 0;
		p[19][0] = -17; p[19][1] = -70;
		p[20][0] = -8; p[20][1] = 0;
		p[21][0] = -12; p[21][1] = 0;
		p[22][0] = -31; p[22][1] = -65;
		p[23][0] = -17; p[23][1] = 0;
		p[24][0] = -39; p[24][1] = 11;
		p[25][0] = -31; p[25][1] = 27;
		p[26][0] = -17; p[26][1] = 20;
		p[27][0] = -31; p[27][1] = 27;
		p[28][0] = -24; p[28][1] = 43;

		for(int i=0; i<29; i++)
			p[i][2] = 1;
    }

	public void actionPerformed(ActionEvent ae)
    {
		a[0][0] = Double.valueOf(t1.getText()).doubleValue();
		a[0][1] = Double.valueOf(t2.getText()).doubleValue();
		a[0][2] = Double.valueOf(t3.getText()).doubleValue();
		a[1][0] = Double.valueOf(t4.getText()).doubleValue();
		a[1][1] = Double.valueOf(t5.getText()).doubleValue();
		a[1][2] = Double.valueOf(t6.getText()).doubleValue();

		repaint( );
    }

	public void textValueChanged(TextEvent te) {
	}


	public void paint(Graphics g) {
		d = getSize( );
		xc = d.width /2;
		yc = d.height / 2;

		a[0][2]-=450;

		write_base(g);
		calc( );
		write_new(g);



		for(re = 0; re<4; re++){
			a[0][0]+=0.8;a[1][1]+=0.8;
			a[0][1]+=0;a[0][2]+=200;a[1][0]+=0;a[1][2]+=0;
			calc( );
			write_new(g);
		}


	}

	public void write_base(Graphics g) {
		g.setColor(Color.green);
		g.fillRect(0, 0, d.width, d.height);
		g.setColor(Color.blue);
		g.drawLine(xc, 0, xc, d.height);
		g.drawLine(0, yc, d.width, yc);
		g.setColor(Color.yellow);
	//	for(int i=0; i<29; i++)
	//		g.drawLine(p[i][0] + xc, yc - p[i][1], p[(i+1)%29][0] + xc, yc - p[(i+1)%29][1]);
	}

	public void calc( ) {
		for(int i=0; i<29; i++) {
			for(int j=0; j<3; j++) {
				p_new[i][j] = 0;
			}
		}


		for(int i=0; i<29; i++) {
			for(int j=0; j<3; j++) {
				for(int k=0; k<3; k++) {
					p_new[i][j] += (int ) (a[j][k]*p[i][k]);
				}
			}
		}
	}

	public void write_new(Graphics g) {
		g.setColor(Color.yellow);
		for(int i=0; i<29; i++)
			g.drawLine(p_new[i][0] + xc, yc - p_new[i][1],
				p_new[(i+1)%29][0] + xc, yc - p_new[(i+1)%29][1]);
	}

}