Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
480 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
# turtle-tutorial | ||
# Programmer en Python | ||
|
||
Ce cours enseigne la programmation en Python à l'aide de la célèbre tortue Logo. | ||
|
||
Vous pouvez trouver le tutoriel online : | ||
https://turtle-tutorial.readthedocs.io/ |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# draw a house | ||
# draw two circles | ||
import turtle | ||
|
||
turtle.forward(100) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
Dessiner | ||
======== | ||
|
||
Nous avons déjà vu les 4 commandes de base pour déplacer la tortue: | ||
*forward, backward, left* et *right*. | ||
|
||
Mais tu peux contrôler tous les aspcets du dessin: | ||
|
||
- épaisseur du trait | ||
- couleur du trait | ||
- couleur de remplissage | ||
|
||
En plus tu peux: | ||
|
||
- monter et descendre le stylo | ||
- dessiner des cercles | ||
- ajouter du text | ||
|
||
Monter/descendre le stylo | ||
------------------------- | ||
|
||
La tortue peut monter et descendre son style. | ||
Ceci lui permet de dessiner des lignes séparés. | ||
|
||
.. image:: draw1.png | ||
|
||
.. literalinclude:: draw1.py | ||
|
||
:download:`draw1.py <draw1.py>` | ||
|
||
|
||
Téléporter la tortue | ||
-------------------- | ||
|
||
La tortue peux aller à n'importer quel position indiqué par des coordonnés (x, y). | ||
La commande ``turtle.goto(0, 20)`` va téléporter la tortue à la position (x=0, y=20). | ||
|
||
.. image:: draw2.png | ||
|
||
.. literalinclude:: draw2.py | ||
|
||
:download:`draw2.py <draw2.py>` | ||
|
||
|
||
L'épaisseur de ligne | ||
-------------------- | ||
|
||
Tu peux modifier l'épaisser du stylo avec la commande ``turtle.width(2)``. | ||
|
||
.. image:: draw3.png | ||
|
||
.. literalinclude:: draw3.py | ||
|
||
:download:`draw3.py <draw3.py>` | ||
|
||
|
||
La couleur de ligne | ||
------------------- | ||
|
||
Tu peux modifier la couldur du stylo avec la commande ``turtle.pencolor('blue')``. | ||
|
||
Voici les couleurs que tu peux choisirs: | ||
|
||
*yellow, gold, orange, red, maroon, violet, pink, magenta, purple, navy, | ||
blue, sky blue, cyan, turquoise, lightgreen, green, darkgreen, chocolate, | ||
brown, black, gray, white* | ||
|
||
N'oublies pas de mettre le nom de couleur entre apostrophes. | ||
|
||
.. image:: draw4.png | ||
|
||
.. literalinclude:: draw4.py | ||
|
||
:download:`draw4.py <draw4.py>` | ||
|
||
|
||
Remplir une forme | ||
----------------- | ||
|
||
Il est possible de remplir une forme d'une couleur. | ||
|
||
Avec la commande ``turtle.fillcolor('green')`` tu peux choisir une couleur de remplissage. | ||
|
||
Ensuite il faut entourer la forme à remplir, par exemple le triangle, avec les deux commandes:: | ||
|
||
turtle.begin_fill() | ||
turtle.end_fill() | ||
|
||
.. image:: draw5.png | ||
|
||
.. literalinclude:: draw5.py | ||
|
||
:download:`draw5.py <draw5.py>` | ||
|
||
|
||
Ajouter un texte | ||
---------------- | ||
|
||
Il est possible d'écrire un texte à la position de la tortue. | ||
|
||
La police par défaut est très petit. Il est préférable que tu augmente la taille. | ||
|
||
.. image:: draw6.png | ||
|
||
.. literalinclude:: draw6.py | ||
|
||
:download:`draw6.py <draw6.py>` | ||
|
||
|
||
Dessiner un cercle | ||
------------------ | ||
|
||
La fonction ``turtle.circle(40)`` permet de dessiner un cercle avec un rayon de 40 pixels. | ||
Dans le programme ci-dessous la tortue dessine deux cercles. | ||
|
||
.. image:: circle.png | ||
|
||
.. literalinclude:: circle.py | ||
|
||
:download:`circle.py <circle.py>` | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# pen up/down | ||
import turtle | ||
|
||
turtle.forward(100) | ||
turtle.up() | ||
turtle.forward(50) | ||
turtle.down() | ||
turtle.forward(50) | ||
|
||
turtle.done() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# goto (x, y) position | ||
import turtle | ||
|
||
turtle.forward(200) | ||
|
||
turtle.up() | ||
turtle.goto(0, 20) | ||
turtle.down() | ||
turtle.forward(200) | ||
|
||
turtle.up() | ||
turtle.goto(0, 40) | ||
turtle.down() | ||
turtle.forward(200) | ||
|
||
|
||
turtle.done() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# change pen widht | ||
import turtle | ||
|
||
turtle.forward(200) | ||
|
||
turtle.up() | ||
turtle.goto(0, 20) | ||
turtle.down() | ||
turtle.width(2) | ||
turtle.forward(200) | ||
|
||
turtle.up() | ||
turtle.goto(0, 40) | ||
turtle.down() | ||
turtle.width(5) | ||
turtle.forward(200) | ||
|
||
turtle.done() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# change pen color | ||
import turtle | ||
|
||
turtle.width(5) | ||
turtle.forward(200) | ||
turtle.left(90) | ||
|
||
turtle.pencolor('blue') | ||
turtle.forward(100) | ||
turtle.left(90) | ||
|
||
turtle.pencolor('green') | ||
turtle.forward(300) | ||
turtle.left(90) | ||
|
||
turtle.done() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# fill a shape | ||
import turtle | ||
|
||
turtle.width(5) | ||
turtle.fillcolor('green') | ||
|
||
turtle.begin_fill() | ||
turtle.forward(200) | ||
turtle.left(120) | ||
turtle.forward(200) | ||
turtle.left(120) | ||
turtle.forward(200) | ||
turtle.left(120) | ||
turtle.end_fill() | ||
|
||
turtle.done() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# add text | ||
import turtle | ||
|
||
turtle.left(90) | ||
turtle.write('default text size') | ||
|
||
turtle.forward(30) | ||
turtle.write('Courier 24', font=('Courier', 24)) | ||
|
||
turtle.forward(30) | ||
turtle.write('Arial 36', font=('Arial', 36)) | ||
|
||
turtle.done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# draw a rainbow | ||
import turtle | ||
|
||
d = 10 | ||
r = 60 | ||
colors = ('red', 'orange', 'yellow', 'lightgreen', 'lightblue', 'violet') | ||
|
||
turtle.pensize(d) | ||
turtle.left(90) | ||
|
||
for color in colors: | ||
turtle.pencolor(color) | ||
turtle.circle(r, 180) | ||
turtle.left(90) | ||
turtle.up() | ||
turtle.forward(2*r + d) | ||
turtle.down() | ||
turtle.left(90) | ||
r += d | ||
|
||
turtle.write('rain bow', font=(None, 36)) | ||
turtle.done() |
Oops, something went wrong.