You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

ds_grid_mirror

$$\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(id,horiz,vert)
Rearranges the elements of a given grid by mirroring horizontally and/or vertically.
COPY/// ds_grid_mirror(id,horiz,vert)
//
//  Rearranges the elements of a given grid by mirroring
//  horizontally and/or vertically.
//
//      id          grid data structure, real
//      horiz       true mirrors horizontally, bool
//      vert        true mirrors vertically, bool
//
/// GMLscripts.com/license
{
    var dsid,horiz,vert,w,h,temp;
    dsid = argument0;
    horiz = argument1;
    vert = argument2;
    w = ds_grid_width(dsid);
    h = ds_grid_height(dsid);
    temp = ds_grid_create(w,h);
    if (horiz) {
        for (i=0;i<w;i+=1) {
            ds_grid_set_grid_region(temp,dsid,i,0,i,h-1,w-i-1,0);
        }
        ds_grid_copy(dsid,temp);
    }
    if (vert) {
        for (i=0;i<h;i+=1) {
            ds_grid_set_grid_region(temp,dsid,0,i,w-1,i,0,h-i-1);
        }
        ds_grid_copy(dsid,temp);
    }
    ds_grid_destroy(temp);
    return 0;
}

Contributors: Leif902, xot

GitHub: View · Commits · Blame · Raw