import com.cult3d.Cult;
import com.cult3d.Cult3DScript;
import com.cult3d.world.CultObject;
import com.cult3d.world.Texture;

import java.awt.Color;
import java.awt.Image;
import java.awt.Graphics;

public class WhiteCube extends Thread implements Cult3DScript
{
	private CultObject whitecube;
	private Texture    cubetexture;
	private Image      timage;

	private int tWidth, tHeight;

	private boolean    going = true;
	
	public WhiteCube()
	{
		whitecube   = new CultObject("Cube");

		cubetexture = new Texture("white");
		tWidth  = cubetexture.getWidth();
		tHeight = cubetexture.getHeight();
		timage  = Cult.createImage(tWidth, tHeight);

		start();
	}

	public void run()
	{
		do {
			whitecube.rotate( whitecube.Z, (float)(10*Math.PI/180.0));
			whitecube.rotate( whitecube.Y, (float)( 5*Math.PI/180.0));
			try {
				sleep(100);
			} catch(InterruptedException e) {
			}
        } while(going);
	}

	public void mouseClick(String arg)
	{
		Color c = new Color((float)Math.random(),
		                    (float)Math.random(),
		                    (float)Math.random());
		Graphics g = timage.getGraphics();
		g.setColor(c);
		g.fillRect(0,0, tWidth,tHeight);
		cubetexture.setTexture(timage);
	}

	public void cult3dDestroy()
	{
		going = false;
	}
}
