diff --git a/TP5/sketch_240321a/City.pde b/TP5/sketch_240321a/City.pde index 4af5e34ce75dc23d3334d4677ae6a609bdd9e80c..287e73eac3af9b125c1617ba01792956db4b839f 100644 --- a/TP5/sketch_240321a/City.pde +++ b/TP5/sketch_240321a/City.pde @@ -7,6 +7,7 @@ class City { float density; float altitude; float radius=0; + boolean isHighlighted=false; // 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) { @@ -28,7 +29,11 @@ class City { radius=map(this.population, minPopulation, maxPopulation, 3, 100); // Draw marker - fill(hue, 100, 100); + float alpha = 80; + if(isHighlighted){ + alpha=255; + } + fill(hue, 100, 100, alpha); ellipse(x, y, radius, radius); } diff --git a/TP5/sketch_240321a/sketch_240321a.pde b/TP5/sketch_240321a/sketch_240321a.pde index 6155715d84d131f14d1b3764b392d80447bdf835..ea8a991437adb24ec72beefe06dd754ce36f93ee 100644 --- a/TP5/sketch_240321a/sketch_240321a.pde +++ b/TP5/sketch_240321a/sketch_240321a.pde @@ -146,16 +146,27 @@ void keyPressed() { } void mouseMoved() { - //println("(x: " + mouseX + ", y: " + mouseY + ")"); 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)) {