play
will sound out a sequence of musical notes.
play "GEC"
The notes are written in standard
ABC notation, which
uses the capital letter "C"
for middle C.
In ABC notation, the C major scale can be written "CDEFGABC'"
.
Read about pitch, sharps, flats, beats, rests, and chords in ABC notation.
Put all the notes inside quotes. Quotation marks are used to separate the music written in ABC notation from the code that plays the whole piece of music.
Triple quotes """
separate a large piece of music
from the rest of the code.
To play a longer song that fills up more than one line of code, use triple-quotes.
play """ F ^G C' F' [=G'E] C' ^G =G' [^G'^D] C' ^G ^G' [=D'D] ^A F D' [^C=C'] ^G F ^G21/3 C' ^G F [=G^DG,][F,F^G] [^GFF,]2 """
Triple quotes must match, just like regular quotes. Put a triple quote before the first line of music, and then put one after the last line of music.
play
accepts an optional options object as a first argument:
play {tempo: 200},
"GEC"
Options include:
tempo
specifies a number of beats per minute.
The normal tempo is 120 beats per minute.wait
can be set to false
to start
a song and then proceed to the next animation without waiting for
it to finish. This can be used to have a turtle
play a song while it is simultaneously drawing, or to play two songs
at once.