The following script maps the [D] key to a function that toggles the display of planets
between their real size and a magnified size Mode (works with any solar system).
----------------------------------------------------
This script works with Celestia 1.5 or later.
----------------------------------------------------
Code: Select all
-- Map the togglePlanetSize function to the [D] key.
-- (Toggle the size of planets between Real and Magnified Modes)
radius = {}
iradius = {}
mag_coeff = 2e3
function getRadius(obj_table)
for k, obj in pairs(obj_table) do
radius[k] = obj:radius()
end
return radius
end
function getSolsysElements()
planets = {}
parent = sel;
while parent:type() ~= "star" do
parent = parent:getinfo().parent
end
if parent then
starname = parent:name()
end
children = parent:getchildren()
for k, v in pairs(children) do
if v:type() == "planet" then
planets[k] = v
end
end
return starname, planets
end
function togglePlanetSize()
sel = celestia:getselection()
if sel and sel:name() ~= "?" then
starname, planets = getSolsysElements()
radius = getRadius(planets)
iradius[starname] = not(iradius[starname])
for k, planet in pairs(planets) do
if iradius[starname] then
planet:setradius(radius[k] * mag_coeff)
celestia:print("Magnification:\n Planets: "..string.format("%gx", mag_coeff).."\n Other bodies: 1x", 10, -1, -1, 1, 10)
else
planet:setradius(radius[k] / mag_coeff)
celestia:print("Real size", 10, -1, -1, 1, 10)
end
end
end
end
keyhandlers =
{
d = togglePlanetSize,
}
function handlekey(k)
handler = keyhandlers[k.char]
if (handler ~= nil) then
handler()
return true
else
return false
end
end
celestia:registereventhandler("key", handlekey)
-----------------------------------------------------------------------
-- Use the following code if you wish to merge
-- the planet mag script with your start.cel script.
-----------------------------------------------------------------------
function CEL(source)
local script = celestia:createcelscript(source)
while script:tick() do
wait(0)
end
end
CEL([[
{
# ... Beginning of start.cel script
# PASTE ALL YOUR STANDARD START SCRIPT HERE
# End of start.cel script...
}
]])
-- end