Guide
Start from a grid
Go from a plain grid to a finished pattern in five steps.
01 Structure
Make the grid visible
@grid makes a 7 × 7 grid, 60vmin square.
The color after the second slash is the background behind the cells, and _ 2px leaves a gap between them.
background: #fff is plain CSS, applied to every cell.
One number makes a square grid; 4x8 is 4 columns and 8 rows.
@grid: 7 / 60vmin / #333 _ 2px;
background: #fff; 02 Position
Let each cell know where it is
css-doodle runs every declaration once for each cell. @i is the cell's number, from
1 in the top-left, row by row. @i(*7) multiplies it by 7, which gives each cell its own hue.
@grid: 7 / 60vmin / #333 _ 2px;
/* 7°, 14°, 21° … one hue per cell */
background: hsl(@i(*7), 78%, 62%);
@content: @i;
color: #fff; 03 Rhythm
Repeat a sequence of shapes
@pn.cycle(100% 0 0 0) hands out the four rotations of 100% 0 0 0 in order, one per cell,
so each square rounds a different corner and becomes a quarter-circle.
@grid: 7 / 60vmin / #333 _ 2px;
background: hsl(@i(*7), 78%, 62%);
border-radius: @pn.cycle(100% 0 0 0); 04 Variation
Pick at random
@p picks one of its arguments at random for each cell.
Here it picks a color out of three, a corner and a quarter turn.
@r(.82, 1) gives each cell a scale from .82 to 1.
@grid: 7 / 60vmin / #333 _ 2px;
background: @p(#ff5f57, #ff9f1c, #7657ff);
border-radius: @p.cycle(100% 0 0 0);
rotate: @p(0deg, 90deg, 180deg, 270deg);
scale: @r(.82, 1); 05 Selection
Select some cells
A @cell block applies only to the cells its expression matches.
x = y is one diagonal and, on a 7 × 7 grid,
x + y = 8 is the other. Their cells become circles.
@grid: 7 / 60vmin / #333 _ 2px;
background: @p(#ff5f57, #ff9f1c, #7657ff);
border-radius: @p.cycle(100% 0 0 0);
rotate: @p(0deg, 90deg, 180deg, 270deg);
scale: @r(.82, 1);
@cell(x = y, x + y = 8) {
border-radius: 50%;
} Pattern complete
Change it
Try other colors, or another list in @p.cycle().
On a grid of another size, change the 8 in x + y = 8 to the size plus one.