%ffp //------------------------------------------------------------------- // Constants Title: "Color bubblesort" Author: "Martijn W. van der Lee" Category: "VDL Test" Copyright :"Copyleft (L)2001 VanDerLee" URL :"http://www.v-d-l.com" //------------------------------------------------------------------- // Controls ctl(0): CheckBox, "Flip", val = false ctl(1): CheckBox, "Unlimited iterations", val = true ctl(2): "Maximum iterations", range = (0, 1000), val = 1, disabled //------------------------------------------------------------------- // OnCtl OnCtl(n): { if(n == 1) enableCtl(2, ctl(1)? 1 : -1); return false; } //------------------------------------------------------------------- // ForEveryTile ForEveryTile: { const bool FLIP = ctl(0); const bool ITERS = ctl(1)? Y : ctl(2); int a, b, loop, iter; bool sorting; for(x = 0; x < X; ++x) { if(updateProgress(x, X)) abort(); for(z = 0; z < Z; ++z) { loop = Y - 1; iter = 0; sorting = true; while(iter < ITERS && sorting) { sorting = false; a = pget(x, 0, z); for(y = 0;y < loop; ++y) { b = pget(x, y + 1, z); if(FLIP? a < b : a > b) { pset(x, y, z, b); pset(x, y + 1, z, a); sorting = true; } else a = b; } --loop; ++iter; } } } return true; } //-------------------------------------------------------------------