conways_game_of_life: Conways game of life

Usage Arguments Examples

Usage

1

Arguments

x

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
### Simulate
mygrid <- Conway_game_of_life(size = 50, num_reps = 200, prob = c(0.01, 0.99), plot=TRUE)

### Plot the result
x11()
for(i in 1:length(mygrid)) {
  image(mygrid[[i]], main=i, col=c("white", "green"))
  Sys.sleep(0.1)
}

### Plot population sizes over time.
pop <- sapply(mygrid, sum)/length(mygrid[[1]])

x11()
par(mar=c(5,5,1,1))
plot(pop ~ seq(1,length(pop), by=1), xlab="Time", ylab="Population size", cex.axis=1.5, cex.lab=1.5, type="l", col="darkred", lwd=1.5, ylim=c(0,0.5))

### Compare several runs with the same parameters!
reps <- replicate(10, Conway_game_of_life(size = 10, num_reps = 30, prob = c(0.5, 0.5), plot=FALSE), simplify = FALSE)

pops <- sapply(reps, function(x) sapply(x, sum)/length(x[[1]]))

x11()
matplot(seq(1,nrow(pops), by=1), pops, xlab="Time", ylab="Population size", cex.axis=1.5, cex.lab=1.5, type="l", col=rainbow(ncol(pops)), lwd=1.5, ylim=c(0,0.6))

### Create a gif
saveGIF(Conway_game_of_life(size = 50, num_reps = 100, prob = c(0.01, 0.99), plot=TRUE), movie.name = "animation.gif", img.name = "Rplot", convert = "convert",  interval = 0.6)

KIT-IfGG/pets documentation built on May 28, 2019, 12:56 p.m.