Hardware Reference
In-Depth Information
FIGURE 7-6 Using play and sleep to play Twinkle Twinkle Little Star in Sonic Pi
It makes more sense to rewrite this code using a data structure . In this case you can
use a list like the ones you created in Python in Adventures 4 and 5. To create a list in
Ruby, you use square brackets and separate the items in the list with commas in much
the same way as in Python.
In computer science, a data structure is a particular way of storing and organizing
related pieces of information. For example, in a list or array like play_pattern
[60, 67, 69] , the list enclosed by square brackets in this line of code is an
example of a data structure.
Type the following example list into Workspace 2 and click Play:
play_pattern [60,60,67,67,69,69,67]
You will notice that the same tune will play, but the delays between the notes are quite
slow. To speed up the timing you can set the tempo. At the top of Workspace 2, above
the line of code you have just written, type this line:
with_tempo 150
Search WWH ::




Custom Search