Skip to content

Instantly share code, notes, and snippets.

@santhoshtr
Created February 13, 2026 10:04
Show Gist options
  • Select an option

  • Save santhoshtr/d85515ad5898f7b158968ec9f81daa6e to your computer and use it in GitHub Desktop.

Select an option

Save santhoshtr/d85515ad5898f7b158968ec9f81daa6e to your computer and use it in GitHub Desktop.
Tiling with gray color variations #metapost-sandbox
beginfig(0);
numeric s; s = 10;
%First a basic path (named atom) is defined,
path atom;
atom = origin
-- (2s,0) rotated -30 -- (2s,0) rotated -30 + (0,s)
-- ( s,0) rotated 30 -- ( s,0) rotated 30 + (0,s)
-- (0,2s) -- cycle;
% then in the first loop three picture variables, p1, p2, and p3, are defined
% each one rotated 120° from the previous and
% filled with a slightly darker shade of grey.
picture p[];
for i=0 upto 2:
p[i] = image(
fill atom rotated -120i withcolor (7/8 - 1/8i) ;
draw atom rotated -120i;
);
endfor
pair u, v;
u = point 3 of atom - point 1 of atom rotated -120;
v = u rotated 60;
n = 13;
% The double loop then draws the three
%versions of the shape on an up-and-down grid.
for i=-n upto n:
for j=-n upto n:
forsuffixes $=0,1,2:
draw p$ shifted (i*u + j*v);
endfor
endfor
endfor
% Finally the picture is clipped to a neat rectangle.
clip currentpicture to
unitsquare shifted -(1/2,1/2) scaled 10in yscaled 0.618;
endfig;
% Credits https://tug.ctan.org/info/drawing-with-metapost/Drawing-with-Metapost.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment