import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*
  <applet code="affine" width=800 height=600>
  </applet>
*/


public class affine 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[100][3];
	int p_new[][] = new int[100][3];
	double a[][] = new double[3][3];

	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] = 0; p[0][1] = 225;
		p[1][0] = 0; p[1][1] = -225;
		p[2][0] = 0; p[2][1] = 0;
		p[3][0] = -30; p[3][1] = 30;
		p[4][0] = 0; p[4][1] = 0;
		p[5][0] = 30; p[5][1] = 30;


		p[6][0] = 30; p[6][1] = 60;
		p[7][0] = 0; p[7][1] = 225;

		p[8][0] = -30; p[8][1] = 60;
		p[9][0] = 0;     p[9][1] = 225;

		p[10][0] = -30; p[10][1] = 60;
		p[11][0] = -30;     p[11][1] = 30;


//-----------------------------------
				p[12][0] = 0; p[12][1] = 0;
				p[13][0] = -30;     p[13][1] = -30;

				p[14][0] = 0; p[14][1] = 0;
				p[15][0] = 30;     p[15][1] = -30;
//-----------------------------------

				p[16][0] = 30; p[16][1] = -60;
				p[17][0] = 0; p[17][1] = -225;

				p[18][0] = -30; 	p[18][1] = -60;
				p[19][0] = 0;     p[19][1] = -225;



				p[33][0] =-30; p[33][1] = -30;
				p[34][0] = -30;     p[34][1] = -60;



//----------------------------------------


	p[35][0] = 0; p[35][1] = 0;
				p[36][0] = 30; p[36][1] = 60;

				p[76][0] = 0; 	p[76][1] = -30;
				p[77][0] = 0;     p[77][1] = 60;



				p[20][0] =0; p[20][1] = 0;
				p[21][0] = 30;     p[21][1] = -60;


				p[22][0] =-30; p[22][1] = 60;
				p[23][0] = 0;     p[23][1] = 0;





		for(int i=0; i<88; 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;

		write_base(g);
		calc( );
		write_new(g);
	}

	public void write_base(Graphics g) {
		g.setColor(Color.white);
		g.fillRect(0, 0, d.width, d.height);
		g.setColor(Color.red);
		g.drawLine(xc, 0, xc, d.height);
		g.drawLine(0, yc, d.width, yc);
		g.setColor(Color.black);
		for(int i=0; i<88; i++)
			g.drawLine(p[i][0] + xc, yc - p[i][1], p[(i+1)%88][0] + xc, yc - p[(i+1)%88][1]);
	}

	public void calc( ) {
		for(int i=0; i<88; i++) {
			for(int j=0; j<3; j++) {
				p_new[i][j] = 0;
			}
		}


		for(int i=0; i<88; 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.blue);
		for(int i=0; i<88; i++)
			g.drawLine(p_new[i][0] + xc, yc - p_new[i][1],
				p_new[(i+1)%88][0] + xc, yc - p_new[(i+1)%88][1]);
	}

}