int quickMedian(int low, int high)
The return value is the median value.
Finds the median value within the given range of put/get cells.
Please notice that quickMedian works fast for radius values from 1 to 8, but above that it gets very slow. There are much faster algorithms that use tables or histogram for calculating median values with a high radius. There are also slightly faster algorithms for medians with a radius of 1 or 2.
%ffp ctl(7): "Radius", range=(1,15), val=1, page=1 ForEveryTile: { for (y=y_start; y < y_end; y++) for (x=x_start; x < x_end; x++) for (z=0; z < 3; z++) { quickFill(x,y,z,0,ctl(7),0,0,X,Y); pset(x,y,z,quickMedian(0,(ctl(7)*2+1)*(ctl(7)*2+1)-1)); } return true; }