Ligne 1 : |
Ligne 1 : |
| {{Python-Turtle-Online-NAV}} | | {{Python-Turtle-Online-NAV}} |
| | | |
− | == Introduction == | + | == Démarrer Turtle == |
| Voici une petite série d'exemples Turtle dont la complexité du code augmente progressivement. | | Voici une petite série d'exemples Turtle dont la complexité du code augmente progressivement. |
| | | |
Ligne 55 : |
Ligne 55 : |
| [[Fichier:Python-Turtle-Exemple-00c.png]] | | [[Fichier:Python-Turtle-Exemple-00c.png]] |
| | | |
− | == Faire un carré == | + | == Dessiner un carré == |
| + | |
| + | Dessiner un carré se résume a parcourir 4 fois la même distance en effectuant une rotation de 90° entre chaque tronçon. |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
Ligne 81 : |
Ligne 83 : |
| [[Fichier:Python-Turtle-Exemple-00.png]] | | [[Fichier:Python-Turtle-Exemple-00.png]] |
| | | |
− | == Faire un carré : syntaxe abrégée == | + | == Dessiner un carré : syntaxe abrégée == |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
Ligne 107 : |
Ligne 109 : |
| [[Fichier:Python-Turtle-Exemple-00.png]] | | [[Fichier:Python-Turtle-Exemple-00.png]] |
| | | |
− | == faire un carré : avec plusieurs couleurs == | + | == Dessiner un carré : avec plusieurs couleurs == |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
Ligne 125 : |
Ligne 127 : |
| [[Fichier:Python-Turtle-Exemple-01.png]] | | [[Fichier:Python-Turtle-Exemple-01.png]] |
| | | |
− | == Faire un carré : avec une fonction == | + | == Dessiner un carré : avec une fonction == |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
Ligne 145 : |
Ligne 147 : |
| | | |
| [[Fichier:Python-Turtle-Exemple-02.png]] | | [[Fichier:Python-Turtle-Exemple-02.png]] |
| + | |
| + | == Dessiner une étoile == |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | import turtle |
| + | |
| + | t = turtle.Turtle() |
| + | |
| + | for i in range(5): # répéter 5 fois |
| + | t.forward(50) |
| + | t.right(144) |
| + | </syntaxhighlight> |
| + | |
| + | Résultat attendu: |
| + | |
| + | [[Fichier:Python-Turtle-Exemple-10.png]] |
| + | |
| + | == Dessiner une étoile spiralée == |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | import turtle |
| + | |
| + | t = turtle.Turtle() |
| + | |
| + | for i in range(20): # i de 0 à 19 |
| + | t.forward(i * 10) |
| + | t.right(144) |
| + | </syntaxhighlight> |
| + | |
| + | Résultat attendu: |
| + | |
| + | [[Fichier:Python-Turtle-Exemple-11.png]] |
| + | |
| + | '''Note''': à chaque fois que l'on déplace la tortue vers l'avant d'une quantité différente. Comme {{fname|i}} varie de 0 à 19, la distance parcourue de par {{fname|forward}} à chaque itération sera de {{fname|i * 10}} soit la suite 0, 10, 20, 30, 40, ... 180, 190. |
| | | |
| == SpiroGraphe simple == | | == SpiroGraphe simple == |