Store one bar.
Each position lasts a quarter of a second. A 1 plays a hit. A 0 waits for the same amount of time, creating a rest.
Repeat a pattern of hits and rests and listen to the result.
Try the projectOne bar
Hit · rest · hit · hit
Change the number of bars. The same four steps repeat in order.
8 steps · 6 hits · 2 bars
[1, 0, 1, 1]for bar in range(2):[1, 0, 1, 1] [1, 0, 1, 1]Each position lasts a quarter of a second. A 1 plays a hit. A 0 waits for the same amount of time, creating a rest.
range(2) gives the loop two turns. The inner loop walks through the four steps during each turn.
Three bars make 12 steps. There are three hits in each bar, so you will hear nine. Switch back to one bar and listen for the rest.
The printed sequence tells the audio code when to play a hit and when to leave silence.
pattern = [1, 0, 1, 1]
sequence = []
for bar in range(2):
for hit in pattern:
sequence.append(hit)
print(sequence)python3 python-beat.py --bars 3Download the Python script ↓