New celx commands available in Celestia 1.5.0

All about writing scripts for Celestia in Lua and the .cel system
Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

New celx commands available in Celestia 1.5.0

Post #1by Vincent » 05.04.2007, 11:23

Here are the new CELX scripting features that have been added to Celestia 1.5.0, along with some examples of scripts:

----------------------------------------------------------------------------------------------
- celestia:getoverlayelements / celestia:setoverlayelements commands
----------------------------------------------------------------------------------------------
> celestia:getoverlayelements()
Return a table with all overlay elements as keys, and a boolean as value indicating whether a specific overlay element is enabled.

> celestia:setoverlayelements( table:overlayelements )
Enable/disable the rendering of overlay elements.
overlayelements is a table which contains the overlayelements Time, Velocity, Selection, Frame as keys, and booleans as values for each key.

>> Example:

Code: Select all

-- Title: Enable/disable the rendering of overlay elements.

celestia:print ("Display Time only", 3)
celestia:setoverlayelements { Time = true, Velocity = false, Selection = false, Frame = false }
wait(5)

celestia:print ("Display Velocity only", 3)
celestia:setoverlayelements { Time = false, Velocity = true, Selection = false, Frame = false }
wait (5)

celestia:print ("Display Selection Information only", 3)
celestia:setoverlayelements { Time = false, Velocity = false, Selection = true, Frame = false }
wait (5)

celestia:print ("Display Frame Information only", 3)
celestia:setoverlayelements { Time = false, Velocity = false, Selection = false, Frame = true }
wait (5)

celestia:print ("Display None", 3)
celestia:setoverlayelements { Time = false, Velocity = false, Selection = false, Frame = false }
wait (5)

celestia:print ("Display All Overlay Elements", 3)
celestia:setoverlayelements { Time = true, Velocity = true, Selection = true, Frame = true }
wait (5)


------------------------------------------------------------------------------------------------
- arrows, circle, disk, filledsquare markers / marker alpha, marker label
------------------------------------------------------------------------------------------------
> new symbols to use as markers : circle, disk, filledsquare, uparrow, downarrow, leftarrow, rightarrow.
> new alpha argument to set transparency; must be between 0 (100% transparent) and 1 (100% opaque).
> new label argument to add labels to markers ; labels are added as strings using the fifth argument.

>> Examples:

Code: Select all

-- Title: Mark Xanadu with a red left arrow 50% transparent.

obs = celestia:getobserver()
titan = celestia:find("Sol/Saturn/Titan")
xanadu = celestia:find("Sol/Saturn/Titan/XANADU")

obs:gotolonglat(titan, math.rad(-100), math.rad(-15), 2e4)
celestia:select(xanadu)
celestia:settimescale(1)

celestia:unmarkall()
xanadu:mark( "red", "leftarrow", 70, 0.5)


Code: Select all

--Title: Mark inner planets with labeled colored disks 70% transparent.

celestia:setrenderflags{planets = true, orbits = true}
celestia:setlabelflags{planets = true}

obs = celestia:getobserver()
sol = celestia:find("Sol")
obs:follow(sol)
obs:gotolonglat(sol, math.rad(0), math.rad(90), 1e9)

mercury = celestia:find("Sol/Mercury")
venus = celestia:find("Sol/Venus")
earth = celestia:find("Sol/Earth")
mars = celestia:find("Sol/Mars")

celestia:unmarkall()
mercury:mark( "yellow", "disk", 24, 0.7, mercury:name()..": Planet type = Telluric")
venus:mark( "white", "disk", 60, 0.7, venus:name()..": Planet type = Telluric")
earth:mark( "blue", "disk", 64, 0.7, earth:name()..": Planet type = Telluric")
mars:mark( "red", "disk", 34, 0.7, mars:name()..": Planet type = Telluric")

celestia:settimescale(1e6)


------------------------------------
- star / dso iterators
------------------------------------
> celestia:stars() / celestia:dsos() [Edit on 20/05/07]
convenient for iterating over the entire star/dso databases

>> Example:

Code: Select all

-- Title: Mark all stars of a specific spectral type

function mark_spectraltype(x)
    for star in celestia:stars() do
        first, last = string.find(star:spectraltype(), x, 1, true)
        if first == 1 then
            star:mark("#ff99ff", "circle", 10)
        end
    end
