start:preparation:python:bonjour
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
start:preparation:python:bonjour [2025/02/27 07:04] – admin | start:preparation:python:bonjour [2025/03/04 16:49] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
======== Bonjour en python dans rectangle ======== | ======== Bonjour en python dans rectangle ======== | ||
- | Voici un programme Python qui trace un rectangle et affiche le mot " | + | Voici un programme Python qui trace un rectangle |
<code python exemple001.py> | <code python exemple001.py> | ||
- | ```python | ||
import turtle | import turtle | ||
- | # Configurer l' | + | # Configuration |
screen = turtle.Screen() | screen = turtle.Screen() | ||
- | screen.bgcolor(" | + | screen.bgcolor(" |
- | # Créer une tortue pour dessiner | + | # Création de la tortue pour dessiner |
- | pen = turtle.Turtle() | + | t = turtle.Turtle() |
- | pen.speed(2) # Vitesse de dessin | + | t.speed(3) |
- | # Dessiner | + | # Fonction pour dessiner |
- | width = 300 | + | def draw_rectangle(width, height, thickness): |
- | height | + | t.pensize(thickness) # Définir l' |
- | pen.penup() | + | t.color(" |
- | pen.goto(-width/2, height/2) # Déplacer la tortue à la position de départ | + | for _ in range(2): |
- | pen.pendown() | + | t.forward(width) |
+ | t.left(90) | ||
+ | t.forward(height) | ||
+ | t.left(90) | ||
- | # Dessiner | + | # Tracer |
- | for _ in range(2): | + | t.penup() |
- | pen.forward(width) | + | t.goto(-150, 100) # Placer la tortue au point de départ |
- | pen.right(90) | + | t.pendown() |
- | pen.forward(height) | + | draw_rectangle(300, 200, 12) # Largeur 300, hauteur 200, épaisseur de 12 pixels |
- | | + | |
- | # Positionner | + | # Afficher |
- | pen.penup() | + | t.penup() |
- | pen.goto(0, | + | t.goto(0, |
- | pen.pendown() | + | t.pendown() |
- | pen.color(" | + | t.color(" |
- | pen.write(" | + | t.write(" |
# Cacher la tortue après le dessin | # Cacher la tortue après le dessin | ||
- | pen.hideturtle() | + | t.hideturtle() |
- | # Laisser | + | # Attendre que l' |
turtle.done() | turtle.done() | ||
- | ``` | + | |
</ | </ | ||
< | < |
/home/chanteri/www/fablab37110/data/attic/start/preparation/python/bonjour.1740636258.txt.gz · Dernière modification : de admin