Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi Projects for Kids (Second Edition)

You're reading from   Raspberry Pi Projects for Kids (Second Edition) Leverage the power of programming to use the Raspberry Pi to create awesome games

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781785281525
Length 146 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Daniel Leonard Bates Daniel Leonard Bates
Author Profile Icon Daniel Leonard Bates
Daniel Leonard Bates
Arrow right icon
View More author details
Toc

Code listing


This section gives a complete listing of the code used in this chapter. You can refer to it if your code is not working to see what changes need to be made. Some of the code blocks have been moved around within the program to keep similar parts of the program together. This can make things easier to read, but it is completely optional. The following is the complete code used in the chapter:

pace = 0.8

define :play_notes do |notes, durations|
  together = notes.zip(durations)
  together.each do |note, duration|
    if one_in(2)
      speaker = -1
    else
      speaker = 1
    end
    play note, release: pace * duration, pan: speaker
    sleep pace * duration
  end
end

define :drum do
  sample :drum_tom_lo_hard, attack: 0, sustain: 0, release: 0.2
end

define :play_beat do |beat|
  beat.each do |pause|
    drum
    sleep pace * pause
  end
end

rhythm = [1, 1, 1, 0.75, 0.25, 1, 0.75, 0.25, 2]
line1 = [:G3, :G3, :G3, :Eb3, :Bb3, :G3, :Eb3, :Bb3, :G3]
line2 = [:D4, :D4, :D4, ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime