
import java.util.*;
import java.awt.*;
import java.applet.*;

public class MathArt12 extends Applet{
	
	int w, h;
	private Image offImage;
   	private Dimension offDimension;
	private Graphics offGraphics;
	Color c = new Color(0,0,0);
	int posx=100;
	int posy=200; 
	
	public void init() {
		
		Dimension d = this.size(); 
		w = d.width;
		h = d.height;
		
		if ((offImage == null) || (w != offDimension.width) || (h != offDimension.height)) {
			offImage = createImage(w, h);
			offDimension = d;
			offGraphics = offImage.getGraphics();
		}
		paintSquares();	
		repaint();
	}
	
	public void update(Graphics g) {
		paint(g);
	}
	
	public void paint(Graphics g) {	
		g.drawImage(offImage, 0, 0, this);
	}
	

		
	public void paintSquares() {
		
		for (int j=0; j<h; j=j+7) {
			for (int i=0; i<w; i=i+11) {

				double hue = (double)i*(0.2)/(double)(h/2)+(0.3);
				hue = hue + (double)((int)i%posx) * (0.2) / (double)(33);
				
				
				double sat = (double)i*(0.2)/(double)(h/2)+(0.3);
				sat = sat + (double)(i*j * 0.2) / (double)(w*h);
	

				double value = (double)j*(0.5)/(double)(h/2)+(0.3);
				value = value + (double)((int)j%posy)*(0.1)/(double)(13);
	
				c = new Color(Color.HSBtoRGB ((float)(hue) , (float)(sat), (float)(value))); 
				offGraphics.setColor(c);
				offGraphics.fillRect(i,j,10,7);
			}
		}
	}

	
	public boolean mouseDrag(Event e, int x, int y) {	
		if (x>0 & x<w)
			posx=x;
		if (y>0 & y<h)
			posy=y;
		paintSquares();	
		repaint();
		return true;
	}
	
}









