Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass[crop=false]{standalone}
- \usepackage{tikz,xstring,fp}
- \usetikzlibrary{calc,intersections}
- %Set dimensions
- \newcommand\secs{20} % number of side divisions
- \newcommand\Width{10} % width of page
- \newcommand\Height{10} % height of page
- \newcommand\edgecut{1} % how many rows - 1 to cut of on all edges, like OP (1 is no rows)
- \FPeval\nWidth{clip(\Width+2)}
- \FPeval\nHeight{clip(\Height+2)}
- \usepackage[paperwidth=\nWidth cm, paperheight=\nHeight cm,margin=.5cm]{geometry}
- \begin{document}
- \thispagestyle{empty}
- \topskip0pt
- \vspace*{\fill}
- \begin{center}
- \begin{tikzpicture}
- %Mark side intervals
- \foreach \i in {1,...,\secs}{
- \coordinate (b\i) at (\i*\Width/\secs-\Width/\secs,0);
- \coordinate (r\i) at (\Width,\i*\Height/\secs-\Height/\secs);
- \coordinate (t\i) at (\Width-\i*\Width/\secs+\Width/\secs,\Height);
- \coordinate (l\i) at (0,\Height-\i*\Height/\secs+\Height/\secs);
- }
- %Mark coordinates
- \foreach \j in {1,...,\secs}{
- \foreach \i in {1,...,\secs}{
- \coordinate (br\i-\j) at (intersection of r\i--b1 and b\j--l1);
- \coordinate (rt\i-\j) at (intersection of t\i--r1 and r\j--b1);
- \coordinate (tl\i-\j) at (intersection of l\i--t1 and t\j--r1);
- \coordinate (lb\i-\j) at (intersection of b\i--l1 and l\j--t1);
- }
- }
- %Fill in sections
- \FPeval\nsecs{clip(\secs-1)}
- \foreach \i in {\edgecut,...,\nsecs}{
- \FPeval\resulti{clip(\i / 2)}
- \FPeval\ip{clip(\i + 1)}
- \IfInteger{\resulti}{
- \fill[fill=black] (br\i-\secs)--(rt\secs-\i)--(rt\secs-\ip)--(br\ip-\secs);
- \fill[fill=black] (rt\i-\secs)--(tl\secs-\i)--(tl\secs-\ip)--(rt\ip-\secs);
- \fill[fill=black] (tl\i-\secs)--(lb\secs-\i)--(lb\secs-\ip)--(tl\ip-\secs);
- \fill[fill=black] (lb\i-\secs)--(br\secs-\i)--(br\secs-\ip)--(lb\ip-\secs);
- }{}
- \foreach \j in {\edgecut,...,\nsecs}{
- \FPeval\resultj{clip(\j / 2)}
- \FPeval\jp{clip(\j + 1)}
- \IfInteger{\resulti}{
- \IfInteger{\resultj}{
- \foreach \k in {br,rt,tl,lb}{
- \fill[fill=black] (\k\i-\j)--(\k\i-\jp)--(\k\ip-\jp)--(\k\ip-\j);
- }
- }{}
- }{
- \IfInteger{\resultj}{}{
- \foreach \k in {br,rt,tl,lb}{
- \fill[fill=black] (\k\i-\j)--(\k\i-\jp)--(\k\ip-\jp)--(\k\ip-\j);
- }
- }
- }
- }
- }
- %Center box
- \fill[fill=black] (br\secs-\secs)--(rt\secs-\secs)--(tl\secs-\secs)--(lb\secs-\secs);
- %To draw whole grid:
- %\foreach \i in {1,...,\secs}{
- % \draw (b1)--(r\i) (r1)--(t\i) (t1)--(l\i) (l1)--(b\i);
- %}
- %To draw just bounding box:
- \draw (0,0)--(\Width,0)--(\Width,\Height)--(0,\Height)--(0,0);
- \end{tikzpicture}
- \end{center}
- \vspace*{\fill}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement