Last active
December 9, 2017 03:29
-
-
Save JoshCheek/9f84c3db437d4149ad060bc49e0f28eb to your computer and use it in GitHub Desktop.
More rules (images @ https://twitter.com/josh_cheek/status/939334887076704256)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -e ' | |
require "io/console" | |
print "\e[?25l" | |
at_exit { print "\e[H\e[2J\e[?25h" } | |
seed = 0 | |
loop do | |
rule = Random.new(seed).rand(2**64) | |
nrows, ncols = $stdin.winsize | |
rows = [Array.new(nrows*2+ncols/2+2, 0), Array.new(nrows*2+ncols/2, 0)] | |
rows.each { |r| rand(5).times { r[rand r.size] = 1 } } | |
to_print = "" | |
nrows.times do |i| | |
cells1, cells2 = rows | |
cells = cells2[nrows-i, ncols/2] | |
slices = cells.zip([0]+cells).slice_before { |l, r| l != r }.map { |row| row.map &:first } | |
to_print << "\e[#{i+1}H" | |
slices.each { |slice| to_print << "\e[4#{slice[0]}m" << (" "*slice.size) } | |
rows = [ | |
cells2, | |
cells1[1...-1].zip(cells2).each_cons(3).map { |(a,d),(b,e),(c,f)| rule[a*32+b*16+c*8+d*4+e*2+f] }, | |
] | |
end | |
to_print << "\e[H\e[97;44mseed #{seed} | rule #{rule}\e[49;34m (press j/k/q)\e[0m" | |
$stdout.write to_print | |
$stdout.flush | |
input = $stdin.getch | |
next seed += 1 if input == ?k | |
next seed -= 1 if input == ?j | |
break if %W[\C-c \C-d q \e].include? input | |
end' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -e ' | |
require "io/console" | |
print "\e[?25l" | |
at_exit { print "\e[H\e[2J\e[?25h" } | |
seed = 0 | |
loop do | |
rule = Random.new(seed).rand(2**64) | |
nrows, ncols = $stdin.winsize | |
rows = [Array.new(nrows*2+ncols/2+2, 0), Array.new(nrows*2+ncols/2, 0),] | |
rows[-1][rows[-1].size/2] = 1 | |
to_print = $stdout | |
nrows.times do |i| | |
cells1, cells2 = rows | |
cells = cells2[nrows-i, ncols/2] | |
slices = cells.zip([0]+cells).slice_before { |l, r| l != r }.map { |row| row.map &:first } | |
to_print << "\e[#{i+1}H" | |
slices.each { |slice| to_print << "\e[4#{slice[0]}m" << (" "*slice.size) } | |
rows = [ | |
cells2, | |
cells1[1...-1].zip(cells2).each_cons(3).map { |(a,d),(b,e),(c,f)| rule[a*32+b*16+c*8+d*4+e*2+f] }, | |
] | |
end | |
to_print << "\e[H\e[97;44mseed #{seed} | rule #{rule}\e[49;34m (press j/k/q)\e[0m" | |
#$stdout.write to_print | |
$stdout.flush | |
input = $stdin.getch | |
next seed += 1 if input == ?k | |
next seed -= 1 if input == ?j | |
break if %W[\C-c \C-d q \e].include? input | |
end' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on looking at 5 instead of 3 | |
ruby -rio/console -e ' | |
rule = (ARGV[0]||raise("PROVIDE THE RULE AS AN ARGUMENT!")).to_i | |
loop do | |
rows, cols = $stdin.winsize | |
vals = Array.new rows*4 + cols/2, 0 | |
vals[vals.size/2-1] = 1 | |
rows.times do |i| | |
print "\e[#{i+1}H", vals[rows*2-i*2, cols/2].map { |v| "\e[4#{v}m \e[0" }.join | |
vals = vals.each_cons(5).tap { |v| }.map { |a,b,c,d,e| rule[a*16+b*8+c*4+d*2+e*1] } | |
end | |
print "\e[H\e[47;30mRULE #{rule}\e[0m" | |
input = $stdin.getch | |
if input == ?j | |
rule += 1 | |
elsif input == ?k | |
rule -= 1 | |
elsif input == q | |
break | |
end | |
end | |
' -- 1208058119 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment