summaryrefslogtreecommitdiff
path: root/info/drawing-with-metapost/src/closed-fixed-polygon.mp
blob: 793b4fac8bab8e2bda9a5a0a1a1e5abb23474d98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
vardef polygon_with_side(expr n, s) = 
    save a, b, r; numeric a, b, r; 
    a * n = 360; a + 2b = 180; r = s * sind(b) / sind(a);
    for i = 0 upto n-1: (0, r) rotated (a * i) -- endfor cycle
enddef;
for n = 11 downto 3:
    path p; p = polygon_with_side(n, 72);
    fill p withcolor (n/32)[white, 3/4 if odd n: red else: blue fi];
    draw p;
endfor
endfig;
\end{mplibcode}
\end{document}