R,378个 356 346 334字节
f=function(n){r=rep;k=r(0,4);m=r(1,6);L=c();for(i in 1:n)L=cbind(L,r(max(L,0)+2^(n-i):1,e=2^(i-1)));png(w=sum(w<-4*2^(1:n)),h=sum(h<-r(8,2^(n-1))));layout(L,w,h);for(i in 1:max(L)){par(mar=k);image(matrix(c(0,0,0,1,k,0,m,0,0,1,1,1,2,r(1,10),0,0,r(r(c(2,1,2,0),e=2),2),m,k,1,k),nr=8),col=c("#74C460","#6EAA5A",1),ax=F,an=F)};dev.off()}
另存为png文件。缩进,带有换行符:
f=function(n){
r=rep
k=r(0,4)
m=r(1,6)
L=c()
for(i in 1:n)L=cbind(L,r(max(L,0)+2^(n-i):1,e=2^(i-1)))
png(w=sum(w<-4*2^(1:n)),h=sum(h<-r(8,2^(n-1))))
layout(L,w,h)
for(i in 1:max(L)){
par(mar=k)
image(matrix(c(0,0,0,1,k,0,m,0,
0,1,1,1,2,r(1,10),0,
0,r(r(c(2,1,2,0),e=2),2),
m,k,1,k),
nr=8),
col=c("#74C460","#6EAA5A",1),ax=F,an=F)
}
dev.off()
}
N = 2:
N = 3:
N = 4:
一些解释:
这是绘制的矩阵(0代表浅绿色,1代表深绿色,2代表黑色;矩阵是倾斜的,因为列是y轴,行是x轴):
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] 0 0 0 1 0 0 0 0
[2,] 0 1 1 1 2 2 1 0
[3,] 0 1 1 1 2 2 1 0
[4,] 1 1 1 1 1 1 1 1
[5,] 0 1 2 1 1 1 1 0
[6,] 0 1 1 1 2 2 1 0
[7,] 0 1 1 1 2 2 1 0
[8,] 0 0 1 0 0 0 0 0
每次调用以image
绘制该矩阵(每个整数对应一种颜色)。对于N = 4,这里是L(布局矩阵,每个唯一的数字代表一个图),w(矩阵列的宽度)和h(矩阵行的高度):
> L
[,1] [,2] [,3] [,4]
[1,] 8 12 14 15
[2,] 7 12 14 15
[3,] 6 11 14 15
[4,] 5 11 14 15
[5,] 4 10 13 15
[6,] 3 10 13 15
[7,] 2 9 13 15
[8,] 1 9 13 15
> w
[1] 8 16 32 64
> h
[1] 8 8 8 8 8 8 8 8