twop += 1 infectchance += 0.05 * (twop - onep) # 3 squares away thrsquare = simulation.get_surroundings(cell[0], cell[1], 3) thrp = 0 for r in thrsquare: for t in r: if t == (200, 0, 0): thrp += 1 infectchance += 0.02 * (thrp - twop) # cap at 97% if infectchance > 0.97: infectchance = 0.97 # convert to infected if random() < infectchance: simulation.set_cell(cell[0], cell[1], (200, 0, 0)) # every infected cell gets its infected time updated by 1 if simulation.cells[cell] == (200, 0, 0): infectedlife[cell[0]][cell[1]] += 1 # if infected time is 3 days, get cured or die if infectedlife[cell[0]][cell[1]] == 3: infectedlife[cell[0]][cell[1]] = 0 if random() > 0.005: simulation.set_cell(cell[0], cell[1], (0, 200, 0)) else: simulation.set_cell(cell[0], cell[1], (0, 255, 255)) simulation.update() time.sleep(0.1) simulation.end()
sim.set_cell(cell[0], cell[1], SIRD[2]) while not done: done = sim.process_events() if setup==False: for i in range(0, 300): sim.set_cell(randint(0, 60), randint(0,40), SIRD[randint(0,1)]) setup=True if time!=0: for cell in sim.cells: InfectionPercent=0 color = sim.get_cell(cell[0], cell[1]) if color==SIRD[0]: InfectionPercent=sweep(cell, InfectionPercent) Infected(cell, InfectionPercent) time-=1 elif time==0: for cell in sim.cells: color = sim.get_cell(cell[0], cell[1]) if color==SIRD[1]: Dead = DeathChance(cell, Death) if Dead==False: Recovery(cell, RecoveryRate) time=3 sim.update() sim.end()