wolfram1 <-
function(wolfrule, initialstate, nrows){
# wolfrule is the number of rule
# N is the number of columns/cell
# nrows is the number of rows/steps
if (nargs()<3){nrows<-700}
if (nargs()<2){ncols=700; A<-matrix(0, nrows, ncols);A[1,ncols-1]<-1}
else {
ncols<-length(initialstate)
A<-matrix(0, nrows, ncols); A[1,]<-initialstate;}
ru<-number2binary(wolfrule, 8)
for (i in 2:nrows){
for (j in 1:ncols){
m<-A[i-1,j]
if (j==ncols){
r<-A[i-1,1]
} else {
r<-A[i-1,j+1]
}
if (j==1){
l<-A[i-1,ncols]
} else {
l<-A[i-1,j-1]
}
if (isTRUE(
( l & m & r & ru[1]) |
( l & m &!r & ru[2]) |
( l &!m & r & ru[3]) |
( l &!m &!r & ru[4]) |
(!l & m & r & ru[5]) |
(!l & m &!r & ru[6]) |
(!l &!m & r & ru[7]) |
(!l &!m &!r & ru[8]))) {A[i,j]=1 }
}
}
title1<-"Wolfram Rule: "
title2<-wolfrule
image(t(2-mirror(A, axe = "y")), col = grey(seq(0, 1, length = 2)),
main=paste(title1,title2),
ylab=paste("steps:", nrows), xlab=paste("cells:", ncols), axes=FALSE)
return(A)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.