ds_grid_translate
$$\mathbf{G} = \begin{array}{|c|c|c|c|} \hline \color{#F80}A & \color{#C8F}B & \color{#C8F}C & \color{#C8F}D \\\hline \color{#C8F}E & F & G & H \\\hline \color{#C8F}I & J & K & L \\\hline \color{#C8F}M & N & O & P \\\hline \end{array} \qquad f(\mathbf{G},1,2) = \begin{array}{|c|c|c|c|} \hline L & \color{#C8F}I & J & K \\\hline P & \color{#C8F}M & N & O \\\hline \color{#C8F}D & \color{#F80}A & \color{#C8F}B & \color{#C8F}C \\\hline H & \color{#C8F}E & F & G \\\hline \end{array}$$
- ds_grid_translate(id,horiz,vert)
- Shifts the contents of a grid by a given number of rows and columns.
COPY/// ds_grid_translate(id,horiz,vert)
//
// Shifts the contents of a grid by a given number of rows
// and columns. The contents are shifted so that they wrap
// around to the opposite side of the grid data structure.
//
// id grid data structure, real
// horiz horizontal shift, real
// vert vertical shift, real
//
/// GMLscripts.com/license
{
var dsid,w,h,sx,sy,mx,my,dx,dy,temp;
dsid = argument0;
w = ds_grid_width(dsid);
h = ds_grid_height(dsid);
sx = (((argument1 mod w)+w) mod w);
sy = (((argument2 mod h)+h) mod h);
mx = w-1;
my = h-1;
dx = mx-sx;
dy = my-sy;
temp = ds_grid_create(w,h);
ds_grid_set_grid_region(temp,dsid,0,0,dx,dy,sx,sy);
if (sx>0) ds_grid_set_grid_region(temp,dsid,dx+1,0,mx,dy,0,sy);
if (sy>0) ds_grid_set_grid_region(temp,dsid,0,dy+1,dx,my,sx,0);
if ((sx>0) && (sy>0)) ds_grid_set_grid_region(temp,dsid,dx+1,dy+1,mx,my,0,0);
ds_grid_copy(dsid,temp);
ds_grid_destroy(temp);
return 0;
}
Contributors: Leif902, xot
GitHub: View · Commits · Blame · Raw