Last active
December 23, 2015 15:19
-
-
Save DmitrySoshnikov/6654918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A simple Time travel machine to the future. | |
* | |
* A theoretical time-traveling to the future | |
* (a very-very-very simplified explanation/application | |
* of the General relativity). | |
* | |
* .allgemeine Relativitätstheorie | |
* | |
* by Dmitry Soshnikov <[email protected]> | |
* MIT Style License | |
*/ | |
// TL;DR: The faster we move, the slower time flows for us | |
// in a relative system. | |
// A relative time "tick". Like a "hammer", it periodically | |
// hits ("ticks") and changes the properties (e.g. age) of who | |
// it's applied to. | |
function timeTick(object) { | |
object.timeHits++; | |
object.timeHandle = setTimeout( | |
timeTick.bind(null, object), | |
object.relativeSpeed | |
); | |
} | |
var aHuman = { | |
// The abstract "timeHits" concept, can be e.g. age | |
// in this human system. | |
timeHits: 0, | |
// A relative speed with which a human "moves" in his | |
// relative system. | |
relativeSpeed: 1 | |
}; | |
var aTimeTraveler = { | |
timeHits: 0, | |
// A time traveler to the future must move *much* faster | |
// (ideally, 99% closely to a speed of light) in order | |
// "to beat" the "time-race". Therefore, his relative | |
// speed is 1000 times faster than the time-tick in this | |
// relative system. | |
relativeSpeed: aHuman.relativeSpeed * 1000 | |
}; | |
// Here we go. | |
timeTick(aHuman); | |
timeTick(aTimeTraveler); | |
console.log("If we fly for 10 years with our super-speed..."); | |
console.log("...let's wait.\n\n") | |
setTimeout(function() { | |
console.log("\n\nTimeout, baby!"); | |
console.log("...then when we will stop:\n\n"); | |
clearTimeout(aHuman.timeHandle); | |
clearTimeout(aTimeTraveler.timeHandle); | |
// Check the relative "hits" (age) changes for aHuman, | |
// and the time traveler. Confirm that we're in the future of | |
// this relative system. lol | |
console.log('aHuman age (and the relative age/year of the system) will be:', aHuman.timeHits, 'years'); | |
console.log('And aTimeTraveler age will be just:', aTimeTraveler.timeHits, 'years'); | |
console.log("\n\nlol. now get back to your physics class."); | |
}, 10000); | |
console.log('"I will look on as time just flies..."'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment