Purely for fun...

7 years 1 week ago - 7 years 1 week ago #97604 by martinus
Purely for fun... was created by martinus
I coded this up a while back in python for a friend on his birthday. It's intended to be a bit of silly fun and makes some *disturbing* assumptions. Feel free to roll your eyes and tut loudly. ;)
from math import pi, cos, degrees, radians

def birfday(age, deg_lat, length="s"):
    latitude = radians(deg_lat)      #need to convert to rads
    earth_radius = 6371    #km
    year = 365.24
    earthsun_dist = 146000000    #km
    
    orbit = pi*(earthsun_dist*2)
    lat_rad = (earth_radius*2)*cos(latitude)
    diam = (pi*lat_rad)   #Diameter of earth at latitude (perpenducular to the axis of rotation.
    year_trav = diam*year
    
    #Total aproximate distance moved in one year by a person standing on earth staying roughly in the same place ->
    #distance moved by earth around sun x distance moved by rotation of earth
    one_year_dist = orbit + year_trav
    
    # distance travelled by [age] years:
    end_dist = int(age*one_year_dist)    
    lightyr_comp = end_dist/9460730472580.8
    
    # Messages
    if length == "s":   #short message
        out = [("You have travelled somewhere in the region of %dkm since you were born!" % (end_dist)), ("That's about %f light years" % (lightyr_comp))]
    else:     #verbose explaination
        out = [
                   "Given that the mean radius of the earth is 6,371km:",
                   ("The circumference of the earth at your latitude (%f) = pi*6371*2*(cos(%f))" % (deg_lat, deg_lat)),
                   ("Thus you would travel %dkm per day." % (lat_rad)),
                   ("In one year you would travel 365.24*%dkm ~= %dkm on the face of the planet, this doesn't account for the earth's rotation though."% (lat_rad, int(year_trav))),
                   ("Since the earth is around 146,000,000km from the sun, a single, averaged orbit ~= pi*146000000*2 or 917345054.8km"),
                   ("Multiplying distance travelled on the earth's surface by the distance travelled in an orbit around the sun = %dkm."% (int(one_year_dist))),
                   "Finally, we must account for your age.",
                   ("You're currently %d years old so %d times the distance travelled in one year is the actual distance you've travelled." % (age, age)),
                   ("You've travelled %dkm since you were born!" % (end_dist)),
                   "The next time someone tells you that you're going no-where in life tell them how wrong they are..."
                   ]
    return out


if __name__ == "__main__":
    age = 25
    deg_lat = 54.4
    length = "v"
    out = birfday(age, deg_lat, length)
    for line in out:
        print(line)
        
    out = birfday(age, deg_lat, "s")
    for line in out:
        print(line)
    


Example output:

Given that the mean radius of the earth is 6,371km:
The circumference of the earth at your latitude (54.400000) = pi*6371*2*(cos(54.400000))
Thus you would travel 7417km per day.
In one year you would travel 365.24*7417km ~= 8510999km on the face of the planet, this doesn't account for the earth's rotation though.
Since the earth is around 146,000,000km from the sun, a single, averaged orbit ~= pi*146000000*2 or 917345054.8km
Multiplying distance travelled on the earth's surface by the distance travelled in an orbit around the sun = 925856053km.
Finally, we must account for your age.
You're currently 25 years old so 25 times the distance travelled in one year is the actual distance you've travelled.
You've travelled 23146401348km since you were born!
The next time someone tells you that you're going no-where in life tell them how wrong they are...
You have travelled somewhere in the region of 23146401348km since you were born!
That's about 0.002447 light years

Please Log in or Create an account to join the conversation.

7 years 1 week ago #97605 by martinus
Replied by martinus on topic Re: Purely for fun...
I should have added, if you want to mess around with the code without having to install python you can copy and paste the code into the left hand pane on this site: www.compileonline.com/execute_python_online.php

Hit the execute button on the top left to see the result.


If you want to customise it for your location and age find the following section of code near the bottom and edit the age and deg_lat to suit:
if __name__ == "__main__":
    age = 25
    deg_lat = 54.4
The following user(s) said Thank You: michael_murphy, donnellan.brendan

Please Log in or Create an account to join the conversation.

Time to create page: 0.069 seconds
Powered by Kunena Forum