From 50aa3989d0deffdb1ee9c2e85adad4c07560ded2 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Thu, 24 Jun 2021 08:14:03 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20description=20du=20d=C3=A9roulement=20e?= =?UTF-8?q?t=20premi=C3=A8re=20grilles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grand_rectangle.py | 65 +++++++++++++++++++++++++++++++++++++++++++++ grids.pdf | Bin 0 -> 6317 bytes index.md | 43 ++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 grand_rectangle.py create mode 100644 grids.pdf create mode 100644 index.md diff --git a/grand_rectangle.py b/grand_rectangle.py new file mode 100644 index 0000000..4cbfca6 --- /dev/null +++ b/grand_rectangle.py @@ -0,0 +1,65 @@ +""" +""" + +from random import random +import matplotlib.pyplot as plt +import numpy as np + + +def generate_grid(proportion, n, m=0): + """Generate a grid nxm with random 1 (with proportion) or 0""" + if m == 0: + m = n + return [[int(random() < proportion) for _ in range(m)] for _ in range(n)] + + +def trim_axs(axs, N): + """ + Reduce *axs* to *N* Axes. All further Axes are removed from the figure. + """ + axs = axs.flat + for ax in axs[N:]: + ax.remove() + return axs[:N] + + +def grid_to_image(grids, filename): + """ """ + plt.clf() + n_cols = 3 + n_rows = len(grids) // 3 + axs = plt.figure(constrained_layout=True).subplots(n_rows, n_cols) + axs = trim_axs(axs, len(grids)) + for ax, grid in zip(axs, grids): + # for i, grid in enumerate(grids): + hight = len(grid) + lenght = len(grid[0]) + ax.tick_params(left=False, bottom=False, labelleft=False, labelbottom=False) + ax.imshow(grid, cmap="binary") + ax.hlines( + y=np.arange(0, hight) + 0.5, + xmin=np.full(lenght, 0) - 0.5, + xmax=np.full(lenght, hight) - 0.5, + color="gray", + ) + ax.vlines( + x=np.arange(0, lenght) + 0.5, + ymin=np.full(lenght, 0) - 0.5, + ymax=np.full(lenght, hight) - 0.5, + color="gray", + ) + + plt.savefig(filename) + + +if __name__ == "__main__": + specs = [ + {"proportion": 0.2, "n": 5}, + {"proportion": 0.3, "n": 5}, + {"proportion": 0.2, "n": 8}, + {"proportion": 0.3, "n": 8}, + {"proportion": 0.2, "n": 10}, + {"proportion": 0.3, "n": 10}, + ] + grids = [generate_grid(**spec) for spec in specs] + grid_to_image(grids, "grids.pdf") diff --git a/grids.pdf b/grids.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4926f500d378fd88998bdcf9771b49135a8488d1 GIT binary patch literal 6317 zcmdT}c~}$I7KbXLF^F1xBD7|zf{H>i$z)-Xolpb>SriuvF$)QV1jB$VvWQBxHrOg+ z2`WokL`784s#HMaxm7_CP%02!YafV!R#s(wGa*4rqHX=&AMO1@a_8hM_nv!le&<|_ zJRRw#pc#ZQ%5MZt6=Ohv00_4PW2~$IyeA`w9S#r?iWh+Qi4J1}cn1c|;0uEQYikT! zz(N^m69k;1U}tZb0kZ*UOo%QNzyN7%?#X~*wnzYw(MJs4QzT@1vteKpV#kq==x0a4 z0Ny1Ov1zaPbWnV{0R8~po6BJF1VI30Ox(|7OE8-W15~;4H_HJhZop0;5W?XANElmz z1F{;n03n!<>2MYaBf4i`p~Jfc`{HtYO#6|U)vv7TX$k%oHZ;pr zqOonWX6InwouS^+hQ$=i*LP|i25D;?u$rYK@uaeEZ0^>4PPqOn@3Uhq3>iDHS&g;hXloPMO{jSQ-KOx4Md$DXUD2utAv@ z+e1HcU3kEcme~Bm^VXvaZ^+WFn?BG?>(LMW_7*b@PBvC#OsBI`KZoh_nzV&Yg(0`J{S2Y1e;>NA`S8+jJUA9P z;U`C(1wW6RuS%buRg(Tid~j>XVeQ2)Bwe>x4xD%6KQJb)rqq!{)dN4`rB4%`^I*=# znzWsR!R~h|@+mv&S}b!e#jgp}^4uDDIrW#bJMMo(xi6VAEzcq_%SRjQx$UZLTUEN1 zpT`~MBWP)R$V*K>Cp|0Q>W%Rl52yJ=#+lk`gzN+#`>dFKb>J&X)ty7+61yFbE$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