#!/bin/bash

cat >LICENSE.txt <<\EOF
The GAATI Research Group Logo.

Copyright (C) 2015-2022, Gaetan Bisson. All rights reserved.

Permission to use, copy, and/or distribute the GAATI Research Group Logo
(hereinafter, "the logo"), as depicted by the files in this directory or
in any other form, is hereby granted, provided that:

1. The logo has not been modified in any way.

2. There is no commercial intent behind the use.

3. The use actually refers to the GAATI Research Group.

4. It does not suggest approval by, sponsorship from, or
   affiliation with the GAATI Research Group.

5. Any copy or redistribution is subject to this very license.

Condition 4 can be waived by obtaining explicit permission from
the GAATI Research Group head. See the group website for contact
information:

	https://gaati.org/
EOF

TEX=texput.tex
rm -f $TEX

cat >>$TEX <<\EOF
\documentclass[a4paper]{article}
\usepackage[french]{babel}
\usepackage{beautiful}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}
\begin{scope}[scale=3]
\clip (0,0) circle (1);
\clip (-0.95,-1) rectangle (0.95,1);
EOF

gp -fq >>$TEX <<\EOF
{
	for(p=3,5,
		for(k=1,2*p,
			r=1/cos(Pi/p/2);
			r=r+9/p^6;
			z=r*exp(I*Pi*(k+1/2)/p);
			a=real(z);
			b=imag(z);
			c=sqrt(r^2-1);
			printf("\\draw (%.5f,%.5f) circle (%.5f);\n",a,b,c);
		);
	);
}
EOF

cat >>$TEX <<\EOF
\end{scope}
\node at (-0.06,0.01) {
\fontsize{39}{0}\selectfont$\boldsymbol{\mathbb{
G\mkern-4mu
A\mkern-5mu
A\mkern-6mu
T\mkern-2mu
I
}}$};
\begin{scope}[yshift=-37mm]
\path[postaction={decorate,decoration={
                reverse path,
                text along path,
                text align/center,
                text={|\large\bfseries|E~A~3~8~9~3}
}}] (10:22mm) arc (10:170:22mm);
\end{scope}
\end{tikzpicture}
\end{document}
EOF

lualatex $TEX

pdfcrop -margins 1 texput{,0}.pdf
fatten texput{0,1}.pdf
fatten texput{1,2}.pdf
fatten texput{2,3}.pdf
pdfcrop texput{3,4}.pdf
mv texput4.pdf gaati.pdf
rm texput*

mutool draw -r 300 -o texput.ppm gaati.pdf
gm convert texput.ppm -trim -type Optimize -transparent white texput.png
gm convert texput.png -resize 500x500 gaati-500.png
gm convert texput.png -resize 250x250 gaati-250.png
gm convert texput.png -resize 125x125 gaati-125.png

#cp gaati.pdf ../gaati.pdf
#cp gaati-125.png ../gaati.png

rm -f texput*
