Make beautify patterns with arrays
int dim = chi("dim");
int prim;
int pt;
int npt = chi("npt")*dim;
int pts[];
int randn;
int randpt;
for(int i;i<dim;i++){
addprim(0,"polyline");
}
vector2 uniform_num;
for(int i;i<npt;i++){
uniform_num = set(i%dim,i/dim);
pt = addpoint(0,uniform_num);
prim = uniform_num.x;;
addvertex(0,prim,pt);
if(prim == 0){
pts = array(i+1,i+1+dim,i+1-dim);
}else if (prim == dim-1){
pts =array(i-1,i-1+dim,i-1-dim);
}else if (uniform_num.y==0){
pts = array(i+dim,i+dim+1,i+dim-1);
}else if (uniform_num.y == chi("npp")-1){
pts = array(i-dim,i-dim+1,i-dim-1);
}else{
pts =array(i-1,i+1,i+dim+1,i+dim-1,i-dim+1,i-dim+1);
}
if(i == 0){
pts =array(i+dim,i+1,i+dim+1);
}
if (i == dim-1){
pts = array ( i+dim,i-1,i+dim-1);
}
if (i == npt -dim){
pts = array ( i-dim,i+1,i-dim+1);
}
if (i == npt -1){
pts = array ( i-dim,i-1,i-dim-1);
}
int pts_no[];
foreach(int ptn;pts){
if(ptn<i){
append(pts_no,ptn);
}
}
setpointattrib(0,"pts",pt,pts);
setpointattrib(0,"pts_no",pt,pts_no);
randn = floor(len(pts_no)*rand(i));
randpt = pts_no[randn];
setpointattrib(0,"randpt",i,randpt);
}