ds_grid_mirror
Rearranges the elements of a given grid by mirroring horizontally and/or vertically.
$$\mathbf{G} = \begin{array}{|c|c|} \hline \color{#F80}A&B \\\hline C&D \\\hline E&\color{#C8F}F \\\hline \end{array} \qquad f(\mathbf{G},1,0) = \begin{array}{|c|c|} \hline B&\color{#F80}A \\\hline D&C \\\hline \color{#C8F}F&E \\\hline \end{array} \qquad f(\mathbf{G},0,1) = \begin{array}{|c|c|} \hline E&\color{#C8F}F \\\hline C&D \\\hline \color{#F80}A&B \\\hline \end{array} \qquad f(\mathbf{G},1,1) = \begin{array}{|c|c|} \hline\color{#C8F}F&E \\\hline D&C \\\hline B&\color{#F80}A \\\hline \end{array}$$
NOTE: Mirroring a grid both horizontally and vertically is the same as rotating it 180 degrees.
- ds_grid_mirror(grid, horiz, vert)
- Rearranges the elements of a given grid by mirroring horizontally and/or vertically.
COPY/// @func ds_grid_mirror(grid, horiz, vert)
///
/// @desc Rearranges the elements of a given grid by mirroring
/// horizontally and/or vertically.
///
/// @param {grid} grid grid data structure
/// @param {bool} horiz true mirrors horizontally
/// @param {bool} vert true mirrors vertically
///
/// GMLscripts.com/license
function ds_grid_mirror(grid, horiz, vert)
{
var w = ds_grid_width(grid);
var h = ds_grid_height(grid);
var temp = ds_grid_create(w, h);
if (horiz) {
for (var i=0; i<w; i++) {
ds_grid_set_grid_region(temp, grid, i, 0, i, h-1, w-i-1, 0);
}
ds_grid_copy(grid, temp);
}
if (vert) {
for (var i=0; i<h; i++) {
ds_grid_set_grid_region(temp, grid, 0, i, w-1, i, 0, h-i-1);
}
ds_grid_copy(grid, temp);
}
ds_grid_destroy(temp);
}
Contributors: Leif902, xot
GitHub: View · Commits · Blame · Raw