SHOW:
|
|
- or go back to the newest paste.
1 | \documentclass[preview]{standalone} | |
2 | ||
3 | \usepackage{tikz} | |
4 | \usetikzlibrary{calc} %for coordinate calculation | |
5 | \usetikzlibrary{math} %for \tikzmath (thanks to /u/tzjin for the LaTeX Challenge Part 2 where I learned about this!) | |
6 | ||
7 | \begin{document} | |
8 | \begin{tikzpicture} | |
9 | \tikzmath{ | |
10 | \N = 30; %the number of lines to draw per side, more is prettier but 30 is a good number for the challenge (I suggest trying 50 or greater) | |
11 | \L = 10; %width of the side, only affects the output size | |
12 | \d = \L/\N; %distance between line connection points (on both horizontal and vertical axes) | |
13 | \lineW = 0.1; %width of the lines, should be small for the best output | |
14 | \lineopac = 1; %opacity of the lines | |
15 | } | |
16 | ||
17 | \coordinate (LL) at (0,0); %lower left corner | |
18 | \coordinate (LR) at (\L,0); %lower right corner | |
19 | \coordinate (UR) at (\L,\L); %upper right corner | |
20 | \coordinate (UL) at (0,\L); %upper left corner | |
21 | ||
22 | \coordinate (dx) at (\d,0); %for coordinate calculations | |
23 | \coordinate (dy) at (0,\d); %for coordinate calculations | |
24 | ||
25 | \foreach \i in {0,...,\N}{ | |
26 | \draw[draw opacity = \lineopac, line width = \lineW] ($(UL) - \i*(dy)$) -- ($(LL) + \i*(dx)$); | |
27 | \draw[draw opacity = \lineopac, line width = \lineW] ($(LR) + \i*(dy)$) -- ($(UR) - \i*(dx)$); | |
28 | } | |
29 | \end{tikzpicture} | |
30 | \end{document} |