From 12c414c3e2c0e3fffa0dd88ca89a1542aa1972b1 Mon Sep 17 00:00:00 2001 From: Jdrezen <jeremie.drezen@gmail.com> Date: Tue, 18 May 2021 16:59:37 +0200 Subject: [PATCH] Ajout d'un graphique dans la simulation des fourmis --- ant_example/controleurAntsExample.py | 10 ++++ .../philosophersAmasExample.py | 56 +++++++++---------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/ant_example/controleurAntsExample.py b/ant_example/controleurAntsExample.py index 6416d72..0d9bdf2 100644 --- a/ant_example/controleurAntsExample.py +++ b/ant_example/controleurAntsExample.py @@ -8,9 +8,17 @@ class ControleurAntsExample(Controleur): super().__init__(fenetre, amas) self.__ants = [] self.__numberAnts = nbr_ants + self.__chart = [] + self.__chart.append(self.addPlotChart('Ants Position')) def initialisation(self): + self.setTitle(self.__chart[0], 'Ants Position') + self.setXLabel(self.__chart[0], 'x') + self.setYLabel(self.__chart[0], 'y') + self.setPolicy(self.__chart[0], 0, 'go') + + widthCanvas = self.get_fenetre().get_canvas_width() heightCanvas = self.get_fenetre().get_canvas_height() @@ -23,6 +31,8 @@ class ControleurAntsExample(Controleur): for i in range(len(ants)): x = ants[i].get_dx() y = ants[i].get_dy() + self.addPoint(self.__chart[0], 0, x, y) + color = ants[i].get_color() if color != ants[i].get_old_color(): diff --git a/philosopher_example/philosophersAmasExample.py b/philosopher_example/philosophersAmasExample.py index e69270d..a6369ed 100644 --- a/philosopher_example/philosophersAmasExample.py +++ b/philosopher_example/philosophersAmasExample.py @@ -1,28 +1,28 @@ -from pyAmakCore.classes.tools.amasIHM import AmasIHM - -from philosophersExample import PhilosophersExample -from tableExample import TableExample - - -class PhilosophersAmasExamples(AmasIHM): - - def __init__(self): - super().__init__(TableExample()) - - - def on_initial_agents_creation(self): - ps = [] - for i in range(9): - ps.append(PhilosophersExample(i, self, self.get_environment().get_forks()[i], - self.get_environment().get_forks()[i + 1])) - - ps.append( - PhilosophersExample(9, self, self.get_environment().get_forks()[9], self.get_environment().get_forks()[0])) - - for j in range(len(ps) - 1): - ps[j + 1].add_neighbour(ps[j]) - ps[j].add_neighbour(ps[j + 1]) - - ps[0].add_neighbour(ps[len(ps) - 1]) - ps[len(ps) - 1].add_neighbour(ps[0]) - self.add_agents(ps) \ No newline at end of file +from pyAmakCore.classes.tools.amasIHM import AmasIHM + +from philosophersExample import PhilosophersExample +from tableExample import TableExample + + +class PhilosophersAmasExamples(AmasIHM): + + def __init__(self): + super().__init__(TableExample()) + + + def on_initial_agents_creation(self): + ps = [] + for i in range(9): + ps.append(PhilosophersExample(i, self, self.get_environment().get_forks()[i], + self.get_environment().get_forks()[i + 1])) + + ps.append( + PhilosophersExample(9, self, self.get_environment().get_forks()[9], self.get_environment().get_forks()[0])) + + for j in range(len(ps) - 1): + ps[j + 1].add_neighbour(ps[j]) + ps[j].add_neighbour(ps[j + 1]) + + ps[0].add_neighbour(ps[len(ps) - 1]) + ps[len(ps) - 1].add_neighbour(ps[0]) + self.add_agents(ps) -- GitLab