Skip to content
Snippets Groups Projects
Commit bf2ab336 authored by Lucas Philippe's avatar Lucas Philippe
Browse files

Ajout etape 4

parent 58dc5817
Branches
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ class City { ...@@ -6,6 +6,7 @@ class City {
float population; float population;
float density; float density;
float altitude; float altitude;
float radius=0;
// put a drawing function in here and call from main drawing loop } // put a drawing function in here and call from main drawing loop }
public City(String postalcode, String name, float x, float y, float population, float surface, float altitude) { public City(String postalcode, String name, float x, float y, float population, float surface, float altitude) {
...@@ -23,14 +24,19 @@ class City { ...@@ -23,14 +24,19 @@ class City {
float porcentageAlt = map(this.altitude, minAltitude, maxAltitude, 0, 100); float porcentageAlt = map(this.altitude, minAltitude, maxAltitude, 0, 100);
float hue = getColorForAltitude(porcentageAlt); float hue = getColorForAltitude(porcentageAlt);
// Set marker size based on population // Set marker size based on populationxxxx
float size = map(this.population, minPopulation, maxPopulation, 3, 100); radius=map(this.population, minPopulation, maxPopulation, 3, 100);
// Draw marker // Draw marker
fill(hue, 100, 100); fill(hue, 100, 100);
ellipse(x, y, size, size); ellipse(x, y, radius, radius);
} }
boolean contains(int px, int py){
float dist = dist(x, y, px, py);
return dist<radius/2+1;
}
} }
...@@ -15,6 +15,7 @@ City cities[]; ...@@ -15,6 +15,7 @@ City cities[];
int legendsHeight=100; int legendsHeight=100;
int minPopulationToDisplay=10000; int minPopulationToDisplay=10000;
boolean redrawInProgress=false; boolean redrawInProgress=false;
City lastCitySelected=null;
void setup() { void setup() {
size(900,900); size(900,900);
...@@ -145,5 +146,21 @@ void keyPressed() { ...@@ -145,5 +146,21 @@ void keyPressed() {
} }
void mouseMoved() { void mouseMoved() {
println("(x: " + mouseX + ", y: " + mouseY + ")"); //println("(x: " + mouseX + ", y: " + mouseY + ")");
City city = pick(mouseX, mouseY);
if (city != null) {
if (lastCitySelected != city) {
lastCitySelected = city;
println(city.name);
}
}
}
City pick(int px, int py) {
for (int i = totalCount - 1 ; i >= 0; --i) {
if (cities[i].contains(px, py)) {
return cities[i];
}
}
return null;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment