From 6e7087480642265c5fd9c3be9236f9b9dce71d8b Mon Sep 17 00:00:00 2001
From: Lucas Philippe <lucasphilippe@MacBook-Air-de-Lucas.local>
Date: Thu, 4 Apr 2024 11:57:05 +0200
Subject: [PATCH] ajout etape 5

---
 TP5/sketch_240321a/City.pde           |  7 ++++++-
 TP5/sketch_240321a/sketch_240321a.pde | 13 ++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/TP5/sketch_240321a/City.pde b/TP5/sketch_240321a/City.pde
index 4af5e34..287e73e 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 6155715..ea8a991 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)) {
-- 
GitLab