Version française de cette page

TorPy

Vernacular Python Turtle.


Presentation

TorPy is a Frenchified (but which can be translated into any language) version of Python turtle module.
Inspired by the Logo turtle, turtle makes learning to program, since writing instructions that the turtle will not make then.
Furthermore it allows to produce beautiful geometric figures

I wrote TorPy after the turtle usage tests with college students, and its purpose is to overcome the some difficulties.

Some Features of TorPy:

TorPy is a cross-platform software, free (GNU GPL 3 license), developed in Python (programming language) and PyQt (or PySide) for the GUI.


Download and install

To run, TorPy needs

GNU/Linux

Windows

Mac OS X

Sources


First classroom session


Some examples

The versions below are not those expected of students (using functions, variables).

home without lifting the pencil

def maison(debut=(0, 0), cote=100, delai=0):

                va(debut[0], debut[1])
                for i in range(4):
                    av(cote)
                    attendre(delai)
                    tg(90)
                    attendre(delai)

                diagonale = cote * racine(2)

                tg(45)
                attendre(delai)
                avance(diagonale)
                attendre(delai)
                tg(90)
                attendre(delai)
                avance(diagonale / 2)
                attendre(delai)
                tg(90)
                attendre(delai)
                avance(diagonale / 2)
                attendre(delai)
                tg(90)
                attendre(delai)
                avance(diagonale)
                attendre(delai)


            dimensions = 200
            depart = -dimensions / 2

            #maison(debut=(depart, depart), cote=dimensions)
            maison(debut=(depart, depart), cote=dimensions, delai=0.5)

            depart = -100 - dimensions / 2
            va(depart, depart)
            couleur('rouge')
            ecris("C'EST LA MAISON DE LA TORTUE...", 16)

            va(0, 0)
            couleur('noir')

3 rosaces

def rosace(rayon=100):
                for i in range(6):
                    couleur()
                    cercle(rayon)
                    tg(60)

            rosace()
            rosace(50)
            rosace(25)
            couleur("noir")

10 squares

def carre(c) :
                for i in range(4) :
                    av(c)
                    tg(90)

            for i in range(10) :
                vaEn(10*i-200, 10*i-200)
                couleur()
                carre((10-i)*30)

            vaEn(-50, 150)
            couleur("bleu")
            ecris("Voilà c'est fait", 20)
            vaEn(-50, 200)

Vasarely

from http://www.prpig.org/2014/08/victor-vasarely-meets-tina-turtle.html

def carre(debut=(0, 0), cote=100):
                # un carré plein
                va(debut[0], debut[1])
                turtle.begin_fill()
                for i in range(4):
                    av(cote)
                    tg(90)
                turtle.end_fill()

            # nombre de carrés :
            nb = 8
            # leur taille :
            taille = 40

            moitie = (nb + 1) / 2
            position = [-moitie * taille, moitie * taille]
            va(position[0], position[1])

            for x in range(nb):
                for y in range(nb):
                    couleur()
                    carre(position, taille)
                    couleur()
                    carre(
                        (position[0] + taille/4, position[1] + taille/4), 
                        taille/2)
                    position[0] += taille
                    va(position[0], position[1])
                position[0] = -moitie * taille
                position[1] -= taille
                va(position[0], position[1])

            position[0] -= taille
            va(position[0], position[1])
            ecris("Alphabet Plastique, de Victor VASARELY.", 20)
            position[1] -= taille
            va(position[0], position[1])


Operation of TorPy

The launch of TorPy a torpy subfolder is created in the temporary folder of the computer and 3 files are copied from the subfolder files installing TorPy:

When the user requests the execution of his instructions, they are inserted into the torpy.py file before it is executed.
Specifically, the torpy.py file contains the following line that serves as a benchmark and will be replaced by the user instruction:

# USER INSTRUCTIONS

Adapt TorPy

As an example, I will add them begin_fill and end_fill functions from the turtle module, translating them into ** debutDeRemplissage ** and ** finDeRemplissage , with short versions remplir** and finRemplir.

Changes to the file files/importturtle_fr.py

Changes to the file translations/instructions_fr

Notes


Translate TorPy in another language

Language is detected at launch but can also be passed as parameter.
For example, if TORPY_DIR means the installation path of TorPy:

python TORPY_DIR/torpy.pyw LANG=es
            python TORPY_DIR/torpy.pyw LANG=fr_CA

The language is indicated as xx or xx_YY shape.
For example fr show the French, but fr_CA the French Quebec.

If you translate TorPy in another language, please send me (pascal.peter at free.fr) your translation so it can be added to the software. Send me the files are (see below for descriptions):

Translation of the functions and instructions

Just change the two following text files and save them by adding xx or xx_YY termination:

For example, I created a variant of the French language called fr_LOL.
In importturtle_fr_LOL.py and instructions_fr_LOL files, I just replaced avance by avanssss and ecris by ekri.

Note: since Python 3 function names (and variables) can be accentuated.
That remains to be avoided because TorPy no longer work with Python 2.
However, for some languages this possibility can be very useful.

Translation Interface Torpy (menus, etc)

Just change the following text file and save it by adding the ending xx or xx_YY:

The file can be modified with Qt Linguist, which will also allow you to generate a torpy_xx_YY.qm file and test your translation. To do this, ask File → Release in Qt Linguist.

Here is the result by launching TorPy with LANG=fr_LOL parameter:

Eventually translating README and CREDITS

They are displayed in the About window


Last modification of this page: 2021-02-18.