HomeTortue graphiqueGPanelRobotique WebTigerPython |
Python - Online |
TU APPRENDS ICI... |
comment la Tortue peut jouer différents sons et mélodies et même dessiner des figures. |
FREQUENCES DES SONS |
Pour jouer différents tons, utilises la fonction :
Pour accorder les instruments, le son la' avec une fréquence de 440 Hz a été défini comme diapason. Les autres fréquences peuvent être calculées.
|
EXEAMPLES |
Exemple 1: Jouer une mélodie courte Programme: from gturtle import * song = [262, 294, 330, 349, 392, 392, 392, 0, 440, 440, 440, 440, 392] for f in song: playTone(f, 250)
Exemple 2: Définir les notes avec des noms de tons
Programme: from gturtle import * song = ["c'","d'","e'","f'","g'","g'","g'",0,"a'","a'","a'","a'","g'"] song2 = ["c''","d''","e''","f''","g''","g''","g''",0,"a''","a''", "a''","a''","g''"] for f in song: playTone(f, 250) delay(1000) for f in song2: playTone(f, 250) Exemple 3: Jouer des sons et dessiner en même temps
Programme: from gturtle import * def step(): forward(20) right(90) forward(30) left(90) song = [262, 294, 330, 349, 392, 440, 494, 524] for f in song: playTone(f, 500, block = False) #playTone(f, 500) step()
Exemple 4: Jouer plusieurs notes simultanément Programme: from gturtle import * playTone(262, 2000, block = False) playTone(330, 2000, block = False) playTone(392, 2000, block = False)
Exemple 5: Choisir différents instruments Programme: from gturtle import * song = ["c'", "e'", "g'", "c''"] for f in song: playTone(f, 600, instrument="piano") for f in song: playTone(f, 600, instrument="guitar") for f in song: playTone(f, 600, instrument="trumpet") for f in song: playTone(f, 600, instrument="violin") for f in song: playTone(f, 600, instrument="organ") Exemple 6: Piano interactif
Programme: from gturtle import * def drawPiano(): setPenColor("black") for x in range(-200, 160, 50): setPos(x, -100) for k in range(2): fd(216).rt(90).fd(50).rt(90) setPenWidth(32) for x in [-150, -100, 0, 50, 100, 200]: setPos(x, 0) fd(100) def onMousePressed(x, y): if x > -200 and x < 215 and y > -100 and y < 100: i = int((x + 200)/50) setPos(x, y) if getPixelColorStr() == "black": k = int((x + 215) / 50) f = blacktones[k] else: f = whitetones[i] playTone(f, 400, instrument="piano",block = False) whitetones = [262, 294, 330, 349, 392, 440, 494, 524] blacktones = [0, 277, 311, 0, 360, 415, 466, 0, 555] makeTurtle(mousePressed = onMousePressed) hideTurtle() drawPiano() addStatusBar(20) setStatusText("Click a piano key to play!") |
REMARQUE... |
La Tortue peut jouer des sons en utilisant la fonction playTone(frequency, duration, instrument). Si tu veux que la Tortue dessine en même temps ou jouer plusieurs sons (accords) simultanément, utilise la fonction non-bloquante: playTone(frequency, duration, block = False). |
À FAIRE PAR TOI-MÊME |
|
![]() |
![]() |
![]() |
Technical information:
These frequencies can be calculated. If you start from a fundamental tone (a‘ with f = 440 Hz), you obtain the frequency of the following semitone with the factor 1.05946 and the next whole tone with the factor 1.05946 * 1.05946 ≈ 1.122. (e.g. h’ = 440 * 1.122 = 494). The frequencies in the table are rounded.
Why these factors? An octave (frequency ratio c‘’ : c' = 2 : 1) is divided into twelve semitone steps.
One semitone = 1/12 octave. This corresponds to the frequency ratio = twelfth root of 2 = 1.05946.
In English notation, notes are indicated with capital letters.
c, d, e, f ... corresponds to C3, D3, E3, F3,...
c', d', e', f'... corresponds toC4, D4, E4, F4, ...
c'', d'', e'', f'', corresponds toC5, D6, E5, F5, ...