-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountryPin.js
More file actions
64 lines (60 loc) · 1.94 KB
/
CountryPin.js
File metadata and controls
64 lines (60 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
*Represents a country affected by sea level rise on a 3D globe. Each instance of this class stores a country's name, its geographic coordinates,
and its respective sea level rise.
*/
class CountryPin {
/**
* Constructs a CountryPin object representing a country affected by sea level rise.
*
* @param {string} name - Name of a country.
* @param {number} latitude - Latitude of a country.
* @param {number} longitude - Longitude of a country.
* @param {number} seaLevelRise - The projected sea level rise in cm.
*
* @returns {CountryPin} A new instance of the CountryPin class.
*/
constructor(name, latitude, longitude, seaLevelRise) {
this.name = name;
this.latitude = latitude;
this.longitude = longitude;
this.seaLevelRise = seaLevelRise;
}
/**
* Determines the color representation of the country based on sea level rise.
*
* @returns {string} A color string in RGB format representing the severity of sea level rise.
*/
getColor() {
if (this.seaLevelRise > 10) {
return 'rgb(3, 32, 252)';
}
if (this.seaLevelRise > 5) {
return 'rgb(3, 215, 252)';
}
if (this.seaLevelRise >= 0){
return 'rgb(166, 45, 247)';
}
else{
return 'rgb(186, 247, 45)';
}
}
/**
* Draws the countries' pins to visually represent their respective location and sea level rise data.
*
* @returns {void} Does not return a value.
*/
draw() {
fill(this.getColor());
let lat = radians(90 - this.latitude);
let lon = radians(this.longitude + 90);
let x = 0.5 * sin(lat) * cos(lon);
let y = 0.5 * cos(lat);
let z = 0.5 * sin(lat) * sin(lon);
push();
translate(x, y, z);
sphere(0.01);
pop();
}
}
//makes the class globally accessible
window.CountryPin = CountryPin;