// *********************************************************************
// Sun.java
// This object draws a sun and sky.  The color of the sky changes with the
// position of the sun.  This object is based on Fred.java graciously provided 
// by Prof. Ken Perlin, NYU
//
// Murphy Stein
// NYU Computer Graphics
// 2006
// *********************************************************************

import java.awt.*;

public class Sun
{
	int width = 500, height = 500;
	Color shapeColor = Color.orange;
	int x, y;
	double mySpeed;
	
	Color SkyColor;
	
	static int mySize = 100;

	
	public Sun(int x, int y) {
		this.x = x;
		this.y = y;
		SkyColor = Color.blue;
	}
	

	public void draw(Graphics g) {

		double time = System.currentTimeMillis() / 1000.0;
		
		g.setColor(Color.black);
		g.fillRect(0,0,500,500);
		SkyColor = new Color(35, 79, 231, (int)(255*(1-(this.y / 1100.0))));
		g.setColor(SkyColor);
		g.fillRect(0,0,500,500);

		mySpeed = Math.PI * time * 0.01;
		this.x = (int)((width)*Math.cos( mySpeed ) + (width/2));
      	this.y = (int)((height)*Math.sin( mySpeed ) + 550);
		g.setColor(shapeColor);
		g.fillOval(x - (mySize / 2), y - (mySize / 2), mySize, mySize);
		
		g.setColor(Color.white);
	
		// draw face
		int dy = (int)(0.5 + 0.5 * Math.sin(5 * time) * 10);
		
		g.fillOval(x - 20, y - 20-dy, 15, 2*dy);
		g.fillOval(x +  5, y - 20-dy, 15, 2*dy);
		
		g.setColor(Color.black);
		
		g.drawOval(x - 20, y - 20-dy, 15, 2*dy);
		g.drawOval(x +  5, y - 20-dy, 15, 2*dy);
		
		g.drawLine(x - 20, y + 20, x + 20, y + 20);
			
   }
   
   public Color SkyColor () {
   	return this.SkyColor;
   }

}


