ぱらぱらめくる『The algorithmic beauty of plants』1 DOLシステム

[1] 2
[1] 1
[1] 2 1
[1] 1 2 1
[1] 2 1 1 2 1
[1] 1 2 1 2 1 1 2 1
 [1] 2 1 1 2 1 1 2 1 2 1 1 2 1
 [1] 1 2 1 2 1 1 2 1 2 1 1 2 1 1 2 1 2 1 1 2 1
 [1] 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 1 2 1 2 1 1 2 1
piece<-c(1,2)
replacer<-NULL
replacer[[1]]<-c(2,1)
replacer[[2]]<-c(1)
x<-NULL

Niter<-10
x<-piece[2]

for(i in 2:Niter){
print(x)
	tmp<-c()
	for(j in 1:length(x)){
		tmp<-c(tmp,replacer[[x[j]]])
	}
	x<-tmp
}
#Development of a filament
L<-c(1,2)
D<-c(-1,1)
piece<-expand.grid(L,D)
font<-c("<-","<--","->","-->")
replacer<-list(c(2),c(1,4),c(4),c(2,3))

Niter<-10
X<-as.list(rep(c(0),Niter))
x<-4
X[[1]]<-x
for(i in 2:Niter){
#print(x)
	tmp<-c()
	for(j in 1:length(x)){
		tmp<-c(tmp,replacer[[x[j]]])
	}
	x<-tmp
	X[[i]]<-x
}
X
printFilament<-function(x,font){
	tmp<-c()
	for(i in 1:length(x)){
		tmp<-paste(tmp,font[x[i]],sep=" ")
	}
	print(tmp)
}
for(i in 1:length(X)){
	printFilament(X[[i]],font)

}