Skip to content
Aravinda VK edited this page Aug 5, 2026 · 3 revisions

Create a grid

//   COLS  ROWS
grid(3,    2);

Grid

(Source)

Create a grid with Gap

//   COLS  ROWS  GAP
grid(3,    2,    gap: 20);

Grid with Gap

(Source)

Create a grid within a given box

//   COLS  ROWS  GAP
grid(3,    2,    gap: 20);
//       X    Y    W    H
gridSize(130, 130, 240, 240); // Creates grid within this box

Grid Position

(Source)

Accessing a Grid cell by its number

//   COLS  ROWS  GAP
grid(3,    2,    gap: 20);
fill("gold");
auto box = gridCell(2);
rect(box); // Same as rect(box.x, box.y, box.width, box.height);

Grid Cell

(Source)

Accessing a Grid area

//   COLS  ROWS  GAP
grid(4,    4,    gap: 20);
fill("gold");
auto box = gridArea(7, 12);
rect(box); // Same as rect(box.x, box.y, box.width, box.height);

Grid Area

(Source)

Creating a named Grid

grid(2, 2, gap: 20);
auto box2 = gridCell(2);

grid("sub", 7, 1);
gridSize("sub", box2.x, box2.y, box2.width, box2.height);

auto colors = [
    "#9400D3",   // Violet
    "#4B0082",   // Indigo
    "#0000FF",   // Blue
    "#00FF00",   // Green
    "#FFFF00",   // Yellow
    "#FF7F00",   // Orange
    "#FF0000"    // Red
];

foreach(i; 0 .. 7)
{
    fill(colors[i]);
    rect(gridCell("sub", i + 1));
}

Named Grid

(Source)

Clone this wiki locally