JavaScript
// The probability that a healthy cell will be infected by an adjacent infected cell EACH FRAME.
var infectionProbability = 0.15
// The probability that the infection will mutate on transmission EACH FRAME.
var mutationProbability = 0.00001
// The maximum number of times a cell can be infected by the same infection.
var maxInfections = 3
// The number of frames a cell in infected before it becomes healthy again.
var infectionDuration = 3
// The width and heigh of the board
var size = 400
// The number of cells infected at the beginning.
var startingNum = 4
var imageData, // the visual representation of the board
cells, // array of cells
infectionCount // counter that is incremented whenever a mutation occurs
// Just some colors. The colors are re-used as the number of mutations increases.
var colors = [[255,0,0],[255,255,0],[0,255,0],[0,255,255],[0,0,255],[255,0,255],[128,0,0],[128,128,0],[0,128,0],[0,128,128],[0,0,128],[128,0,128],[255,128,128],[255,255,128],[128,255,128],[128,255,255],[128,128,255],[255,128,255]
]
// when a cell is infected, it isn't contagious until the next frame
function infect(person, infection){
person.infect = true
person.infectionCounts[infection] = (person.infectionCounts[infection] || 0) + 1
person.currentInfection = infection
}
// when a mutation occurs, it is given a number and the counter is incremented
function mutation(){
return infectionCount++
}
function reset(){
cells = []
infectionCount = 0
imageData = T.createImageData(size, size)
// initialize the cells, store them in a grid temporarily and an array for use in each frame
var grid = []
for (var i = 0; i < size; i++){
grid[i] = []
for (var j = 0; j < size; j++){
cells.push(grid[i][j] = {
infectionTime: 0, // how many frames until they are no longer infected, so 0 is healthy
infectionCounts: [], // this stores how many times the cell has been infected by each mutation
neighbors: [] // the neighboring cells
})
}
}
// store the...