import java.applet.*;
import java.awt.*;

/* <applet code="m0104434_01.class" width=480 height=480></applet> */

public class m0104434_01 extends Applet {
	private static final double V_SIZE = 480;
	private static final double WHIRL_X = V_SIZE * 1 / 1.618, WHIRL_Y = V_SIZE * (1 - 1 / 1.618);
	private static final double EYE_X = V_SIZE * 0.15, EYE_Y = V_SIZE * 0.175;
	private static final boolean IS_INTERNAL_LANTERN = true;
	
	public void paint(Graphics g) {
		int vsize = (int) V_SIZE;
		int x, y, R, G, B;
		double X, X2, sX, wX, dX, Y, Y2, sY, wY, dY, Z1, Z2, Z3, oD, oD2, oA, eD;
		
		// *** BEGIN WINDOW *** //
		
		sX = -50.0;
		sY = -50.0;
		wX = 150.0;
		wY = 150.0;
		
		// *** END WINDOW *** //
		
		dX = wX/(double)vsize;
		dY = wY/(double)vsize;
		
		// *** BEGIN YOUR PROGRAM *** //
		
		for (x = 0; x < vsize; x++) {
			for (y = 0; y < vsize; y++) {
				oD = Math.sqrt(Math.pow(x - WHIRL_X, 2) + Math.pow(y - WHIRL_Y, 2));
				oD2 = Math.sqrt(Math.pow(x - V_SIZE/2, 2) + Math.pow(y - V_SIZE/2, 2));
				oA = Math.atan2(y - WHIRL_Y, x - WHIRL_X) / Math.PI;
				
				X = sX + dX * (x * Math.cos(Math.PI / 180 * 75) - (y + V_SIZE) * Math.sin(Math.PI / 180 * 75));
				Y = sY + dY * (x * Math.sin(Math.PI / 180 * 75) + (y + V_SIZE) * Math.cos(Math.PI / 180 * 75));
				X2 = x * Math.cos(Math.PI / 180 * -30) - y * Math.sin(Math.PI / 180 * -30);
				Y2 = x * Math.sin(Math.PI / 180 * -30) + y * Math.cos(Math.PI / 180 * -30);
				
				Z1 = Math.abs(X * Y + X / Y) / 256.0;
				Z2 = Math.pow(x, 4) / (1024.0 + y * y) / 32.0;
				Z3 = Math.abs(Math.cos(X2 / V_SIZE * 24.0));
				
				eD = Math.abs((X2 - EYE_X) % 250 - 125) - (Y2 - EYE_Y) - Math.pow(Y2 - EYE_Y, 2) * 0.002;
				if (!IS_INTERNAL_LANTERN ^ ((eD > 100.0 || Y2 > EYE_Y) && (Z3 + 3.5 > Y2 / V_SIZE * 12.0 || -Z3 + 6.5 < Y2 / V_SIZE * 12.0))) {
					R = 32 + 63 - ((int) Z1 % 32);
					G = 16 + 31 - ((int) Z1 % 32);
					B = 0;
					
					if ((oD % 60 < 45 || oD < 90.0) && (int) (oA * 5.5 + oD / 60.0) % 2 == 0) {
						R += -32 + 191 * (V_SIZE - x) / V_SIZE;
						G += -16 + (47 * (V_SIZE - y) + 63 * (V_SIZE - x)) / V_SIZE;
					}
					
					if ((int) (oA * -13.5 + oD / 60.0) % 2 == 0) {
						R += 63 * (V_SIZE - x) / V_SIZE;
						G += 31 * (V_SIZE - y) / V_SIZE;
						
						if (oD % 30 < 20 && oD > 90.0) { R *= 0.85; G *= 0.85; }
					}
				} else {
					R = (int) (40 * (V_SIZE - x) / V_SIZE);
					G = (int) (25 * (V_SIZE - x) / V_SIZE + 15 * (V_SIZE - y) / V_SIZE);
					B = (int) (25 * (V_SIZE - x) / V_SIZE);
				}
				
				R *= 1.5 - oD2 / V_SIZE * 2.25; if (R >= 256) R = 255; if (R < 0) R = 0;
				G *= 1.5 - oD2 / V_SIZE * 2.25; if (G >= 256) G = 255; if (G < 0) G = 0;
				B *= 1.5 - oD2 / V_SIZE * 2.25; if (B >= 256) B = 255; if (B < 0) B = 0;
				
 				// *** END YOUR PROGRAM *** //
				g.setColor(new Color(R,G,B));
				g.drawLine(x,y,x,y);
			}
		}
	}
}