end

spectral = "O"
celestia:flash("Marking all " .. spectral .. " stars.")
mark_spectraltype(spectral)


-----------------------------------------------------------------------
- celestia:getdsocount / celestia:getdso commands
-----------------------------------------------------------------------
> celestia:getdsocount()
Return number of DSOs in the used DSO catalogue.

> celestia:getdso(number:index_number)
Return a dso identified by its index number.


-----------------------------------------------------------------------------------------
- type, hubbletype, catalogNumber, absoluteMagnitude fields for DSOs
-----------------------------------------------------------------------------------------
> object:getinfo().type
Return Type of DSO among "galaxy", "nebula", or "opencluster" (instead of the generic "deepsky" previously returned)

> object:getinfo().hubbletype
Return Hubble Type of galaxies.

> object:getinfo().catalogNumber
Return Catalog Number of DSO.

> object:getinfo().absoluteMagnitude
Return Absolute Magnitude of DSO.

>> Example:

Code: Select all

-- Title: Marks all galaxies according to their Hubble Type.

function mark_galaxy_types()
   for dso in celestia:dso() do
      if dso:getinfo().type == "galaxy" then
         hubbleType = dso:getinfo().hubbleType
         if string.find(hubbleType, "E") then
            dso:mark( "red", "disk", 1, 0.7 )
         elseif string.find(hubbleType, "Irr") then
            dso:mark( "yellow", "disk", 1, 0.7 )
         elseif string.find(hubbleType, "SB") then
            dso:mark( "green", "disk", 1, 0.7 )
         elseif string.find(hubbleType, "S") then
            dso:mark( "blue", "disk", 1, 0.7 )
         end
      end
    end
end

celestia:unmarkall()
celestia:setrenderflags { markers = true }
mark_galaxy_types()


----------------------------------------------------------------------------------------------
- object:localname command [Edit on 10/04/07]
----------------------------------------------------------------------------------------------
> object:localname()
Return localized name of object.
Return "?" if no localization is available.
Note: "Sol", "Milky Way", along with the name of all other stars and DSOs are not localized.

>> Example:

Code: Select all

-- Title: Display the localized name of the current selection.

while true do
   sel = celestia:getselection()
   celestia:print(sel:getinfo().type)
   wait(0)
end


----------------------------------------------------------------------------------------------
- observer:gettrackedobject command [Edit on 16/04/07]
----------------------------------------------------------------------------------------------
> observer:gettrackedobject()
Return the current tracked object for this observer.

>> Example:

Code: Select all

-- Title: Display the name of the current tracked object.

while true do
   obs = celestia:getobserver()
   trackedObjName = obs:gettrackedobject():name()
   if trackedObjName == "?" then
      celestia:print("Press the [T] key to track the current selection.")
   else
      celestia:print(trackedObjName.." is currently tracked.")
   end
   wait(0)
end


----------------------------------------------------------------------------------------------
- celestia:getaltazimuthmode / celestia:setaltazimuthmodecommands [Edit on 18/05/07]
----------------------------------------------------------------------------------------------
> celestia:getaltazimuthmode()
Return true if Alt-Azimuth Mode is enabled, otherwise false.

> celestia:setaltazimuthmode(boolean:enable)
Enable/disable Alt-Azimuth Mode.

>> Example:

Code: Select all

-- Title: Enable Alt-Azimuth Mode.

celestia:setaltazimuthmode(true)


----------------------------------------------------------------------------------------------
- object:setradius command [Edit on 06/07/07]
----------------------------------------------------------------------------------------------
> object:setradius(number)
Set the radius of this object (in km).

>> Example:

Code: Select all

-- Title: Increase the size of Planets for an educational view of our solar system.

function celestia_cleanup_callback()
   sol_children = sol:getchildren()
   for k, child in pairs(sol_children) do
      if child:type() == "planet" then
         child:setradius(iRadius[k])
      end
   end
end

celestia:setorbitflags( { Planet = true } )
celestia:setrenderflags( { planets = true, orbits = true, smoothlines = true } )
celestia:setlabelflags( { planets = true } )
celestia:setminorbitsize(3)

