prologues := 3; % make it work with ps2pdf
outputtemplate := "%j-%c.eps"; % better file names

color myblack;

myblack := (.00, .00, .00);

def GoRight =
  j := j + 1;
enddef;

def GoUp =
  i := i + 1;
enddef;

def GoLeft =
  j := j - 1;
enddef;

def GoDown =
  i := i - 1;
enddef;

def Square =
  draw ((0u, 0u) -- (1u, 0u) -- (1u, 1u) -- (0u, 1u) -- cycle) shifted (j * u, i * u); 
enddef;

def Black =
  fill ((0u + s, 0u + s) -- (1u - s, 0u + s) -- (1u - s, 1u - s) -- (0u + s, 1u - s) -- cycle) shifted (j * u, i * u) withcolor myblack; 
enddef;

def BottomRight =
  draw ((0u + s, 0u + s) -- (1u - s, 0u + s) -- (1u - s, 1u - s) -- cycle) shifted (j * u, i * u); 
  fill ((0u + s, 0u + s) -- (1u - s, 0u + s) -- (1u - s, 1u - s) -- cycle) shifted (j * u, i * u) withcolor myblack; 
enddef;

def BottomLeft =
  draw ((0u + s, 0u + s) -- (1u - s, 0u + s) -- (0u + s, 1u - s) -- cycle) shifted (j * u, i * u); 
  fill ((0u + s, 0u + s) -- (1u - s, 0u + s) -- (0u + s, 1u - s) -- cycle) shifted (j * u, i * u) withcolor myblack; 
enddef;

def TopLeft =
  draw ((0u + s, 0u + s) -- (0u + s, 1u - s) -- (1u - s, 1u - s) -- cycle) shifted (j * u, i * u); 
  fill ((0u + s, 0u + s) -- (0u + s, 1u - s) -- (1u - s, 1u - s) -- cycle) shifted (j * u, i * u) withcolor myblack; 
enddef;

def TopRight =
  draw ((1u - s, 1u - s) -- (1u - s, 0u + s) -- (0u + s, 1u - s) -- cycle) shifted (j * u, i * u); 
  fill ((1u - s, 1u - s) -- (1u - s, 0u + s) -- (0u + s, 1u - s) -- cycle) shifted (j * u, i * u) withcolor myblack; 
enddef;

beginfig(1)
  u := 12mm;
  s := 0.05u;

  j := 0;
  i := 0;

  Square BottomRight
  GoRight GoRight
  Square BottomLeft
  GoRight GoRight
  Square TopLeft
  GoRight GoRight
  Square TopRight
  
endfig;

beginfig(2)
  u := 12mm;
  s := 0.05u;

  j := 0;
  i := 0;

  Square BottomLeft GoRight Square Black GoUp Square TopRight GoLeft Square GoDown GoRight GoRight GoRight
  Square TopLeft    GoRight Square Black GoUp Square TopRight GoLeft Square GoDown GoRight GoRight GoRight
  Square TopLeft    GoRight Square Black GoUp Square TopLeft  GoLeft Square GoDown GoRight GoRight GoRight
  Square BottomLeft GoRight Square Black GoUp Square TopLeft  GoLeft Square GoDown GoRight GoRight GoRight
  
endfig;

beginfig(3)
  u := 12mm;
  s := 0.05u;

  j := 0;
  i := 0;

  Square BottomLeft GoRight Square Black    GoRight Square Black    GoUp GoLeft GoLeft
  Square Black      GoRight Square TopRight GoRight Square TopRight GoUp GoLeft GoLeft
  Square Black      GoRight Square TopRight GoRight Square TopRight GoUp GoLeft GoLeft
  
endfig;

end.