I need create script which will calculate distance between planets,closest planet to the sun might have red color,furthest - blue

I need create script which will calculate distance between planets

  • closest planet to the sun might have red color
  • furthest - blue

In addition, others planets might stay with white color.

I have no idea how to do it. Can someone help me?

And can you explain each of yours step’s
Please