xxxxxxxxxx
/*
Load current coordinates of the IIS as json-data and mapping on canvas.
February 2017
Ivan Rybakov
*/
var coordinates;
var url = "http://api.open-notify.org/iss-now.json";
var lat;
var lon;
var col;
var stars = [];
function setup(){
frameRate(10);
createCanvas(640, 200);
setInterval(reqData, 5000);
for (var i=0; i<=100; i++){
stars[i] = new Star(0.5, 3);
}
}
function reqData(){
loadJSON(url, gotData, 'jsonp');
}
function gotData(data){
coordinates = data;
console.log(coordinates);
lat = coordinates.iss_position.latitude;
lon = coordinates.iss_position.longitude;
}
function draw(){
background(0);
var x = map(lat, -90,90, 0, width);
var y = map(lon, -180,180, 0,height);
for(var i=0; i<stars.length; i++){
stars[i].showStar();
stars[i].moveStar();
}
if(coordinates){
fill('#FFFF00');
textStyle(BOLD);
text("Track IIS online:", 10, 20);
textStyle(NORMAL);
text("latitude: " + lat, 10, 40);
text("longitude: " + lon, 10, 60);
// text("IIS" + lon, x+10, y-10);
fill('#00FFFF');
ellipse(x, y, 10, 10);
console.log(x, y);
} else {
fill('#FFFF00');
text("Loading data from http://api.open-notify.org...", 10, 20);
}
}
function Star(minSize, maxSize) {
this.x = random(width);
this.y = random(height);
this.minSize = minSize;
this.maxSize = maxSize;
this.size = random(this.minSize, this.maxSize);
this.speed = map(this.size, this.minSize, this.maxSize, 0.01, 2);
this.showStar = function(){
fill(255,255,255);
ellipse(this.x, this.y, this.size, this.size);
}
this.moveStar = function(){
this.x = this.x + this.speed;
if(this.x > width){
this.x = 0;
this.y = random(height);
}
}
}