sol = celestia:find("Sol")
celestia:select(sol)
obs = celestia:getobserver()

obs:gotolonglat(sol, 0, 70, 1e10, 5)
wait(5)

sol_children = {}
iRadius = {}

sol_children = sol:getchildren()

for k, child in pairs(sol_children) do
   if child:type() == "planet" then
      iRadius[k] = child:radius()
      child:setradius(iRadius[k] * 2e3)
   end
end
 
while true do
      wait(0)
end


----------------------------------------------------------------------------------------------
- celestia:getgalaxylightgain / celestia:setgalaxylightgain commands [Edit on 13/10/07]
----------------------------------------------------------------------------------------------
> celestia:getgalaxylightgain()
Return the current Galaxy Light Gain value.

> celestia:setgalaxylightgain(number)
Set the Galaxy Light Gain. Can take values between 0 and 1.

>> Example:

Code: Select all

-- Title: Set the Galaxy Light Gain to 50%.

celestia:setgalaxylightgain(0.50)


----------------------------------------------------------------------------------------------
- celestia:setlabelcolor / celestia:setlinecolor commands [Edit on 13/10/07]
----------------------------------------------------------------------------------------------
> celestia:setlabelcolor(string:objectclass, number:red, number:green, number:blue)
Set label colors.
objectclass: String describing the class of objects on which the label color change is applied. Must be one of stars, planets, moons, asteroids, comets, spacecraft, locations, galaxies, nebulae, openclusters, constellations, equatorialgrid.

> celestia:setlabelcolor(string:linetype, number:red, number:green, number:blue)
Set line colors.
linetype: String describing the type of lines on which the color change is applied. Must be one of starorbits, planetorbits, moonorbits, asteroidorbits, cometorbits, spacecraftorbits, constellations, boundaries, equatorialgrid.

>> Example:

Code: Select all

-- Title: Alternate Line and Label Colors from ElChristou.

celestia:setlabelcolor("stars",            0.471, 0.356, 0.682)
celestia:setlinecolor ("starorbits",       0.5, 0.5, 0.8)

celestia:setlabelcolor("planets",          0.407, 0.333, 0.964)
celestia:setlinecolor ("planetorbits",     0.3, 0.323, 0.833)

celestia:setlabelcolor("moons",            0.231, 0.733, 0.792)
celestia:setlinecolor ("moonorbits",       0.08, 0.407, 0.392)

celestia:setlabelcolor("asteroids",        0.596, 0.305, 0.164)
celestia:setlinecolor ("asteroidorbits",   0.58, 0.152, 0.08)

celestia:setlabelcolor("comets",           0.768, 0.607, 0.227)
celestia:setlinecolor ("cometorbits",      0.639, 0.487, 0.168)

celestia:setlabelcolor("spacecraft",       0.93, 0.93, 0.93)
celestia:setlinecolor ("spacecraftorbits", 0.4, 0.4, 0.4)

celestia:setlabelcolor("locations",        0.24, 0.89, 0.43)

celestia:setlabelcolor("galaxies",         0.0, 0.45, 0.5)

celestia:setlabelcolor("nebulae",          0.541, 0.764, 0.278)

celestia:setlabelcolor("openclusters",     0.239, 0.572, 0.396)

celestia:setlabelcolor("constellations",   0.125, 0.167, 0.2)
celestia:setlinecolor ("constellations",   0.0, 0.12, 0.18)

celestia:setlabelcolor("equatorialgrid",   0.095, 0.196, 0.1)
celestia:setlinecolor ("equatorialgrid",   0.07, 0.114, 0.073)

celestia:setlinecolor ("boundaries",       0.1, 0.006, 0.066)


----------------------------------------------------------------------------------------------
- celestia:tdbtoutc / celestia:utctotdb commands [Edit on 13/01/08]
----------------------------------------------------------------------------------------------
> celestia:tdbtoutc(number)
Convert a TDB Julian date (number) to a UTC date (table).
The UTC date is returned as a table containing the keys 'year', 'month', 'day', 'hour', 'minute', 'second' and the respective values.

> celestia:utctotdb(table)
Convert a UTC date (table) to a TDB Julian date (number).

>> Example:

Code: Select all

-- Title: Display UTC Julian Date

while true do
   TDBjd = celestia:gettime()
   UTCdate = celestia:tdbtoutc(TDBjd)
   UTCjd = celestia:tojulianday(UTCdate.year, UTCdate.month, UTCdate.day, UTCdate.hour, UTCdate.minute, UTCdate.seconds)
   celestia:print("UTC Julian date: "..string.format("%0.5f", UTCjd))
   wait(0)
end
Last edited by Vincent on 13.01.2008, 13:58, edited 24 times in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

Post #2by Vincent » 10.04.2007, 16:17

I've edited the post to add the object:localname() command.
Last edited by Vincent on 16.04.2007, 10:53, edited 1 time in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

Post #3by Vincent » 16.04.2007, 10:52

I've edited the first post to add the observer:gettrackedobject() command.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

Post #4by Vincent » 18.05.2007, 19:35

The setaltazimuthmode/getaltazimuthmode commands are now available in celx scripting (cf edit on the 1st post).

PS: Celestia now also correctly displays "Alt-azimuth mode enabled/disabled" when CTRL+F is pressed.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

Post #5by Vincent » 06.07.2007, 19:55

I've added an object:setradius(number) command that allows changing the radius of every object of a solar system (except the star) within a celx script.

You'll find an example of script that displays big planets for an educational view of our solar system in the first post of this thread.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

Post #6by Vincent » 13.10.2007, 09:07

Added new commands:
- to get/set the Galaxy Light Gain (celestia:getgalaxylightgain / celestia:setgalaxylightgain).
- to set line and label colors (celestia:setlabelcolor / celestia:setlinecolor).
(see examples above).
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

Post #7by Vincent » 13.01.2008, 13:43

Added UTC/TDB date conversion commands.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

jjfoerch
Posts: 3
Joined: 10.05.2008
With us: 16 years

Re:

Post #8by jjfoerch » 10.05.2008, 19:54

Vincent wrote:I've added an object:setradius(number) command that allows changing the radius of every object of a solar system (except the star) within a celx script.

You'll find an example of script that displays big planets for an educational view of our solar system in the first post of this thread.

Hello,

This is a fantastic new feature. Any reason why radius of stars cannot be set? I would like to include the sun in a view of the relative sizes of the objects of the solar system.

Thank you,
John Foerch

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years
Location: Rome, ITALY

Re: Re:

Post #9by ANDREA » 10.05.2008, 23:21

jjfoerch wrote:Hello,.... Any reason why radius of stars cannot be set? I would like to include the sun in a view of the relative sizes of the objects of the solar system.
Thank you, John Foerch
Hello John, do you mean something like this?
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

jjfoerch
Posts: 3
Joined: 10.05.2008
With us: 16 years

Re: Re:

Post #10by jjfoerch » 11.05.2008, 17:20

ANDREA wrote:
jjfoerch wrote:Hello,.... Any reason why radius of stars cannot be set? I would like to include the sun in a view of the relative sizes of the objects of the solar system.
Thank you, John Foerch
Hello John, do you mean something like this?
Bye

Andrea :D

Yes, exactly. I found other threads in this forum concerning development of this feature, but nothing very recent. I experimented and found that setradius does not work on stars in Celestia 1.5.1.

Did you achieve this effect by using setradius in a development version of Celestia > 1.5.1, or did you create an object database containing an alternate solar system? I think the setradius approach is cleaner, because then the whole power of Lua is available to dynamically explore any system, not just a predefined one.

John Foerch

Topic author
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 4 months
Location: Nancy, France

Re: New celx commands available in Celestia 1.5.0

Post #11by Vincent » 11.05.2008, 19:01

John,

Indeed, setting the radius of stars is not possible yet via celx scripting.
As a workaround, you can create a .ssc body around the star(s).
You'll find an example of this in 'The Future of our Sun' addon:
viewtopic.php?f=6&t=11593
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
selden
Developer
Posts: 10190
Joined: 04.09.2002
With us: 21 years 8 months
Location: NY, USA

Re: New celx commands available in Celestia 1.5.0

Post #12by selden » 11.05.2008, 19:17

If the radius doesn't have to change, you can set it in the Star's STC file:

Radius 100000

causes the Star to be drawn 200,000 km in diameter.
Selden


Return to “Scripting”