# Day 19
#   __       _              __           _
#  / _\ ___ | | __ _ _ __  / _\_   _ ___| |_ ___ _ __ ___
#  \ \ / _ \| |/ _` | '__| \ \| | | / __| __/ _ \ '_ ` _ \
#  _\ \ (_) | | (_| | |    _\ \ |_| \__ \ ||  __/ | | | | |
#  \__/\___/|_|\__,_|_|    \__/\__, |___/\__\___|_| |_| |_|
#                              |___/

from tkinter import *
import time
import random
import math

# Window
root=Tk()
root.title("I'm a God!")
root.geometry("800x800+0+0")

# Canvas
c=Canvas(root,width=800,height=750,bg="black")
c.pack()

# Extra functions
# _,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,_

# pause function
def toggle_pause():
    global paused
    if paused == True:
        paused = False
    else:
        paused = True

# pause button
pause = Button(root,
               text="⏸︎",
               background="blue",
               foreground="white",
               font=16,
               command = toggle_pause)
pause.place(x=10, y=760)

# sink function
def toggle_sink():
    global sink
    if sink == False:
        sink = True

# sink button
sink = Button(root,
               text="⏻︎",
               background="blue",
               foreground="white",
               font=16,
               command = toggle_sink)
sink.place(x=60, y=760)

# Main function
# _,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,_

paused = False
sink = False
sinkamount = 1

def revolve():

    # center
    centerx = 400
    centery = 375

    # background
    bgimg = PhotoImage(file='phodo/solar-system-bg.png')
    bg = c.create_image(400, 375, image=bgimg)

    # sun
    sunimg = PhotoImage(file='phodo/sun.png').subsample(14,14)
    sun = c.create_image(400, 375, image=sunimg)


    # Earth
    earradius = 150   # distance from sun
    eardegrees = 0    # angle position (0 to 360)
    earx = 0          # x position
    eary = 0          # y position
    earyears = 0
    earthimg = PhotoImage(file='phodo/earth.png').subsample(100,100)
    earth = c.create_image(400, 350, image=earthimg)

    # moon
    moonradius = 20   # distance from sun
    moondegrees = 0    # angle position (0 to 360)
    moonx = 0          # x position
    moony = 0          # y position
    moonyears = 0
    moonimg = PhotoImage(file='phodo/moon.png').subsample(300,300)
    moon = c.create_image(400, 350, image=moonimg)

    # Venus
    venradius = 109
    vendegrees = 0
    venx = 0
    veny = 0
    venyears = 0
    venusimg = PhotoImage(file='phodo/Venus.png').subsample(80,80)
    venus = c.create_image(400, 350, image=venusimg)

    # Mercury
    merradius = 70
    merdegrees = 0
    merx = 0
    mery = 0
    meryears = 0
    mercuryimg = PhotoImage(file='phodo/mercury.png').subsample(80,80)
    mercury = c.create_image(400, 350, image=mercuryimg)

    # Mars
    marradius = 200
    mardegrees=0
    marx=0
    mary=0
    maryears = 0
    marsimg = PhotoImage(file='phodo/mars.png').subsample(80,80)
    mars = c.create_image(400, 350, image=marsimg)

    # Jupiter
    jupradius = 350
    jupdegrees = 0
    jupx=0
    jupy=0
    jupyears = 0
    jupiterimg = PhotoImage(file='phodo/jupiter.png').subsample(1,1)
    jupiter = c.create_image(400, 350, image=jupiterimg)

    interfacetxt = Label(root,
                     text = f"Mercury Years = {meryears}  |  Venus Years = {venyears}  |  Earth Years = {earyears}  |  Mars Years = {maryears}  |  Jupiter Years = {jupyears} ",
                     font="16")
    interfacetxt.place(x=105, y=765)

    while True:
        if not paused:
            # Earth Movement
            #convert degrees to radians for trig functions
            radian = eardegrees/57.2

            # calculate point using Trigonometry !
            earx = earradius * math.sin(radian) - 7
            eary = earradius * math.cos(radian) - 7

            # update Earth position
            c.moveto(earth,centerx+earx,centery+eary)

            # update angle
            eardegrees+=1

            # reset degrees after full circle
            if not sink and eardegrees >=360:
                eardegrees=0
                earyears += 1


            # moon Movement
            #convert degrees to radians for trig functions
            radian = moondegrees/57.2

            # calculate point using Trigonometry !
            x = moonradius * math.sin(radian)
            y = moonradius * math.cos(radian)

            # update Earth position
            c.moveto(moon,centerx+earx+x,centery+eary+y)

            # update angle
            moondegrees+=13

            # reset degrees after full circle
            if moondegrees >=360:
                moondegrees=0


            # Venus Movement
            #convert degrees to radians for trig functions
            radian = vendegrees/57.2

            # calculate point using Trigonometry !
            x = venradius * math.sin(radian) - 7  # to adjust to middle of image (7 is half its length
            y = venradius * math.cos(radian) - 7

            # update Venus position
            c.moveto(venus,centerx+x,centery+y)

            # update angle
            vendegrees+=1.6

            # reset degrees after full circle
            if not sink and vendegrees >=360:
                vendegrees=0
                venyears += 1


            # Mercury Movement
            #convert degrees to radians for trig functions
            radian = merdegrees/57.2

            # calculate point using Trigonometry !
            x = merradius * math.sin(radian) - 2
            y = merradius * math.cos(radian) - 2

            # update Venus position
            c.moveto(mercury,centerx+x,centery+y)

            # update angle
            merdegrees+=4

            # reset degrees after full circle
            if not sink and merdegrees >=360:
                merdegrees=0
                meryears += 1


            # Mars Movement
            #convert degrees to radians for trig functions
            radian = mardegrees/57.2

            # calculate point using Trigonometry !
            x = marradius * math.sin(radian) - 3
            y = marradius * math.cos(radian) - 3

            # update Venus position
            c.moveto(mars,centerx+x,centery+y)

            # update angle
            mardegrees+=0.5

            # reset degrees after full circle
            if not sink and mardegrees >=360:
                mardegrees=0
                maryears += 1


            # Jupiter Movement
            #convert degrees to radians for trig functions
            radian = jupdegrees/57.2

            # calculate point using Trigonometry
            x = jupradius * math.sin(radian) - 90
            y = jupradius * math.cos(radian) - 90

            # update Venus position
            c.moveto(jupiter,centerx+x,centery+y)

            # update angle
            jupdegrees+=0.08

            # reset degrees after full circle
            if not sink and jupdegrees >=360:
                jupdegrees=0
                jupyears += 1

            # SINK INTO THE ABYSS!
            if sink:
                sun = c.create_oval(365, 340, 435, 410, fill="black")

                global sinkamount
                # lower the radius to make each plant closer to the sun
                merradius -= sinkamount
                venradius -= sinkamount
                earradius -= sinkamount
                marradius -= sinkamount
                jupradius -= sinkamount

                # once its zero, get rid of it
                if merradius <= 0:
                   c.delete(mercury)
                if venradius <= 0:
                   c.delete(venus)
                if marradius <= 0:
                   c.delete(mars)
                if earradius <= 0:
                   c.delete(earth)
                   c.delete(moon)
                if jupradius <= 0:
                   c.delete(jupiter)

                sinkamount += 0.1

        interfacetxt.config(text = f"Mercury Years = {meryears}  |  Venus Years = {venyears}  |  Earth Years = {earyears}  |  Mars Years = {maryears}  |  Jupiter Years = {jupyears} ")
        time.sleep(0.01)
        root.update()

revolve()
mainloop()