diff --git a/.DS_Store b/.DS_Store index 5435a7ff2b2edef631fc07ce7147d9366b17f6e0..307682f3aa99e88340e75c2f425f70c3e6cbc164 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/TP5/sketch_240321a/Legends.pde b/TP5/sketch_240321a/Legends.pde index 8c4b5fe07d8c2cd02ddebe14df41732e94431088..68fd3246789212fa9205dc30618df9bcd43efd2f 100644 --- a/TP5/sketch_240321a/Legends.pde +++ b/TP5/sketch_240321a/Legends.pde @@ -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 float binWidth = width / numberOfDiv; diff --git a/TP5/sketch_240321a/sketch_240321a.pde b/TP5/sketch_240321a/sketch_240321a.pde index 9918691014d9d948702e84a22b4108b434cb85e6..624d11db5c8c4b594ad3154ca2fadecec2090b3e 100644 --- a/TP5/sketch_240321a/sketch_240321a.pde +++ b/TP5/sketch_240321a/sketch_240321a.pde @@ -13,6 +13,7 @@ int y = 2; City cities[]; int legendsHeight=100; +int minPopulationToDisplay=10000; void setup() { size(900,900); @@ -21,7 +22,15 @@ void setup() { void draw(){ 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); + textSize(12); + + for (int i = 0 ; i < totalCount; ++i) { // draw a point at the coordinates of the city cities[i].draw(); } @@ -30,7 +39,7 @@ void draw(){ // Draw the distribution of the altitude values 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; } @@ -54,15 +63,22 @@ void readData() { parseInfo(lines[0]); // read the header line - cities = new City[totalCount]; + ArrayList<City> filteredCities = new ArrayList<City>(); for (int i = 2 ; i < totalCount ; ++i) { String[] columns = split(lines[i], TAB); float pointX = float (columns[x]); 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"); + } @@ -95,7 +111,6 @@ void drawLegend() { float distributionY = height - legendsHeight; float distributionWidth = width - 100; float distributionHeight = 50; - drawAltitudeLegend(minAltitude, maxAltitude, distributionX, distributionY, distributionWidth, distributionHeight); // get list of population values from the cities float[] populationValues = new float[cities.length]; for (int i = 0; i < cities.length - 2; i++) { @@ -104,5 +119,6 @@ void drawLegend() { int numberOfDiv = 30; // draw the population distribution + //drawAltitudeLegend(minAltitude, maxAltitude, distributionX, distributionY, distributionWidth, distributionHeight); drawDistributionPopulationLegend(minPopulation, maxPopulation, distributionX, distributionY, distributionWidth, distributionHeight, numberOfDiv, populationValues); }