Astro: Solar System
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BarefootJoey

// ██████████████████████████████████████████████████████████████████████   _____ __   _      _______  _____  _______ _______ _______
// █▄─▄─▀██▀▄─██▄─▄▄▀█▄─▄▄─█▄─▄▄─█─▄▄─█─▄▄─█─▄─▄─███▄─▄█─▄▄─█▄─▄▄─█▄─█─▄█     |   | \  |      |______ |_____] |_____| |       |______
// ██─▄─▀██─▀─███─▄─▄██─▄█▀██─▄███─██─█─██─███─███─▄█─██─██─██─▄█▀██▄─▄██   __|__ |  \_|      ______| |       |     | |_____  |______ 
// █▄▄▄▄██▄▄█▄▄█▄▄█▄▄█▄▄▄▄▄█▄▄▄███▄▄▄▄█▄▄▄▄██▄▄▄██▄▄▄███▄▄▄▄█▄▄▄▄▄██▄▄▄██                                                            

//@version=5
indicator("Astro: Solar System",overlay=true,max_lines_count=500,scale=scale.none)
width     = input.int(40,step=10, minval=40)
spacing   = input.float(4.,minval=1)
thickness = input.int(3)
offset    = input.int(10)
src       = input(close)

orb_col = input.color(color.new(color.gray,100), "Orbit Color")

grp = "🪐 Planets 🪐"
plut_col = input(color.black,'Plu',inline='inline1',group=grp) 
nept_col = input(color.purple,'Nep',inline='inline1',group=grp) //  #366896
uran_col = input(color.blue,'Ura',inline='inline1',group=grp) //  #5580aa
satu_col = input(color.gray,'Sat',inline='inline2',group=grp) //  #e6b01e
jupi_col = input(color.orange,'Jup',inline='inline2',group=grp) //  #f38d52
mars_col = input(color.red,'Mar',inline='inline2',group=grp) //  #b32e06
eart_col = input(color.silver,'Ear',inline='inline3',group=grp) //  #2f6a69
venu_col = input(color.green,'Ven',inline='inline3',group=grp) //  #ffc5c5
merc_col = input(color.maroon,'Mer',inline='inline3',group=grp) //  #854f4f

//------------------------------------------------------------------------------
import BarefootJoey/AstroLib/1 as AL

grtm = "🕜 Time Machine 🕜"
gsd = input.bool(false, "Activate Time Machine", group=grtm)
sdms = input.time(timestamp("2022-04-20T00:00:00"), "Select Date", group=grtm)
gt = gsd ? sdms : time

grol = "🔭 Observer Location 🔭"
htz = input.float(0, "Timezone Hour", step=0.5, inline="2", group=grol)
mtz = input.int(0, "Minute", minval=0, maxval=45, inline="2",  group=grol)
tz = htz + math.round(mtz / 60, 4)
latitude = input.float(0, "Latitude", inline="1", group=grol)
longitude = input.float(0, "Longitude", inline="1", group=grol)
geo = false
geoout = geo ? 1 : 0

day = AL.J2000(AL.JDN(gt, 0, tz))
dayr = AL.J2000(AL.JDN(gt, 1, tz))

//------------------------------------------------------------------------------
n = bar_index+width+offset

lset(l,x1,y1,x2,y2,col,width)=>
    line.set_xy1(l,x1,y1)
    line.set_xy2(l,x2,y2)
    line.set_color(l,col)
    line.set_width(l,width)

var plut_line = array.new_line(0)
var nept_line = array.new_line(0)
var uran_line = array.new_line(0)
var satu_line = array.new_line(0)
var jupi_line = array.new_line(0)
var astb_line = array.new_line(0)
var mars_line = array.new_line(0)
var eart_line = array.new_line(0)
var venu_line = array.new_line(0)
var merc_line = array.new_line(0)

if barstate.isfirst
    for i = 0 to 360 by 10
        array.push(plut_line,line.new(na,na,na,na))
        array.push(nept_line,line.new(na,na,na,na))
        array.push(uran_line,line.new(na,na,na,na))
        array.push(satu_line,line.new(na,na,na,na))
        array.push(jupi_line,line.new(na,na,na,na))
        array.push(astb_line,line.new(na,na,na,na,style=line.style_dotted))
        array.push(mars_line,line.new(na,na,na,na))
        array.push(eart_line,line.new(na,na,na,na))
        array.push(venu_line,line.new(na,na,na,na))
        array.push(merc_line,line.new(na,na,na,na))

l(Line,r,len,col_a,col_b,width_a,width_b)=>
    int prev_x = na
    float prev_y = na
    nl = 0
    for i = 0 to 360 by 10
        x = r*math.sin(math.toradians(i))
        y = r*math.cos(math.toradians(i))
        
        css =  col_a 
        
        lset(array.get(Line,nl),prev_x,prev_y,n+math.round(x),y,
          i > len ? col_b : css,
          i > len ? width_b : width_a)
        
        prev_x := n+math.round(x)
        prev_y := y
        
        nl += 1

//------------------------------------------------------------------------------
angle_plut = AL.getplanet(9,geoout, day, dayr, latitude, longitude,tz)
angle_nept = AL.getplanet(8,geoout, day, dayr, latitude, longitude,tz)
angle_uran = AL.getplanet(7,geoout, day, dayr, latitude, longitude,tz)
angle_satu = AL.getplanet(6,geoout, day, dayr, latitude, longitude,tz)
angle_jupi = AL.getplanet(5,geoout, day, dayr, latitude, longitude,tz)
angle_astb = 360 //AL.getplanet(5,geoout, day, dayr, latitude, longitude,tz)
angle_mars = AL.getplanet(4,geoout, day, dayr, latitude, longitude,tz)
angle_eart = AL.getplanet(3,geoout, day, dayr, latitude, longitude,tz)
angle_venu = AL.getplanet(2,geoout, day, dayr, latitude, longitude,tz)
angle_merc = AL.getplanet(1,geoout, day, dayr, latitude, longitude,tz)
//------------------------------------------------------------------------------
if barstate.islast
    //Circular Plot
    l(plut_line,width,angle_plut,plut_col,orb_col,thickness,1)
    l(nept_line,width-spacing*.8,angle_nept,nept_col,orb_col,thickness,1)
    l(uran_line,width-spacing*1.6,angle_uran,uran_col,orb_col,thickness,1)
    l(satu_line,width-spacing*2.4,angle_satu,satu_col,orb_col,thickness,1)
    l(jupi_line,width-spacing*3.2,angle_jupi,jupi_col,orb_col,thickness,1)
    l(astb_line,width-spacing*4.25,angle_astb,#856c44,orb_col,thickness,1)
    l(mars_line,width-spacing*5.7,angle_mars,mars_col,orb_col,thickness,1)
    l(eart_line,width-spacing*6.4,angle_eart,eart_col,orb_col,thickness,1)
    l(venu_line,width-spacing*7.2,angle_venu,venu_col,orb_col,thickness,1)
    l(merc_line,width-spacing*8,angle_merc,merc_col,orb_col,thickness,1)
    
    label.delete(label.new(n,0,"🌞",color=color.new(color.yellow,100),
      style=label.style_label_center,textcolor=color.white,textalign=text.align_center,size=size.huge)[1])

// EoS made w/ ❤ by @BarefootJoey ✌💗📈