Using 1D cellular automata to generate giant dominant chords across four octaves.
#Elementary Cellular Automata
#by Loopiloop
#---settings---
#rule of the elementary cellular automata
rule = 73
#initial generation
gen = (bools 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
#random alternative to determine inital generation
use_random_seed = 12345
#gen = (ring false, true).pick(20)
#speed
speed = 150
#lowest note
output_start = 36
#used scale in distances to lowest note
output_scale = (ring 0, 4, 7, 11)
#length of scale
output_length = 4
#speed
#---setup---
rule_b = (ring)
#iterate through cases
9.times do
#convert rule into a truth ring binary number
rule_b = rule_b + (ring (range 0, 2)[rule] == 1)
rule = rule/2
end
#---main loop---
live_loop :main do
#set speed
use_bpm speed
#set synth
use_synth :piano
#clean the output
use_debug false
#display current gen
spark gen
#empty next gen
gen_new = (ring)
#iterate through 20 spaces
tick_reset
20.times do
#advance to next space
tick
#play the note coresponding to that cell
if gen.look
play (chord_invert output_scale, look)[0] + output_start
end
#calculate cell neigborhood as binary number
hood = 0
if gen.look(offset: -1)
hood = hood + 4
end
if gen.look
hood = hood + 2
end
if gen.look(offset: 1)
hood = hood + 1
end
#calculate new cell state
gen_new = gen_new + (ring rule_b[hood])
end
#advance to next generation
gen = gen_new
#sleep
sleep 1
end