diff --git a/malaria.py b/malaria.py index 4325827..8d6b4f9 100644 --- a/malaria.py +++ b/malaria.py @@ -9,12 +9,14 @@ class Model: def __init__(self, width=32, height=32, humandens=0.15, mosquitodens=0.10, immunepct=0.1, mosqinfpct=0.1, hm_infpct=0.5, mh_infpct=0.5, hinfdiepct=0.01, mhungrypct=0.1, humandiepct=10**-3, - mosqdiepct=10**-3, mosqnetdens=0.05, time_steps=2000): + mosqdiepct=10**-3, mosqnetdens=0.05, time_steps=2000, + graphical=True): - plt.ion() self.width = width self.height = height + # Determines if the simulation should be graphical + self.graphical = graphical # The percentage of tiles that start as humans self.humandens = humandens # The percentage of tiles that contain mosquitos @@ -42,9 +44,12 @@ class Model: self.grid = self.gen_humans() self.mosquitos = self.gen_mosquitos() - self.init_draw() + + if self.graphical: + self.init_draw() def init_draw(self): + plt.ion() self.colors = matplotlib.colors.ListedColormap( ["black", "green", "red", "yellow"]) bounds = [Human.DEAD, Human.HEALTHY, Human.INFECTED, Human.IMMUNE] @@ -162,7 +167,10 @@ class Model: """ for t in range(self.time_steps): self.step() - self.draw(t) + if self.graphical: + self.draw(t) + else: + print("Simulating timestep: {}".format(t), end='\r') def step(self): """ @@ -214,6 +222,6 @@ class Human(IntEnum): if __name__ == "__main__": - model = Model() + model = Model(graphical=False) model.run()