Let's make our music loop without having to write lines and lines of code over and over again using some simple arithmetic operations.
Presentation
In today's lesson we are learning:
- How to repeat parts of our code.
- To introduce some randomisation to our code.
- To add basic arithmetic operations to our code.
Tasks:
1. Setup your Rasp Pi, login and open Sonic Pi.
2. Type the following into worksheet two:
3.times do
play 60
sleep 0.2
end
3. Use different numbers of times and different contents between the do and end keywords.
4. Now replace one of your sleeps with rand and see what happens:
3.times do
play 60
sleep rand
end
5. Let's try using some more arithmetic:
3.times do
play 60 + rand(10)
sleep rand
end
6. Make some music using this new code.