Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • lucas.philippe.etu/philippe-iihm
1 result
Select Git revision
Show changes
Commits on Source (6)
No preview for this file type
...@@ -6,6 +6,8 @@ class City { ...@@ -6,6 +6,8 @@ class City {
float population; float population;
float density; float density;
float altitude; float altitude;
float radius=0;
boolean isHighlighted=false;
// 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 +25,38 @@ class City { ...@@ -23,14 +25,38 @@ 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); float alpha = 80;
ellipse(x, y, size, size); if(isHighlighted){
alpha=255;
}
fill(hue, 100, 100, alpha);
ellipse(x, y, radius, radius);
// Draw city name
if (isHighlighted) {
textSize(16);
textAlign(LEFT, CENTER);
float textWidth = textWidth(name);
float rectWidth = textWidth + 10;
float rectHeight = 20;
fill(255);
rect(x + radius/2 + 5, y - rectHeight/2, rectWidth, rectHeight, 5);
fill(0);
text(name, x + radius/2 + 10, y - 2);
setBasePen();
}
} }
boolean contains(int px, int py){
float dist = dist(x, y, px, py);
return dist<radius/2+1;
}
} }
float getColorForAltitude(float altitude) { float getColorForAltitude(float altitude) {
return map(altitude, 0, 100, 230, -50); return map(altitude, 0, 100, 230, -50);
} }
void setBasePen() {
fill(0);
textSize(12);
}
...@@ -49,6 +49,8 @@ void drawDistributionPopulationLegend(int minPopulation, int maxPopulation, floa ...@@ -49,6 +49,8 @@ void drawDistributionPopulationLegend(int minPopulation, int maxPopulation, floa
} }
} }
fill(220, 100, 100);
// Dessin de l'axe et des barres de l'histogramme // Dessin de l'axe et des barres de l'histogramme
float binWidth = width / numberOfDiv; float binWidth = width / numberOfDiv;
......
...@@ -13,15 +13,28 @@ int y = 2; ...@@ -13,15 +13,28 @@ int y = 2;
City cities[]; City cities[];
int legendsHeight=100; int legendsHeight=100;
int minPopulationToDisplay=10000;
boolean redrawInProgress=false;
City lastCitySelected=null;
void setup() { void setup() {
size(900,900); size(900,900);
colorMode(HSB, 360, 100, 100);
readData(); readData();
noLoop();
} }
void draw(){ void draw(){
background(255); background(255);
for (int i = 0 ; i < totalCount - 2 ; ++i) {
// Draw title
fill(0);
textSize(20);
textAlign(CENTER,CENTER);
text("Afficher les populations supérieures à " + minPopulationToDisplay, width/2, 20);
setBasePen();
for (int i = 0 ; i < totalCount; ++i) {
// draw a point at the coordinates of the city // draw a point at the coordinates of the city
cities[i].draw(); cities[i].draw();
} }
...@@ -30,18 +43,18 @@ void draw(){ ...@@ -30,18 +43,18 @@ void draw(){
// Draw the distribution of the altitude values // Draw the distribution of the altitude values
float[] altitudeValues = new float[cities.length]; float[] altitudeValues = new float[cities.length];
for (int i = 0; i < cities.length - 2; i++) { for (int i = 0; i < totalCount; i++) {
altitudeValues[i] = cities[i].altitude; altitudeValues[i] = cities[i].altitude;
} }
if (legendsHeight > 0) { if (legendsHeight > 0) {
drawLegend(); drawLegend();
} }
redrawInProgress=false;
} }
void readData() { void readData() {
redrawInProgress=true;
String[] lines = loadStrings("./villes.tsv"); String[] lines = loadStrings("./villes.tsv");
// check that the file has been loaded // check that the file has been loaded
...@@ -54,15 +67,22 @@ void readData() { ...@@ -54,15 +67,22 @@ void readData() {
parseInfo(lines[0]); // read the header line parseInfo(lines[0]); // read the header line
cities = new City[totalCount]; ArrayList<City> filteredCities = new ArrayList<City>();
for (int i = 2 ; i < totalCount ; ++i) { for (int i = 2 ; i < totalCount ; ++i) {
String[] columns = split(lines[i], TAB); String[] columns = split(lines[i], TAB);
float pointX = float (columns[x]); float pointX = float (columns[x]);
float pointY = float (columns[y]); float pointY = float (columns[y]);
cities[i-2] = new City(columns[0], columns[4], mapX(pointX), mapY(pointY), float (columns[5]), float (columns[6]), float (columns[7])); // filter the cities
if (float (columns[5]) > minPopulationToDisplay) {
filteredCities.add(new City(columns[0], columns[4], mapX(pointX), mapY(pointY), float (columns[5]), float (columns[6]), float (columns[7])));
}
} }
println("City list created: " + cities.length + " cities");
totalCount = filteredCities.size();
cities = filteredCities.toArray(new City[0]);
println("City list created: " + totalCount + " cities");
} }
...@@ -83,11 +103,11 @@ void parseInfo(String line) { ...@@ -83,11 +103,11 @@ void parseInfo(String line) {
} }
float mapX(float x) { float mapX(float x) {
return map(x, minX, maxX, 0, 800); return map(x, minX, maxX, 50, 800);
} }
float mapY(float y) { float mapY(float y) {
return map(y, maxY, minY, 0, 800); return map(y, maxY, minY, 50, 800);
} }
void drawLegend() { void drawLegend() {
...@@ -95,7 +115,6 @@ void drawLegend() { ...@@ -95,7 +115,6 @@ void drawLegend() {
float distributionY = height - legendsHeight; float distributionY = height - legendsHeight;
float distributionWidth = width - 100; float distributionWidth = width - 100;
float distributionHeight = 50; float distributionHeight = 50;
drawAltitudeLegend(minAltitude, maxAltitude, distributionX, distributionY, distributionWidth, distributionHeight);
// get list of population values from the cities // get list of population values from the cities
float[] populationValues = new float[cities.length]; float[] populationValues = new float[cities.length];
for (int i = 0; i < cities.length - 2; i++) { for (int i = 0; i < cities.length - 2; i++) {
...@@ -104,5 +123,55 @@ void drawLegend() { ...@@ -104,5 +123,55 @@ void drawLegend() {
int numberOfDiv = 30; int numberOfDiv = 30;
// draw the population distribution // draw the population distribution
//drawAltitudeLegend(minAltitude, maxAltitude, distributionX, distributionY, distributionWidth, distributionHeight);
drawDistributionPopulationLegend(minPopulation, maxPopulation, distributionX, distributionY, distributionWidth, distributionHeight, numberOfDiv, populationValues); drawDistributionPopulationLegend(minPopulation, maxPopulation, distributionX, distributionY, distributionWidth, distributionHeight, numberOfDiv, populationValues);
} }
void keyPressed() {
if(redrawInProgress) {
return;
}
int gap=2;
if (key == '+') {
if (minPopulationToDisplay == 0) {
minPopulationToDisplay = 1;
}
minPopulationToDisplay = minPopulationToDisplay * gap;
readData();
} else if (key == '-') {
minPopulationToDisplay = minPopulationToDisplay / gap;
readData();
}
redraw();
}
void mouseMoved() {
City city = pick(mouseX, mouseY);
if (city != null) {
if (lastCitySelected != city) {
if (lastCitySelected != null) {
lastCitySelected.isHighlighted = false;
}
lastCitySelected = city;
//println(city.name);
lastCitySelected.isHighlighted = true;
redraw();
}
} else {
if (lastCitySelected != null) {
lastCitySelected.isHighlighted = false;
lastCitySelected = null;
redraw();
}
}
}
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;
}