Mark all stars within a 40ly radius?

All about writing scripts for Celestia in Lua and the .cel system
Topic author
3Deity
Posts: 2
Joined: 12.12.2017
With us: 6 years 11 months

Mark all stars within a 40ly radius?

Post #1by 3Deity » 12.12.2017, 16:06

Can someone provide an example of a working script for this?

I was thinking it could be done by
  • setting initial number to 1 and cycling through all the stars in celestia:getstar()
  • using celestia:getobserver():gedistanceto() star
  • use an if statement to decide whether to mark, i.e. whenever the distance is smaller than 40 million millionths of a light year
  • increment the star number by one and repeat until it reaches 120404

or
  • set celestia:setstardistancelimit(40)
  • cycle through stars in celestia:getstar()
  • if star:visible() is true then mark it
  • increment star number by one until 120404

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Post #2by Cham » 14.12.2017, 03:02

Here's a CELX script that selects all the stars in a radius of 100 LY, relative to your current stellar selection. You can easily edit it to your taste and needs :

Code: Select all

-- Title: All stars inside a sphere of radius 100 LY, centered on your current selection.
-- Mark all stars in a sphere centered on the current selection.

function mark_star_dist(obj, radius)
   for star in celestia:stars() do
      if star:getposition():distanceto(obj:getposition()) <= radius then
         star:mark("yellow", "disk", 1, 1)
      end
   end
end

celestia:unmarkall()
objname = ""
obj = celestia:getselection()

-- Radius of the sphere (in km):
radius = 9.46e14

while true do
   obj = celestia:getselection()
   if obj and objname ~= obj:name() then
      objname = obj:name()
      celestia:unmarkall()
      mark_star_dist(obj, radius)
   end
   wait(0)
end


Save this code in a text file, with the extension .celx, and enjoy!
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Topic author
3Deity
Posts: 2
Joined: 12.12.2017
With us: 6 years 11 months

Post #3by 3Deity » 14.12.2017, 07:46

mark ly.png


When I saw your code I started wondering why I assumed that star in celestia:stars() can't be used here; and went around the world via the approaches I've mentioned instead.

I modified your code to be able to reduce marking down to the stars in between two distances from the selection; 99 and 101 light years from Altair for example. To achieve the result in the thread title, radius1 needs to be set to 0 and radius2 to 40

Code: Select all

-- Title: Mark all stars inside the difference between two spheres of radius 30 and 40 LY, centered on your current selection.

function mark_star_dist(obj, radius1, radius2)
   for star in celestia:stars() do
      if star:getposition():distanceto(obj:getposition()) > radius1 and radius2 >= star:getposition():distanceto(obj:getposition()) then

         --star:unmark()
         star:mark("ffffff", "square", 9, 0.7, star:name(), true)
      end
   end
end

--celestia:unmarkall()
objname = ""
obj = celestia:getselection()

-- Radius of the sphere (in ly / km_to_ly):
radius1 = 30 / 0.00000000000010570
radius2 = 40 / 0.00000000000010570

while true do
   obj = celestia:getselection()
   if obj and objname ~= obj:name() then
      objname = obj:name()
      mark_star_dist(obj, radius1, radius2)
   end
   wait(0)
end


I've left celestia:unmarkall() commented out as to not counteract stacking
By commenting out star:mark(...) and removing the -- from star:unmark() one can swiftly undo previously made markings.


Return to “Scripting”