diff --git a/TP5/sketch_240321a/sketch_240321a.pde b/TP5/sketch_240321a/sketch_240321a.pde index 624d11db5c8c4b594ad3154ca2fadecec2090b3e..1603126f29c6f221c0187d37649cce2f93859375 100644 --- a/TP5/sketch_240321a/sketch_240321a.pde +++ b/TP5/sketch_240321a/sketch_240321a.pde @@ -14,10 +14,13 @@ City cities[]; int legendsHeight=100; int minPopulationToDisplay=10000; +boolean redrawInProgress=false; void setup() { size(900,900); + colorMode(HSB, 360, 100, 100); readData(); + noLoop(); } void draw(){ @@ -46,11 +49,11 @@ void draw(){ if (legendsHeight > 0) { drawLegend(); } - - + redrawInProgress=false; } void readData() { + redrawInProgress=true; String[] lines = loadStrings("./villes.tsv"); // check that the file has been loaded @@ -99,11 +102,11 @@ void parseInfo(String line) { } float mapX(float x) { - return map(x, minX, maxX, 0, 800); + return map(x, minX, maxX, 50, 800); } float mapY(float y) { - return map(y, maxY, minY, 0, 800); + return map(y, maxY, minY, 50, 800); } void drawLegend() { @@ -122,3 +125,21 @@ void drawLegend() { //drawAltitudeLegend(minAltitude, maxAltitude, distributionX, distributionY, distributionWidth, distributionHeight); 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(); +}