//
// Name: Solar Eclipse 2009
// License: Public Domain
// Author: Matthew Gates
// Version: 1.0
// Description: Script to demonstrate a total solar eclipse which has happened
//              in 2009 (location=Rangpur, Bangladesh).
//
	
function blockText(textArray)
{
	var fontSize = 20;
	var lineSep = fontSize * 1.5;
	y = 50;
	ids = new Array();
	for(i=0; i<textArray.length; i++)
	{
		ids[i] = LabelMgr.labelScreen(textArray[i], 30, y, false, fontSize, "#0044ff");
		y += lineSep;
	}

	for(i=0; i<ids.length; i++)
	{
		LabelMgr.setLabelShow(ids[i], true);
		core.wait(0.15);
	}
	return ids;
}

function clearLabels(ids)
{
	for(i=0; i<ids.length; i++)
	{
		LabelMgr.setLabelShow(ids[i], false);
		core.wait(0.15);
	}
	core.wait(1);
	for(i=0; i<ids.length; i++)
	{
		LabelMgr.deleteLabel(ids[i]);
	}
}

// While we're setting up, change the time to go nice and slow
LabelMgr.deleteAllLabels();
core.setTimeRate(1);

// Setup display mode
core.clear("natural");

// We'll turn these off as the sun comes up, but for pre-dawn we want to show them
ConstellationMgr.setFlagLines(true);
ConstellationMgr.setFlagLabels(true);
SolarSystem.setFlagPlanets(true);

// OK, move to the proper location and date for the eclipse
core.setDate("2009:07:21T22:05:00");
core.setObserverLocation(89.34, 26.5, 10, 0, "Rangpur, Bangladesh");

// Point at a bit of sky approx above the Eastern horizon
core.moveToAltAzi(20, 90, 3);
StelMovementMgr.zoomTo(60, 4);
core.wait(3);

ids = blockText(Array("Place: Rangpur, Bangladesh",
                      "Date: 2009-07-21, just before dawn.",
                      "Orion and Gemini climb into the dawn sky",
                      "fading from view as the sky brightens with",
                      "the appearance of the Sun"));

core.wait(1);
// slowly ramp up the time rate
for(t=1; t<=250; t++)
{
	core.setTimeRate(t);
	core.wait(0.007);
}

core.waitFor("2009:07:21T22:45:00");
clearLabels(ids);
ConstellationMgr.setFlagLines(false);
ConstellationMgr.setFlagLabels(false);
core.waitFor("2009:07:21T23:30:00");
ids = blockText(Array("The Sun has a companion this morning...",
                      "The Moon."));
core.waitFor("2009:07:21T23:54:00");
clearLabels(ids);

core.waitFor("2009:07:22T00:09:00");
ids = blockText(Array("The Moon starts to obscure the Sun's disc",
                      "and the sky becomes a little darker"));
core.waitFor("2009:07:22T00:15:00");
for(t=250; t>150; t--)
{
	core.setTimeRate(t);
	core.wait(0.007);
}
core.waitFor("2009:07:22T00:30:00");
clearLabels(ids);
core.wait(7);
for(t=150; t>25; t--)
{
	core.setTimeRate(t);
	core.wait(0.007);
}
core.waitFor("2009:07:22T00:56:00");
for(t=25; t>8; t--)
{
	core.setTimeRate(t);
	core.wait(0.007);
}
ids = blockText(Array("As the last of the Sun is covered by the Moon",
                      "the sky darkens quickly, and the brighter stars",
                      "and planets become visible"));
core.waitFor("2009:07:22T00:58:20");
for(t=8; t>5; t--)
{
	core.setTimeRate(t);
	core.wait(0.007);
}
clearLabels(ids);
core.waitFor("2009:07:22T00:59:10");
StarMgr.setLabelsAmount(4);
SolarSystem.setLabelsAmount(4);
StarMgr.setFlagLabels(true);
SolarSystem.setFlagLabels(true);
core.waitFor("2009:07:22T00:59:30");
ids = blockText(Array("At totality, the Sun is completely hidden behind the Moon"));
core.selectObjectByName("Moon", false);
StelMovementMgr.setFlagTracking(true);
StelMovementMgr.zoomTo(4, 5);
core.wait(1);
StarMgr.setFlagLabels(false);
SolarSystem.setFlagLabels(false);
core.wait(4);
clearLabels(ids);
core.wait(3);
StelMovementMgr.setFlagTracking(false);
core.moveToAltAzi(20, 90, 3);
StelMovementMgr.zoomTo(60, 4);
core.waitFor("2009:07:22T01:01:45");
for(t=5; t>2; t--)
{
	core.setTimeRate(t);
	core.wait(0.007);
}
clearLabels(ids);
ids = blockText(Array("The Sun emerges from behind the Moon",
                      "The sky brightens once more"));
core.waitFor("2009:07:22T01:02:50");
for(t=3; t<150; t++)
{
	core.setTimeRate(t);
	core.wait(0.02);
}
clearLabels(ids);
core.wait(3);
ids = blockText(Array("The End"));
core.wait(4);
clearLabels(ids);


