Imma save my code here. Not ready for production use. Easier to read, faster too.
Saving rep_dla refactored code here
#@cli rep_dla : eq. to 'rep_diffusion_limited_aggregation' : (+)
rep_dla_new: rep_diffusion_limited_aggregation_new $*
#@cli rep_diffusion_limited_aggregation: _point_proximity,_escape,_mode,_target={ 0=dark | 1=light },_border,_preserve_binary_image={ 0=maskless | 1=mask }
#@cli : Generate Diffusion Limited Aggregation
#@cli : (eq. to 'rep_dla').\n
#@cli : '_point_proximity' defines how frequently noises are generated based on the proximity of pixels. The lower the number, the higher the density.
#@cli : '_escape' defines how much attempts on filling the aggregation form before finishing.
#@cli : '_mode' defines how particles aggregate on the aggregation form.
#@cli : '_target' defines where the aggregation form will fill on.
#@cli : '_border' is only applicable if there is a planting seed map. It is used to limit particles based on proximity away from existing structure.
#@cli : '_preserve_binary_image' is only applicable on images with variance.
#@cli : Author: Reptorian.
#@cli : Default values: '_point_proximity=2','_escape=10','_mode=1','_target=1','_border=0','_keep_erase_mask=1','[mask]=0'
rep_diffusion_limited_aggregation_new:
skip ${1=2},${2=100},${3=1},${4=0},${5=0},${6=1}
bg,use_altern_text={$4?1:0},{($3%4)==3}
m "dla_target_2s : n 0,1 s. c * midpoint={avg(iM,im)} f. i>$midpoint?1"
m "dla_target_3s : n 0,1 s c add / 3 midpoint={avg(iM,im)} f. i>$midpoint?1"
m "dla_target_4s_plus : n 0,1 ts={s-1} s c add[^-1] /.. $ts * midpoint={avg(iM,im)} f. i>$midpoint?1"
m "dla_target : if s==1 n 0,1 elif s==2 dla_target_2s elif s==3 dla_target_3s elif s>3 dla_target_4s_plus fi"
m "dla_check_variance : tv=0 repeat s sh $> tv+={iv#-1} rm. if $tv break fi done u {$tv?1:0}"
m "dla_clear_image : {w#0},{h#0},1,1,"{$4?0:1}" rv[-1,0] rm."
if $use_altern_text
altern_text_a=altern=int(u(0,2))
altern_text_b=altern=++altern%2
fi
n_threads,border={$_cpus},{round(abs($5))}
mt={$n_threads-1}
foreach {
if s>4||d#0>1 continue fi
+dla_create_coordinate_map $1
gcd_shuffle.
use_dla_map=${dla_check_variance[0]}
if $use_dla_map
dla_target[0]
if !$6
if $4
*[0] .001
else
replace[0] 0,.999
fi
fi
if $border
if $4 +dilate_circ[0] $border
else +erode_circ[0] $border
fi
1,{h},1,1,y
eval[-3] :if(i(#0,I)==i(#-2,I),i(#-1,0,y)=-1);I;
map[-1] [-3]
rv[-3,-1]
rm[-2,-1]
else
if $4 val_check=>.999
else val_check=<.001
fi
1,{h},1,1,y
eval.. :if(!(i(#0,I)$val_check),i(#-1,0,y)=-1;);I;
discard. -1
map. ..
rm..
+distance[-2] {!$4},2
1,{h#-2},1,1,i(#-1,I(#-2))
rm[-2]
pixelsort[-2] +,y,[-1]
rm[-1]
1,{h},1,1,:"begin_t(const n_threads=$n_threads;n=t;);v=n;n+=n_threads;v;"
map. ..
rm..
fi
else
center_x,center_y={[(w#0-1)>>1,(h#0-1)>>1]}
1,{h},1,1,norm(I#-1-[$center_x,$center_y])
pixelsort.. +,y,.
rm.
dla_clear_image
set[0] $bg,50%,50%
fi
a[^0] y
eval[1] :"begin_t(
const width=w#0;
const height=h#0;
const limit_of_attempts=$2;
const pixel_detection_mode=$3%4;
const target_mode=!($4&1);
new_pos_x=[-1, 0, 1,
-1, 1,
-1, 0, 1];
new_pos_y=[-1,-1,-1,
0, 0,
1, 1, 1];
!target_mode?(
pixel_detection_mode==3?(
pixel_detected()=
altern?(
i(#0,xp-1,yp-1,0,0,0,2)<1||
i(#0,xp-1,yp+1,0,0,0,2)<1||
i(#0,xp+1,yp-1,0,0,0,2)<1||
i(#0,xp+1,yp+1,0,0,0,2)<1
):(
i(#0,xp-1,yp,0,0,0,2)<1||
i(#0,xp+1,yp,0,0,0,2)<1||
i(#0,xp,yp-1,0,0,0,2)<1||
i(#0,xp,yp+1,0,0,0,2)<1
);
):
pixel_detection_mode==2?(
pixel_detected()=
i(#0,xp-1,yp-1,0,0,0,2)<1||
i(#0,xp-1,yp+1,0,0,0,2)<1||
i(#0,xp+1,yp-1,0,0,0,2)<1||
i(#0,xp+1,yp+1,0,0,0,2)<1||
i(#0,xp-1,yp,0,0,0,2)<1||
i(#0,xp+1,yp,0,0,0,2)<1||
i(#0,xp,yp-1,0,0,0,2)<1||
i(#0,xp,yp+1,0,0,0,2)<1;
):
pixel_detection_mode==1?(
pixel_detected()=
i(#0,xp-1,yp,0,0,0,2)<1||
i(#0,xp+1,yp,0,0,0,2)<1||
i(#0,xp,yp-1,0,0,0,2)<1||
i(#0,xp,yp+1,0,0,0,2)<1;
):(
pixel_detected()=
i(#0,xp-1,yp-1,0,0,0,2)<1||
i(#0,xp-1,yp+1,0,0,0,2)<1||
i(#0,xp+1,yp-1,0,0,0,2)<1||
i(#0,xp+1,yp+1,0,0,0,2)<1;
);
):(
pixel_detection_mode==3?(
pixel_detected()=
altern?(
i(#0,xp-1,yp-1,0,0,0,2)||
i(#0,xp-1,yp+1,0,0,0,2)||
i(#0,xp+1,yp-1,0,0,0,2)||
i(#0,xp+1,yp+1,0,0,0,2)
):(
i(#0,xp-1,yp,0,0,0,2)||
i(#0,xp+1,yp,0,0,0,2)||
i(#0,xp,yp-1,0,0,0,2)||
i(#0,xp,yp+1,0,0,0,2)
);
):
pixel_detection_mode==2?(
pixel_detected()=
i(#0,xp-1,yp-1,0,0,0,2)||
i(#0,xp-1,yp+1,0,0,0,2)||
i(#0,xp+1,yp-1,0,0,0,2)||
i(#0,xp+1,yp+1,0,0,0,2)||
i(#0,xp-1,yp,0,0,0,2)||
i(#0,xp+1,yp,0,0,0,2)||
i(#0,xp,yp-1,0,0,0,2)||
i(#0,xp,yp+1,0,0,0,2);
):
pixel_detection_mode==1?(
pixel_detected()=
i(#0,xp-1,yp,0,0,0,2)||
i(#0,xp+1,yp,0,0,0,2)||
i(#0,xp,yp-1,0,0,0,2)||
i(#0,xp,yp+1,0,0,0,2);
):(
pixel_detected()=
i(#0,xp-1,yp-1,0,0,0,2)||
i(#0,xp-1,yp+1,0,0,0,2)||
i(#0,xp+1,yp-1,0,0,0,2)||
i(#0,xp+1,yp+1,0,0,0,2);
);
);
"$altern_text_a"
);
temp_vec=I;
xp=temp_vec[0];
yp=temp_vec[1];
repeat(limit_of_attempts,attempts,
if(pixel_detected(),
i(#0,xp,yp)=target_mode;
break();
);
pv=int(u(0,8));
xp+=new_pos_x[pv];
yp+=new_pos_y[pv];
xp%=width;
yp%=height;
"$altern_text_b"
);
[0,0];
"
k[0]
if $use_dla_map&&!$6 round fi
}
um dla_target,dla_target_2s,dla_target_3s,dla_target_4s_plus,dla_create_coordinate_map
+dla_create_coordinate_map:
if $1
row_a={ceil(h/2)}
row_b={h-$row_a}
counts_per_row_a,counts_per_row_b={[w,w+1]>>1}
1,{$row_a*$counts_per_row_a+$row_b*$counts_per_row_b},1,2,:"begin(
const row_length=w#-1;
const half_row_length=row_length>>1;
);
pos_y=int(y/half_row_length);
ny=y<<1;
pos_x=pos_y&1?(ny%row_length):((ny+1)%row_length);
[pos_x,pos_y];
"
else
1,{(w>>1)*(ceil(h/2))},1,2,:"begin(
const row_length=w#-1;
const half_row_length=row_length>>1;
);
y_pos=int(y/half_row_length)<<1;
[(y<<1)%row_length,y_pos];
"
fi
Picture of refactored rep_dla result.

Hmm, it’s interesting how this flows along edge. I never made that feature in mind. Seem like it’s the result of distance-based sorting.
Also, I found that the new version is more beautiful. Here’s the old version result with identical setting.