SHOW:
|
|
- or go back to the newest paste.
1 | \documentclass[crop=false]{standalone} | |
2 | ||
3 | \usepackage{tikz,xstring,fp} | |
4 | \usetikzlibrary{calc,intersections} | |
5 | ||
6 | %Set dimensions | |
7 | \newcommand\secs{20} % number of side divisions | |
8 | \newcommand\Width{10} % width of page | |
9 | \newcommand\Height{10} % height of page | |
10 | - | \newcommand\edgecut{1} % how many rows to cut of on all edges, like OP |
10 | + | \newcommand\edgecut{1} % how many rows - 1 to cut of on all edges, like OP (1 is no rows) |
11 | ||
12 | \FPeval\nWidth{clip(\Width+2)} | |
13 | \FPeval\nHeight{clip(\Height+2)} | |
14 | ||
15 | \usepackage[paperwidth=\nWidth cm, paperheight=\nHeight cm,margin=.5cm]{geometry} | |
16 | ||
17 | \begin{document} | |
18 | ||
19 | \thispagestyle{empty} | |
20 | ||
21 | \topskip0pt | |
22 | \vspace*{\fill} | |
23 | ||
24 | \begin{center} | |
25 | ||
26 | \begin{tikzpicture} | |
27 | %Mark side intervals | |
28 | \foreach \i in {1,...,\secs}{ | |
29 | \coordinate (b\i) at (\i*\Width/\secs-\Width/\secs,0); | |
30 | \coordinate (r\i) at (\Width,\i*\Height/\secs-\Height/\secs); | |
31 | \coordinate (t\i) at (\Width-\i*\Width/\secs+\Width/\secs,\Height); | |
32 | \coordinate (l\i) at (0,\Height-\i*\Height/\secs+\Height/\secs); | |
33 | } | |
34 | %Mark coordinates | |
35 | \foreach \j in {1,...,\secs}{ | |
36 | \foreach \i in {1,...,\secs}{ | |
37 | \coordinate (br\i-\j) at (intersection of r\i--b1 and b\j--l1); | |
38 | \coordinate (rt\i-\j) at (intersection of t\i--r1 and r\j--b1); | |
39 | \coordinate (tl\i-\j) at (intersection of l\i--t1 and t\j--r1); | |
40 | \coordinate (lb\i-\j) at (intersection of b\i--l1 and l\j--t1); | |
41 | } | |
42 | } | |
43 | %Fill in sections | |
44 | \FPeval\nsecs{clip(\secs-1)} | |
45 | \foreach \i in {\edgecut,...,\nsecs}{ | |
46 | \FPeval\resulti{clip(\i / 2)} | |
47 | \FPeval\ip{clip(\i + 1)} | |
48 | \IfInteger{\resulti}{ | |
49 | \fill[fill=black] (br\i-\secs)--(rt\secs-\i)--(rt\secs-\ip)--(br\ip-\secs); | |
50 | \fill[fill=black] (rt\i-\secs)--(tl\secs-\i)--(tl\secs-\ip)--(rt\ip-\secs); | |
51 | \fill[fill=black] (tl\i-\secs)--(lb\secs-\i)--(lb\secs-\ip)--(tl\ip-\secs); | |
52 | \fill[fill=black] (lb\i-\secs)--(br\secs-\i)--(br\secs-\ip)--(lb\ip-\secs); | |
53 | }{} | |
54 | \foreach \j in {\edgecut,...,\nsecs}{ | |
55 | \FPeval\resultj{clip(\j / 2)} | |
56 | \FPeval\jp{clip(\j + 1)} | |
57 | \IfInteger{\resulti}{ | |
58 | \IfInteger{\resultj}{ | |
59 | \foreach \k in {br,rt,tl,lb}{ | |
60 | \fill[fill=black] (\k\i-\j)--(\k\i-\jp)--(\k\ip-\jp)--(\k\ip-\j); | |
61 | } | |
62 | }{} | |
63 | }{ | |
64 | \IfInteger{\resultj}{}{ | |
65 | \foreach \k in {br,rt,tl,lb}{ | |
66 | \fill[fill=black] (\k\i-\j)--(\k\i-\jp)--(\k\ip-\jp)--(\k\ip-\j); | |
67 | } | |
68 | } | |
69 | } | |
70 | } | |
71 | } | |
72 | %Center box | |
73 | \fill[fill=black] (br\secs-\secs)--(rt\secs-\secs)--(tl\secs-\secs)--(lb\secs-\secs); | |
74 | ||
75 | %To draw whole grid: | |
76 | %\foreach \i in {1,...,\secs}{ | |
77 | % \draw (b1)--(r\i) (r1)--(t\i) (t1)--(l\i) (l1)--(b\i); | |
78 | %} | |
79 | ||
80 | %To draw just bounding box: | |
81 | \draw (0,0)--(\Width,0)--(\Width,\Height)--(0,\Height)--(0,0); | |
82 | ||
83 | \end{tikzpicture} | |
84 | ||
85 | \end{center} | |
86 | ||
87 | \vspace*{\fill} | |
88 | ||
89 | \end{document} |