//
// Draw a simple house

import java.awt.*;

public class House extends BufferedApplet
{
   // GEOMETRY - YOU'LL WANT TO REPLACE THIS WITH YOUR OWN SHAPES.

   double points[][][] = {
      {{-.9,-1,0},{1,-1,0},{1,.8,0},{0,1.5,0},{-1,.8,0},{-1,-1,0},{.9,.8,0},{-.9,.8,0},{.9,-.9,0}},
      {{-.2,-.95,0},{-.2,-.4,0},{.2,-.4,0},{.2,-.95,0}},
   };

   double a[] = {0,0,0}, b[] = {0,0,0};
   int w, h, count = 0;
   double t = 0;

   public void init() {
       super.init();

       // YOU MIGHT WANT TO CREATE YOUR MATRIX OBJECTS HERE
   }

   public void render(Graphics g) {
      w = bounds().width;                         // FIND OUT HOW BIG THE APPLET WINDOW IS
      h = bounds().height;

      g.setColor(Color.white);                    // MAKE A CLEAR WHITE BACKGROUND
      g.fillRect(0,0,w,h);

      g.setColor(Color.black);                    // SET THE DRAWING COLOR TO BLACK

      animate();                                  // DO ANIMATION CALCULATIONS

      for (int i = 0 ; i < points.length ; i++)   // LOOP THROUGH ALL THE SHAPES
      for (int j = 1 ; j < points[i].length ; j++) { // LOOP THROUGH ALL THE LINES IN THE SHAPE
	 transform(points[i][j-1], a);                      // TRANSFORM BOTH ENDPOINTS OF LINE
	 transform(points[i][j  ], b);
	 g.drawLine(x(a[0]), y(a[1]), x(b[0]), y(b[1]));    // DRAW ONE LINE ON THE SCREEN
      }
   }

   void animate() {

      ////////// REPLACE THIS CODE BY A SEQUENCE OF TIME-VARYING MATRIX OPERATIONS //////////

      t = .7 + .3 * Math.sin(.1 * count++);       // VARY PARAMETERS TO CONTROL THE ANIMATION

      ///////////////////////////////////////////////////////////////////////////////////////
   }

   int x(double t) { return w/2 + (int)(t*w/4); } // CONVERT X COORDINATE TO SCREEN PIXELS
   int y(double t) { return h/2 - (int)(t*w/4); } // CONVERT Y COORDINATE TO SCREEN PIXELS

   void transform(double src[], double dst[]) {

      ///////// REPLACE THIS CODE WITH A METHOD CALL TO TRANSFORM THE POINT BY YOUR MATRIX

      dst[0] = t * src[0];
      dst[1] = t * src[1];
      dst[2] = t * src[2];

      ////////////////////////////////////////////////////////////////////////////////////
   }
}