From 2b045011fb6a535cd39b8568cbd75f57edd32c1b Mon Sep 17 00:00:00 2001 From: Lucas Philippe <lucasphilippe@MacBook-Air-de-Lucas.local> Date: Thu, 4 Apr 2024 11:18:27 +0200 Subject: [PATCH] Ajout etape 2 --- TP5/sketch_240321a/sketch_240321a.pde | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/TP5/sketch_240321a/sketch_240321a.pde b/TP5/sketch_240321a/sketch_240321a.pde index 624d11d..1603126 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(); +} -- GitLab