Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
FRIST P0STgit add *1
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgneves committed Aug 31, 2011
0 parents commit d1e1107
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -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)
98 changes: 98 additions & 0 deletions gift.css
Original file line number Diff line number Diff line change
@@ -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);
}
125 changes: 125 additions & 0 deletions gift.js
Original file line number Diff line number Diff line change
@@ -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);

}
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>

<html>
<head>
<title>Gift countdown</title>
<link rel="stylesheet" type="text/css" href="gift.css" />
<script src="gift.js" type="text/javascript"></script>
</head>
<body onload="setup_gps(38.725259, -9.150040);">
<div id="content">
<div id="distance_label">DISTANCE TO TARGET:</div>
<div id="distance">UNKNOWN</div>
<div id="tracker" class="far"></div>
<div id="text">DEPLOYING GIFT...</div>
<img id="loader" src="loader.gif" />
<img id="pic" src="lolcat.jpg" />
</div>
</body>
</html>
Binary file added loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lolcat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d1e1107

Please sign in to comment.