Skip to content

Instantly share code, notes, and snippets.

@dndrks
Last active December 6, 2019 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dndrks/0afac7374b73043e768fceca94aed868 to your computer and use it in GitHub Desktop.
Save dndrks/0afac7374b73043e768fceca94aed868 to your computer and use it in GitHub Desktop.
druid_lc
--less concepts for druid
-- ONLY RUN, DO NOT UPLOAD.
-- UPLOADING WILL FREEZE CROW.
-- RUN IS 100% FINE + FUN.
seed = 36
rule = 30
next_seed = nil
new_seed = seed
low = 1
high = 14
v = {}
for i = 1,2 do
v[i] = {}
v[i].bit = 1
v[i].oct = 0
v[i].odds = 99 -- don't touch
v[i].chance = 0
v[i].trans = 0
v[i].add = 0
end
v[1].bit = 1
v[2].bit = 3
scaled = nil
semi = 0
ionian = 1
aeolian = 2
dorian = 3
phrygian = 4
lydian = 5
mixolydian = 6
major_pent = 7
minor_pent = 8
chromatic = 9
scale = ionian
notes = { {0,2,4,5,7,9,11,12,14,16,17,19,21,23,24,26,28,29,31,33,35,36,38,40,41,43,45,47,48},
{0,2,3,5,7,8,10,12,14,15,17,19,20,22,24,26,27,29,31,32,34,36,38,39,41,43,44,46,48},
{0,2,3,5,7,9,10,12,14,15,17,19,21,22,24,26,27,29,31,33,34,36,38,39,41,43,45,46,48},
{0,1,3,5,7,8,10,12,13,15,17,19,20,22,24,25,27,29,31,32,34,36,37,39,41,43,44,46,48},
{0,2,4,6,7,9,11,12,14,16,18,19,21,23,24,26,28,30,31,33,35,36,38,40,42,43,45,47,48},
{0,2,4,5,7,9,10,12,14,16,17,19,21,22,24,26,28,29,31,33,34,36,38,40,41,43,45,46,48},
{0,3,5,7,10,12,15,17,19,22,24,27,29,31,34,36,39,41,43,46,48,51,53,55,58,60,63,65,67},
{0,2,4,7,9,12,14,16,19,21,24,26,28,31,33,36,38,40,43,45,48,50,52,55,57,60,62,64,67},
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28} }
--preset_count = 0
-- maths: translate the seed integer to binary
function seed_to_binary()
seed_as_binary = {}
for i = 0,7 do
table.insert(seed_as_binary, (seed & (2 ^ i)) >> i)
end
end
-- maths: translate the rule integer to binary
function rule_to_binary()
rule_as_binary = {}
for i = 0,7 do
table.insert(rule_as_binary, (rule & (2 ^ i)) >> i)
end
end
function compare( a, b )
return table.concat(a) == table.concat(b)
end
function scaling(lo, hi, received)
scaled = math.floor(((((received-1) / (256-1)) * (hi - lo) + lo)))
end
function bang()
seed_to_binary()
rule_to_binary()
seed_pack1 = {seed_as_binary[1], seed_as_binary[8], seed_as_binary[7]}
seed_pack2 = {seed_as_binary[8], seed_as_binary[7], seed_as_binary[6]}
seed_pack3 = {seed_as_binary[7], seed_as_binary[6], seed_as_binary[5]}
seed_pack4 = {seed_as_binary[6], seed_as_binary[5], seed_as_binary[4]}
seed_pack5 = {seed_as_binary[5], seed_as_binary[4], seed_as_binary[3]}
seed_pack6 = {seed_as_binary[4], seed_as_binary[3], seed_as_binary[2]}
seed_pack7 = {seed_as_binary[3], seed_as_binary[2], seed_as_binary[1]}
seed_pack8 = {seed_as_binary[2], seed_as_binary[1], seed_as_binary[8]}
neighborhoods1 = {1,1,1}
neighborhoods2 = {1,1,0}
neighborhoods3 = {1,0,1}
neighborhoods4 = {1,0,0}
neighborhoods5 = {0,1,1}
neighborhoods6 = {0,1,0}
neighborhoods7 = {0,0,1}
neighborhoods8 = {0,0,0}
function com (seed_packN, lshift, mask)
if compare (seed_packN,neighborhoods1) then
return (rule_as_binary[8] << lshift) & mask
elseif compare (seed_packN, neighborhoods2) then
return (rule_as_binary[7] << lshift) & mask
elseif compare (seed_packN, neighborhoods3) then
return (rule_as_binary[6] << lshift) & mask
elseif compare (seed_packN, neighborhoods4) then
return (rule_as_binary[5] << lshift) & mask
elseif compare (seed_packN, neighborhoods5) then
return (rule_as_binary[4] << lshift) & mask
elseif compare (seed_packN, neighborhoods6) then
return (rule_as_binary[3] << lshift) & mask
elseif compare (seed_packN, neighborhoods7) then
return (rule_as_binary[2] << lshift) & mask
elseif compare (seed_packN, neighborhoods8) then
return (rule_as_binary[1] << lshift) & mask
else return (0 << lshift) & mask
end
end
out1 = com(seed_pack1, 7, 128)
out2 = com(seed_pack2, 6, 64)
out3 = com(seed_pack3, 5, 32)
out4 = com(seed_pack4, 4, 16)
out5 = com(seed_pack5, 3, 8)
out6 = com(seed_pack6, 2, 4)
out7 = com(seed_pack7, 1, 2)
out8 = com(seed_pack8, 0, 1)
next_seed = out1+out2+out3+out4+out5+out6+out7+out8
end
function iterate()
seed = next_seed
bang()
scaling(low,high,seed)
if seed_as_binary[v[1].bit] == 1 then
v[1].odds = math.random(0,100)
if v[1].odds < v[1].chance then
v[1].add = v[1].trans
else
v[1].add = 0
end
output[1].volts = (((notes[scale][scaled])+(36+(v[1].oct*12)+semi+v[1].add)-48)/12)
output[2]()
end
if seed_as_binary[v[2].bit] == 1 then
v[2].odds = math.random(0,100)
if v[2].odds < v[2].chance then
v[2].add = v[2].trans
else
v[2].add = 0
end
output[3].volts = (((notes[scale][scaled])+(36+(v[2].oct*12)+semi+v[2].add)-48)/12)
output[4]()
end
end
function dice()
seed = math.random(0,255)
new_seed = seed
rule = math.random(0,255)
new_rule = rule
v[1].bit = math.random(0,8)
v[2].bit = math.random(0,8)
bang()
end
function init()
input[1].mode('change',1.0,0.1,'rising')
input[2].mode('change',1.0,0.1,'rising')
output[2].action = pulse()
output[4].action = pulse()
bang()
end
input[1].change = function(state)
iterate()
end
input[2].chance = function(state)
dice()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment