# ############################################################### # Paysage dessiné en utilisant le module Matplotlib de Python # Juin 2026 # nsi.gecif.net # ############################################################### import matplotlib.pyplot as plt import matplotlib.patches as patches import numpy as np # Configuration de la figure et des axes fig, ax = plt.subplots(figsize=(12, 8)) ax.set_xlim(0, 100) ax.set_ylim(0, 100) ax.axis('off') # Masquer les axes pour l'effet "tableau" # 1. LE CIEL ET LE SOL # Ciel (Grand rectangle bleu) ciel = patches.Rectangle((0, 40), 100, 60, color='#87CEEB', zorder=1) ax.add_patch(ciel) # Sol / Colline (Polygone vert pour donner du relief) sol = patches.Polygon([[0, 0], [0, 42], [30, 45], [70, 38], [100, 42], [100, 0]], color='#228B22', zorder=2) ax.add_patch(sol) # 2. LE SOLEIL ET LES NUAGES # Soleil (Cercle jaune avec effet de rayonnement) soleil = patches.Circle((85, 85), 8, color='#FFD700', zorder=3) ax.add_patch(soleil) # Nuages (Superposition de cercles blancs) nuages_coords = [(20, 80), (24, 82), (28, 80), (24, 78), (60, 75), (64, 77), (68, 75)] for cx, cy in nuages_coords: nuage = patches.Circle((cx, cy), 4, color='white', alpha=0.85, zorder=3, ec='none') ax.add_patch(nuage) # 3. LA MAISON # Murs (Rectangle) mur = patches.Rectangle((15, 25), 25, 20, color='#FAEBD7', edgecolor='#333', linewidth=1.5, zorder=4) ax.add_patch(mur) # Toit (Triangle/Polygone rouge) toit = patches.Polygon([[12, 45], [27.5, 60], [43, 45]], color='#CD5C5C', edgecolor='#333', linewidth=1.5, zorder=5) ax.add_patch(toit) # Porte (Rectangle marron) porte = patches.Rectangle((24, 25), 6, 12, color='#8B4513', zorder=5) ax.add_patch(porte) # Poignée de porte (Petit cercle) poignee = patches.Circle((25, 31), 0.4, color='#FFD700', zorder=6) ax.add_patch(poignee) # Fenètres (Rectangles bleus avec quadrillage) fenetre1 = patches.Rectangle((18, 33), 4, 5, color='#ADD8E6', edgecolor='#333', zorder=5) fenetre2 = patches.Rectangle((33, 33), 4, 5, color='#ADD8E6', edgecolor='#333', zorder=5) ax.add_patch(fenetre1) ax.add_patch(fenetre2) # 4. LES ARBRES def dessiner_arbre(x_tronc, y_tronc, hauteur, largeur, rayon_feuillage): # Tronc tronc = patches.Rectangle((x_tronc - largeur/2, y_tronc), largeur, hauteur, color='#5C4033', zorder=4) ax.add_patch(tronc) # Feuillage (Superposition de 3 cercles pour faire plus réaliste) f1 = patches.Circle((x_tronc, y_tronc + hauteur), rayon_feuillage, color='#006400', zorder=5) f2 = patches.Circle((x_tronc - 2, y_tronc + hauteur + 3), rayon_feuillage * 0.8, color='#191970', alpha=0.1, zorder=6) # Ombre f3 = patches.Circle((x_tronc + 2, y_tronc + hauteur + 2), rayon_feuillage * 0.8, color='#2E8B57', zorder=6) ax.add_patch(f1) ax.add_patch(f3) dessiner_arbre(55, 28, 15, 2.5, 7) dessiner_arbre(68, 25, 12, 2, 5.5) # 5. LA ROUTE route = patches.Polygon([[45, 0], [75, 0], [55, 25], [48, 25]], color='#555555', zorder=3) ax.add_patch(route) # Ligne pointillée au milieu de la route ax.plot([60, 51.5], [0, 25], color='#FFFFFF', linestyle='--', linewidth=2, zorder=4) # 6. LA VOITURE # Carrosserie inférieure (Rectangle rouge) voiture_bas = patches.Rectangle((70, 12), 16, 5, color='#DC143C', zorder=5) ax.add_patch(voiture_bas) # Habitacle supérieur (Polygone rouge/vitres bleues) voiture_haut = patches.Polygon([[73, 17], [75, 21], [81, 21], [84, 17]], color='#DC143C', zorder=5) ax.add_patch(voiture_haut) vitre = patches.Polygon([[74.5, 17.2], [76, 20.2], [80.5, 20.2], [82.5, 17.2]], color='#87CEFA', zorder=6) ax.add_patch(vitre) # Roues (Cercles noirs et centres gris) roue1 = patches.Circle((74, 12), 2.2, color='black', zorder=6) roue1_centre = patches.Circle((74, 12), 0.8, color='darkgray', zorder=7) roue2 = patches.Circle((82, 12), 2.2, color='black', zorder=6) roue2_centre = patches.Circle((82, 12), 0.8, color='darkgray', zorder=7) ax.add_patch(roue1) ax.add_patch(roue1_centre) ax.add_patch(roue2) ax.add_patch(roue2_centre) # Phare (Petit trait jaune) phare = patches.Circle((86, 14.5), 0.4, color='#FFFF00', zorder=6) ax.add_patch(phare) # 7. LES PERSONNAGES (Silhouettes stylisées près de la maison) def dessiner_personnage(x, y, hauteur_corps, couleur): # Jambes (Traits) ax.plot([x - 0.5, x - 0.5], [y, y + 4], color=couleur, linewidth=2, zorder=5) ax.plot([x + 0.5, x + 0.5], [y, y + 4], color=couleur, linewidth=2, zorder=5) # Corps (Rectangle ou ligne épaisse) corps = patches.Rectangle((x - 1, y + 4), 2, hauteur_corps, color=couleur, zorder=5) ax.add_patch(corps) # Tête (Cercle) tete = patches.Circle((x, y + 4 + hauteur_corps + 1.5), 1.2, color='#FFCD94', zorder=5) ax.add_patch(tete) # Bras ax.plot([x - 1.5, x + 1.5], [y + 4 + hauteur_corps - 1, y + 4 + hauteur_corps - 1], color=couleur, linewidth=2, zorder=5) dessiner_personnage(10, 20, 5, '#333399') # Personnage 1 dessiner_personnage(13, 20, 4, '#990033') # Personnage 2 # Affichage du tableau plt.title("Paysage Géométrique - Matplotlib - nsi.gecif.net", fontsize=16, fontweight='bold') plt.show()