diff --git a/README b/README new file mode 100644 index 0000000..1255c77 --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +WHA? +=== + +It's just a toy project done to make Carlos Fonseca hunt around for a gift (and soon become disappointed. :P) diff --git a/gift.css b/gift.css new file mode 100644 index 0000000..56c6058 --- /dev/null +++ b/gift.css @@ -0,0 +1,98 @@ +body { + background-color: #000000; + font-family: Arial; + color: #00C2C5; + -webkit-text-stroke-color: #009295; + -webkit-text-stroke-width: 2px; + font-size: 48px; + text-align: center; +} + +#content { + width: 100%; +} + +#tracker { + position: absolute; + top: 50%; + left: 25%; + width: 300px; + height: 300px; + border-radius: 150px; + -webkit-border-radius: 150px; + -webkit-transition: all 1s ease-in-out; +} + +#tracker.far { + background-color: #FF0000; +} + +#tracker.close { + background-color: #0000FF; + -webkit-transform: scale(0.5); +} + +#tracker.closest { + background-color: #00FF00; + -webkit-transform: scale(0.2); +} + +#tracker.bam { + background-color: #FFFFFF; + -webkit-transform: scale(0.05); +} + +#tracker.hidden { + opacity: 0; +} + +#text { + opacity: 0; + -webkit-transition: all 1s ease-in; +} + +#text.show { + opacity: 1; +} + +#loader { + opacity: 0; + -webkit-transition: all 1s ease-in; +} + +#loader.show { + opacity: 1; +} + +#distance_label { + opacity: 1; + -webkit-transition: all 1s ease-in; +} + +#distance_label.hidden { + opacity: 0; +} + +#distance { + opacity: 1; + -webkit-transition: all 1s ease-in; +} + +#distance.hidden { + opacity: 0; +} + +#pic { + position: absolute; + top: 0px; + left: 0px; + opacity: 0; + width: 100%; + -webkit-transform: scale(0.00); + -webkit-transition: all 1s ease-in; +} + +#pic.show { + opacity: 1; + -webkit-transform: scale(1.00); +} \ No newline at end of file diff --git a/gift.js b/gift.js new file mode 100644 index 0000000..cedbd26 --- /dev/null +++ b/gift.js @@ -0,0 +1,125 @@ +var target = [0, 0]; +var watcher = null; + +function ping(distance) { + + var tracker = document.getElementById("tracker"); + var dtext = document.getElementById("distance"); + + var text; + + if(distance > 1) { + text = distance + " km"; + } else { + text = distance * 1000 + " m"; + } + + dtext.innerHTML = text; + + if(distance <= 0.02) { // On tha spot (para um iPhone :P) + tracker.className = "bam"; + setTimeout(deploy_gift, 3000); + return; + } + + if(distance <= 0.05) { // 50m + tracker.className = "closest"; + return; + } + + if(distance <= 0.07) { // 70m + tracker.className = "close"; + return; + } + + tracker.className = "far"; + + +} + +function check_gps(position) { + + var lat = position.coords.latitude; + var lon = position.coords.longitude; + + var R = 6371; /* Raio da Terra, em KM */ + var dLat = (target[0] - lat).toRad(); + var dLon = (target[1] - lon).toRad(); + var s_lat = lat.toRad(); + var t_lat = target[0].toRad(); + + var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(s_lat) * Math.cos(t_lat) + * Math.sin(dLon/2) * Math.sin(dLon/2); + + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); + + var d = R*c; + + ping(d.toPrecisionFixed(8)); +}; + +function setup_gps(t_lat, t_lon) { + + if(typeof(Number.prototype.toRad) === "undefined") { + Number.prototype.toRad = function() { + return this * Math.PI / 180; + } + } + + if (typeof(Number.prototype.toPrecisionFixed) === "undefined") { + Number.prototype.toPrecisionFixed = function(precision) { + if (isNaN(this)) return 'NaN'; + var numb = this < 0 ? -this : this; // can't take log of -ve number... + var sign = this < 0 ? '-' : ''; + + if (numb == 0) { n = '0.'; while (precision--) n += '0'; return n }; // can't take log of zero + + var scale = Math.ceil(Math.log(numb)*Math.LOG10E); // no of digits before decimal + var n = String(Math.round(numb * Math.pow(10, precision-scale))); + if (scale > 0) { // add trailing zeros & insert decimal as required + l = scale - n.length; + while (l-- > 0) n = n + '0'; + if (scale < n.length) n = n.slice(0,scale) + '.' + n.slice(scale); + } else { // prefix decimal and leading zeros if required + while (scale++ < 0) n = '0' + n; + n = '0.' + n; + } + return sign + n; + } + } + + + if(navigator.geolocation) { + watcher = navigator.geolocation.watchPosition(check_gps); + } else { + alert("EPIC FAIL!"); + } + target = [t_lat, t_lon]; + +}; + + +function deploy_gift() { + var tracker = document.getElementById("tracker"); + var text = document.getElementById("text"); + var loader = document.getElementById("loader"); + var pic = document.getElementById("pic"); + var distanceText = document.getElementById("distance"); + var distanceLabel = document.getElementById("distance_label"); + + tracker.className = "hidden"; + distanceText.className = "hidden"; + distanceLabel.className = "hidden"; + text.className = "show"; + loader.className = "show"; + + setTimeout(function() { + text.className = ""; + loader.className = ""; + + setTimeout(function() { + pic.className = "show"; + }, 1000) + }, 3000); + +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..0c39150 --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + + Gift countdown + + + + +
+
DISTANCE TO TARGET:
+
UNKNOWN
+
+
DEPLOYING GIFT...
+ + +
+ + \ No newline at end of file diff --git a/loader.gif b/loader.gif new file mode 100644 index 0000000..fe95089 Binary files /dev/null and b/loader.gif differ diff --git a/lolcat.jpg b/lolcat.jpg new file mode 100644 index 0000000..216fff8 Binary files /dev/null and b/lolcat.jpg differ