ajout representation construits
108
representation_construits/chapitre_1/tp/README.md
Normal file
@@ -0,0 +1,108 @@
|
||||
---
|
||||
title : Les Drapeaux
|
||||
author: M. BODDAERT
|
||||
license: CC-BY-NC-SA
|
||||
---
|
||||
# TP : Les Drapeaux
|
||||
|
||||
<img src='./assets/france.png'/>
|
||||
|
||||
Fig 1. Drapeau français
|
||||
|
||||
## 1. Contexte
|
||||
|
||||
Un drapeau peut être vu comme une matrice, i.e un tableau de tableaux, de dimension $n \times m$.
|
||||
|
||||
Soient les codes couleurs suivants :
|
||||
|
||||
| Code | Couleur associée |
|
||||
| :--: | :----------------: |
|
||||
| 0 | NOIR |
|
||||
| 1 | ROUGE |
|
||||
| 2 | VERT |
|
||||
| 3 | JAUNE |
|
||||
| 4 | BLEU |
|
||||
| 5 | MAGENTA |
|
||||
| 6 | CYAN |
|
||||
| 7 | BLANC |
|
||||
|
||||
Il est dès lors possible de représenter le drapeau français de la Fig.1 , en python, par la matrice $15 \times 7$ suivante :
|
||||
|
||||
```python
|
||||
>>> drapeau = [
|
||||
[4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1],
|
||||
[4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1],
|
||||
[4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1],
|
||||
[4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1],
|
||||
[4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1],
|
||||
[4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1],
|
||||
[4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1]
|
||||
]
|
||||
```
|
||||
|
||||
En utilisant le formalisme par compréhension :
|
||||
|
||||
```python
|
||||
>>> drapeau = [ [4] * 5 + [7] * 5 + [1] * 5 for _ in range(7)]
|
||||
```
|
||||
|
||||
Ce formalisme compact traduit le fait que le drapeau français est constitué de ***5 cases bleues, 5 cases blanches et 5 cases rouges, et cela sur 7 lignes***.
|
||||
|
||||
## 2. Matériel fourni
|
||||
|
||||
Le module `paint` dispose de :
|
||||
|
||||
- 8 variables : `NOIR, ROUGE, VERT, JAUNE, BLEU, MAGENTA, CYAN, BLANC`, qui permettent de matérialiser les couleurs,
|
||||
- d'une méthode `dessiner` qui permet d'afficher un drapeau, à partir d'une matrice passée en paramètre, dans la console de l'interpréteur python.
|
||||
|
||||
<figure>
|
||||
<center><img src='./assets/utilisation_paint.png'/></center>
|
||||
<figcaption style='text-align:center;'>Fig 2. Exemple d'utilisation du module paint</figcaption>
|
||||
</figure>
|
||||
|
||||
## 3. Consignes
|
||||
|
||||
Vous devez créer un module `drapeau`.
|
||||
|
||||
Pour chaque drapeau de la liste fournie en Annexe, vous devez :
|
||||
|
||||
- Formaliser la matrice modélisant le drapeau,
|
||||
|
||||
- Identifier la structure algorithmique,
|
||||
|
||||
- Écrire une fonction, dans le module `drapeau` qui permette de créer la matrice modélisant le drapeau.
|
||||
|
||||
***N.B : Vous devez utiliser le formalisme par compréhension ou l'utilisation de boucle mais il est interdit d'utiliser l'affectation par valeur, case par case.***
|
||||
|
||||
Le module sera exécutable de la manière suivante :
|
||||
|
||||
> python3 drapeau.py france
|
||||
|
||||
Le résultat attendu étant l'affichage du drapeau du pays passé en paramètre.
|
||||
|
||||
## 4. Annexe : Liste des pays et drapeaux
|
||||
|
||||
| Pays | Drapeau | Consigne |
|
||||
| :--: | :--: | :-- |
|
||||
| Belgique | <img src='./assets/belgique.png'/> | Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Pays-Bas |<img src='./assets/pays_bas.png'/> | Le drapeau est de dimension $ 15 \times 6$ |
|
||||
| Suède | <img src='./assets/suede.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Finlande | <img src='./assets/finlande.png'/> | Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Irlande | <img src='./assets/irlande.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Côte d'Ivoire |<img src='./assets/cote_ivoire.png'/> | Vous devez utiliser la fonction de création du drapeau d'Irlande. |
|
||||
| Bénin | <img src='./assets/benin.png'/>| Le drapeau est de dimension $ 15 \times 6$ |
|
||||
| Suisse | <img src='./assets/suisse.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Guinée | <img src='./assets/guinee.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Mali |<img src='./assets/mali.png'/> | Vous devez utiliser la fonction de création du drapeau de Guinée. |
|
||||
| Botswana | <img src='./assets/botswana.png'/> | Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Monaco | <img src='./assets/monaco.png'/>| Le drapeau est de dimension $ 15 \times 6$ |
|
||||
| Pologne | <img src='./assets/pologne.png'/>| Vous devez utiliser la fonction de création du drapeau de Monaco. |
|
||||
| Japon | <img src='./assets/japon.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Hongrie | <img src='./assets/hongrie.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Iran | <img src='./assets/iran.png'/>| Vous devez utiliser la fonction de création du drapeau de Hongrie. |
|
||||
| Palaos | <img src='./assets/palaos.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Grèce |<img src='./assets/grece.png'/> | Le drapeau est de dimension $ 15 \times 6$ |
|
||||
| Etats-Unis |<img src='./assets/etats_unis.png'/> | Le drapeau est de dimension $ 15 \times 6$ |
|
||||
| République du Congo | <img src='./assets/republique_congo.png'/>| Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Trinidad et Tobago |<img src='./assets/trinidad.png'/> | Le drapeau est de dimension $ 15 \times 7$ |
|
||||
| Jamaique |<img src='./assets/jamaique.png'/> | Le drapeau est de dimension $ 15 \times 7$ |
|
||||
BIN
representation_construits/chapitre_1/tp/assets/belgique.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/benin.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
representation_construits/chapitre_1/tp/assets/botswana.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
representation_construits/chapitre_1/tp/assets/cote_ivoire.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/etats_unis.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
representation_construits/chapitre_1/tp/assets/finlande.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
representation_construits/chapitre_1/tp/assets/france.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/grece.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/guinee.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/hongrie.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
representation_construits/chapitre_1/tp/assets/iran.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
representation_construits/chapitre_1/tp/assets/irlande.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/jamaique.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
representation_construits/chapitre_1/tp/assets/japon.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
representation_construits/chapitre_1/tp/assets/mali.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/monaco.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
representation_construits/chapitre_1/tp/assets/palaos.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
representation_construits/chapitre_1/tp/assets/pays_bas.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
representation_construits/chapitre_1/tp/assets/pologne.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
BIN
representation_construits/chapitre_1/tp/assets/suede.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
representation_construits/chapitre_1/tp/assets/suisse.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
representation_construits/chapitre_1/tp/assets/trinidad.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 21 KiB |
276
representation_construits/chapitre_1/tp/correction.py
Normal file
@@ -0,0 +1,276 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding : utf-8 -*-
|
||||
# Author : Philippe BODDAERT
|
||||
# Date : 28/12/2020
|
||||
# License : CC-BY-NC-SA
|
||||
''' Module de génération de Drapeaux '''
|
||||
|
||||
import sys, copy
|
||||
from paint import NOIR, ROUGE, VERT, JAUNE, BLEU, CYAN, BLANC, dessiner
|
||||
|
||||
def miroir_vertical(matrice):
|
||||
'''
|
||||
Inverse une matrice verticalment
|
||||
'''
|
||||
for ligne in matrice:
|
||||
ligne.reverse()
|
||||
|
||||
def miroir_horizontal(matrice):
|
||||
'''
|
||||
Inverse une matrice horizontalment
|
||||
'''
|
||||
matrice.reverse()
|
||||
|
||||
def creer_drapeau_france():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la France
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [ [BLEU] * 5 + [BLANC] * 5 + [ROUGE] * 5 for _ in range(7)]
|
||||
|
||||
def creer_drapeau_irlande():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de l'Irlande
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [ [VERT] * 5 + [BLANC] * 5 + [ROUGE] * 5 for _ in range(7)]
|
||||
|
||||
def creer_drapeau_cote_ivoire():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Côte d'Ivoire
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
drapeau = creer_drapeau_irlande()
|
||||
miroir_vertical(drapeau)
|
||||
return drapeau
|
||||
|
||||
def creer_drapeau_belgique():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Belgique
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [ [NOIR] * 5 + [JAUNE] * 5 + [ROUGE] * 5 for _ in range(7)]
|
||||
|
||||
def creer_drapeau_pays_bas():
|
||||
'''
|
||||
Génère la matrice relative au drapeau des Pays-Bas
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [[BLEU] * 15] * 2 + [[BLANC] * 15] * 2 + [[ROUGE] * 15] * 2
|
||||
|
||||
def creer_drapeau_suede():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Suède
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
bloc = [[BLEU] * 4 + [JAUNE] * 2 + [BLEU] * 9] * 3
|
||||
|
||||
return bloc + [[JAUNE] * 15] + bloc
|
||||
|
||||
def creer_drapeau_finlande():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Finlande
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
bloc = [[BLANC] * 4 + [BLEU] * 2 + [BLANC] * 9] * 3
|
||||
return bloc + [[BLEU] * 15] + bloc
|
||||
|
||||
def creer_drapeau_guinee():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Guinée
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [ [ROUGE] * 5 + [JAUNE] * 5 + [VERT] * 5 for _ in range(7)]
|
||||
|
||||
def creer_drapeau_mali():
|
||||
'''
|
||||
Génère la matrice relative au drapeau du Mali
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
drapeau = creer_drapeau_guinee()
|
||||
miroir_vertical(drapeau)
|
||||
return drapeau
|
||||
|
||||
def creer_drapeau_monaco():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de Monaco
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [[ROUGE] * 15] * 3 + [[BLANC] * 15] * 3
|
||||
|
||||
def creer_drapeau_pologne():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Pologne
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
drapeau = creer_drapeau_monaco()
|
||||
miroir_horizontal(drapeau)
|
||||
return drapeau
|
||||
|
||||
def creer_drapeau_hongrie():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Hongrie
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [[ROUGE] * 15] * 2 + [[BLANC] * 15] * 2 + [[VERT] * 15] * 2
|
||||
|
||||
def creer_drapeau_iran():
|
||||
'''
|
||||
Génère la matrice relative au drapeau d'Iran
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
drapeau = creer_drapeau_hongrie()
|
||||
miroir_horizontal(drapeau)
|
||||
return drapeau
|
||||
|
||||
def creer_drapeau_rc():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la République du Congo
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
drapeau = []
|
||||
for i in range(7):
|
||||
drapeau.append([VERT] * (12 - (i * 2)) + [JAUNE] * 3 + [ROUGE] * (i * 2))
|
||||
return drapeau
|
||||
|
||||
def creer_drapeau_trinidad():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de Trinidad et Tobago
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
drapeau = []
|
||||
for i in range(7):
|
||||
drapeau.append([ROUGE] * (7 - i) + [BLANC] + [NOIR] * 4 + [BLANC] + [ROUGE] * (i + 2))
|
||||
miroir_vertical(drapeau)
|
||||
return drapeau
|
||||
|
||||
def creer_drapeau_etats_unis():
|
||||
'''
|
||||
Génère la matrice relative au drapeau des Etats-Unis
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return ([[BLEU, BLANC] * 3 + [BLEU] + [ROUGE] * 8] +
|
||||
[[BLEU, BLEU, BLANC, BLEU, BLANC, BLEU, BLEU] + [BLANC] * 8] +
|
||||
[[BLEU, BLANC] * 3 + [BLEU] + [ROUGE] * 8] +
|
||||
[[BLANC] * 15] + [[ROUGE] * 15] + [[BLANC] * 15])
|
||||
|
||||
def creer_drapeau_benin():
|
||||
'''
|
||||
Génère la matrice relative au drapeau du Bénin
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return [[VERT] * 6 + [JAUNE] * 9 ] * 3 + [[VERT] * 6 + [ROUGE] * 9 ] * 3
|
||||
|
||||
def creer_drapeau_botswana():
|
||||
'''
|
||||
Génère la matrice relative au drapeau du Botswana
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
haut = [[CYAN] * 15] * 2 + [[BLANC] * 15]
|
||||
bas = haut.copy()
|
||||
miroir_horizontal(bas)
|
||||
return haut + [[NOIR] * 15] + bas
|
||||
|
||||
def creer_drapeau_grece():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Grèce
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
return ([[BLEU] * 2 + [BLANC] + [BLEU] * 2 + [BLANC] * 10] +
|
||||
[[BLANC] * 5 + [BLEU] * 10] +
|
||||
[[BLEU] * 2 + [BLANC] + [BLEU] * 2 + [BLANC] * 10] +
|
||||
[[BLEU] * 15] + [[BLANC] * 15] + [[BLEU] * 15])
|
||||
|
||||
def creer_drapeau_suisse():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Suisse
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
haut = [[ROUGE] * 15] + [[ROUGE] * 6 + [BLANC] * 3 + [ROUGE] * 6] * 2
|
||||
bas = haut.copy()
|
||||
miroir_horizontal(bas)
|
||||
return haut + [[ROUGE] * 3 + [BLANC] * 9 + [ROUGE] * 3] + bas
|
||||
|
||||
def creer_drapeau_japon():
|
||||
'''
|
||||
Génère la matrice relative au drapeau du Japon
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
haut = ([[BLANC] * 15] +
|
||||
[[BLANC] * 6 + [ROUGE] * 3 + [BLANC] * 6 ] +
|
||||
[[BLANC] * 4 + [ROUGE] * 7 + [BLANC] * 4 ])
|
||||
bas = haut.copy()
|
||||
miroir_horizontal(bas)
|
||||
return haut + [[BLANC] * 3 + [ROUGE] * 9 + [BLANC] * 3 ] + bas
|
||||
|
||||
def creer_drapeau_jamaique():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la Jamaique
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
haut = [[JAUNE] * 2 + [VERT] * 11 + [JAUNE] * 2,
|
||||
[NOIR] * 2 + [JAUNE] * 2 + [VERT] * 7 + [JAUNE] * 2 + [NOIR] * 2,
|
||||
[NOIR] * 4 + [JAUNE] * 2 + [VERT] * 3 + [JAUNE] * 2 + [NOIR] * 4]
|
||||
bas = haut.copy()
|
||||
miroir_horizontal(bas)
|
||||
return haut + [[NOIR] * 6 + [JAUNE] * 3 + [NOIR] * 6] + bas
|
||||
|
||||
def creer_drapeau_palaos():
|
||||
'''
|
||||
Génère la matrice relative au drapeau du Palaos
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
haut = [[CYAN] * 15] + [[CYAN] * 5 + [JAUNE] * 3 + [CYAN] * 7 ] + [[CYAN] * 3 + [JAUNE] * 7 + [CYAN] * 5 ]
|
||||
bas = haut.copy()
|
||||
miroir_horizontal(bas)
|
||||
return haut + [[CYAN] * 2 + [JAUNE] * 9 + [CYAN] * 4 ] + bas
|
||||
|
||||
def creer_drapeau_republique_dominicaine():
|
||||
'''
|
||||
Génère la matrice relative au drapeau de la République Dominicaine
|
||||
:return: (list) la matrice de codes couleurs
|
||||
'''
|
||||
haut = [[BLEU] * 6 + [BLANC] * 3 + [ROUGE] * 6] * 3
|
||||
bas = copy.deepcopy(haut)
|
||||
miroir_horizontal(bas)
|
||||
miroir_vertical(bas)
|
||||
return haut + [[BLANC] * 7 + [BLEU] + [BLANC] * 7] + bas
|
||||
|
||||
DRAPEAUX = {
|
||||
'france' : creer_drapeau_france,
|
||||
'belgique' : creer_drapeau_belgique,
|
||||
'pays_bas' : creer_drapeau_pays_bas,
|
||||
'irlande' : creer_drapeau_irlande,
|
||||
'cote_ivoire' : creer_drapeau_cote_ivoire,
|
||||
'suede' : creer_drapeau_suede,
|
||||
'finlande' : creer_drapeau_finlande,
|
||||
'guinee' : creer_drapeau_guinee,
|
||||
'mali' : creer_drapeau_mali,
|
||||
'monaco' : creer_drapeau_monaco,
|
||||
'pologne' : creer_drapeau_pologne,
|
||||
'hongrie' : creer_drapeau_hongrie,
|
||||
'trinidad' : creer_drapeau_trinidad,
|
||||
'iran' : creer_drapeau_iran,
|
||||
'etats_unis' : creer_drapeau_etats_unis,
|
||||
'republique_congo' : creer_drapeau_rc,
|
||||
'benin' : creer_drapeau_benin,
|
||||
'botswana' : creer_drapeau_botswana,
|
||||
'grece' : creer_drapeau_grece,
|
||||
'suisse' : creer_drapeau_suisse,
|
||||
'japon' : creer_drapeau_japon,
|
||||
'jamaique' : creer_drapeau_jamaique,
|
||||
'palaos' : creer_drapeau_palaos,
|
||||
'dominique' : creer_drapeau_republique_dominicaine
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) >= 2:
|
||||
if sys.argv[1] == 'all':
|
||||
for nom, fonction in DRAPEAUX.items():
|
||||
print(nom)
|
||||
dessiner(fonction())
|
||||
print('')
|
||||
elif sys.argv[1] in DRAPEAUX:
|
||||
dessiner(DRAPEAUX[sys.argv[1]]())
|
||||
else:
|
||||
print(f'Le pays doit être dans la liste {list(DRAPEAUX.keys())}')
|
||||
44
representation_construits/chapitre_1/tp/paint.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding : utf-8 -*-
|
||||
# Author : Philippe BODDAERT
|
||||
# Date : 28/12/2020
|
||||
# License : CC-BY-NC-SA
|
||||
''' Affichage en couleur '''
|
||||
|
||||
NOIR = 0
|
||||
ROUGE = 1
|
||||
VERT = 2
|
||||
JAUNE = 3
|
||||
BLEU = 4
|
||||
MAGENTA = 5
|
||||
CYAN = 6
|
||||
BLANC = 7
|
||||
|
||||
def case_couleur(back = 9):
|
||||
'''
|
||||
Renvoi le texte d'un espace dont la couleur de fond est celle donnée
|
||||
:param back: (int) le code couleur du fond du texte
|
||||
'''
|
||||
return couleur(' ', back)
|
||||
|
||||
def couleur(texte, back = 9, fore = 9):
|
||||
'''
|
||||
Renvoi le texte dans la couleur donnée
|
||||
:param fore: (int) le code couleur du texte
|
||||
:param back: (int) le code couleur de fond du texte
|
||||
:param texte: (str) texte à mettre en couleur
|
||||
:return: (str) le texte mis en couleur pour affichage
|
||||
'''
|
||||
return f'\033[3{fore}m\033[4{back}m{texte}\033[39m\033[49m'
|
||||
|
||||
def dessiner(matrice):
|
||||
'''
|
||||
Affiche le contenu de la matrice sous la forme de cases colorées
|
||||
:param matrice: (list) un tableau de tableaux
|
||||
:return: None
|
||||
:CU: les valeurs de la matrice doivent être comprises entre 0 et 7 inclus
|
||||
'''
|
||||
for ligne in matrice:
|
||||
for colonne in ligne:
|
||||
print(case_couleur(colonne), sep = '', end = '')
|
||||
print('')
|
||||