import java.awt.*;
import java.applet.Applet;


/**
 * by Geoff Towell
 * Example applet
 * file: Hello.java
 * Description: goes yellow, put in pie and hello
 **/

/**
 * AUTHOR:      Geoff Towell
 * FILE:        Mondrian.java
 * PURPOSE:     draw a crude reproduction of a Mondrian print
 * DESCRIPTION: reproduces (sort of) http://205.126.22.50/art/terms/largeprints/mondrian.jpg
 *              In the code below, I set up a 10 wise by 6 high grid into 
 *              which the colors will go.  The point of this grid is that it
 *              approximates Mondrian's print and is independent of the size
 *              of the applet.
 **/   
public class Mondrian extends Applet
{

    public void paint(Graphics g)
    {
	// fist get the size of the applet as defined in the html page
	int appX = (int)getSize().getWidth();
	int appY = (int)getSize().getHeight();

	// now set the size of reproduction. The original is about 2 by 3.
	int paintY = appY - 40;
	int paintX = 2*appY/3;
	int offsetX = 30; // the distance of the painting from the left edge of the applet 

	setBackground(Color.WHITE);
	
	// draw a frame
	g.setColor(new Color(190, 190, 190)); // a light gray
	g.fillRect(offsetX+paintX, 0, (appX-paintX), appY);
	g.fillRect(0, paintY, appX, (appY-paintY));
	g.fillRect(0,0,offsetX, appY);

	g.setColor(Color.BLACK);
	g.drawString("Geoff'f homage to Mondrian", offsetX, appY-5);

	// set the size of the grid into which I will be painting.. 
	// 6 high by 10 wise
	int yGrid=6;
	int xGrid=10;

	// the first paint block.  
	int yellowX=1;
	int yellowY=0;
	int yellowWidth = 5;
	int yellowHeight = 1;

	g.setColor(new Color(203, 169, 21));
	
	// this is a little tricky because I set up my grid to have the 0.0
	// point in the lower left and applets have their 0,0 point in the 
	// the upper left.  Hence, I need to do a lot of rather strange 
	// subtractions to translate my y grid locations into applet coordinnates
	// here is the idea:
	//    1. Go to the bottom of the picture.  
	//    2. Then go up to the bottom of the area to be colored
	//    3. Then go up to the to of the area to be colored
	// 
	// Here is the calculation (in words):  
	//    (y size of paint area) - (y size of 1 grid)*(bottom grid location) - (y size of 1 grid)*(grid height of area to be colored)
	// Putting this into equations:
	//    paintY - (paintY/yGrid) * (yellowY) - (paintY/yGrid) * (yellowHeight)
	// This could have been a easier had I chosen to make the 
	// 0,0 location of my grid in the top left corner.
	g.fillRect( offsetX+paintX/xGrid*yellowX, paintY-(paintY/yGrid*yellowY)-paintY/yGrid*yellowHeight, 
		    paintX/xGrid*yellowWidth, paintY/yGrid*yellowHeight);

	
	int blueX=6;
	int blueY=1;
	int blueWidth=4;
	int blueHeight=3;
	g.setColor(new Color(24, 24, 129));
	g.fillRect( offsetX+paintX/xGrid*blueX, paintY-(paintY/yGrid*blueY)-paintY/yGrid*blueHeight, 
		    paintX/xGrid*blueWidth, paintY/yGrid*blueHeight);

	int brickRedX = 0;
	int brickRedY= 4;
	int brickRedWidth = 6;
	int brickRedHeight = 2;

	g.setColor(new Color(226, 35,35));
	g.fillRect( offsetX+paintX/xGrid*brickRedX, paintY-(paintY/yGrid*brickRedY)-paintY/yGrid*brickRedHeight, 
		    paintX/xGrid*brickRedWidth, paintY/yGrid*brickRedHeight);


    }




}
