Code: Select all
frank@bluemoon:~/Documents/GOL/patterns/1c5$ more 76P5H1V0_kermit.rle
#CXRLE Pos=-11,-7
x = 23, y = 15, rule = B3/S23
bo19bo$2o19b2o$o2bo4b2o3b2o4bo2bo$4bob2obo3bob2obo$3bo15bo$5b4o5b4o$9b
2ob2o2$10bobo$9bo3bo$5b5o3b5o$4b2o2b2o3b2o2b2o$4bo5bobo5bo$2b4o2bobobo
bo2b4o$9bo3bo!
frank@bluemoon:~/Documents/GOL/patterns/1c5$ ./rle2blk.py 76P5H1V0_kermit.rle
▄█ █▄
▀ ▀▄ ▄▄▀█ █▀▄▄ ▄▀ ▀
▀ ▄▄▄▄ ▄▄▄▄ ▀
▀▀ ▀▀
▄▀ ▀▄
▄█▀▀██ ██▀▀█▄
▄▄█▄ ▄ █ █ ▄ ▄█▄▄
▀ ▀
5
This way i can quickly eyeball if there are any interesting patterns appearing during calculations without resorting to cut and paste into Golly.
For each rle found and displayed, it will print the line number where the pattern is located in the log file, so the corresponding rle can be located.
Code: Select all
#!/usr/bin/env python3
import copy
import sys
import re
lookup_block = {
0 : ' ' , 1 : '\u2598', 2 : '\u259d', 3 : '\u2580',
4 : '\u2596', 5 : '\u258c', 6 : '\u259e', 7 : '\u259b',
8 : '\u2597', 9 : '\u259a', 10 : '\u2590', 11 : '\u259c',
12 : '\u2584', 13 : '\u2599', 14 : '\u259f', 15 : '\u2588'
}
def make_blk(bitmap,maxwidth):
"""Turn bitmap list into a unicode block form"""
width = len(bitmap[0])
height = len(bitmap)
blk_string = ""
block = []
for i in range(0,height,2) :
for j in range(0,width) :
key = 3 * bitmap[i][j]
key += 12 * bitmap[i+1][j] if i+1<height else 0
block.append(lookup_block[key])
block.append('\n')
blk_string += "".join(block)
return blk_string
class RLE2Bitmap:
def __init__(self):
self.width = 0
self.height = 0
self.x = 0
self.y = 0
self.bitmap = []
self.maxwidth = 100
self.lineptr = 0
def dimset(self):
return ((self.width != 0) & (self.height != 0))
def setdim(self, ls):
self.x = 0
self.y = 0
values = ls.split(',')
self.width = int(list(re.findall('\d+', values[0]))[0])
self.height = int(list(re.findall('\d+', values[1]))[0])
self.bitmap = [[0 for i in range(self.width)] for j in range(self.height)]
def cleardim(self):
self.width = 0
self.height = 0
def process(self, ls):
self.lineptr += 1
if (ls.startswith('x')):
self.setdim(ls)
else:
if self.dimset():
n = 0
for c in ls:
if (c.isdigit()):
n = 10 * n + ord(c) - ord('0')
else:
if (n == 0):
n = 1
if (c == 'b'):
self.x += n
n = 0
if (c == '$'):
self.x = 0
self.y += n
n = 0
if (c == '!'):
print(make_blk(self.bitmap,self.maxwidth))
print(self.lineptr)
self.cleardim()
return
if (c == 'o'):
for i in range(self.x, self.x + n):
self.bitmap[self.y][i] = 1
self.x += n
n = 0
if __name__ == "__main__":
rbm = RLE2Bitmap()
if len(sys.argv) > 1:
with open(sys.argv[1],'r') as file_rle:
for line_str in file_rle:
rbm.process(line_str.rstrip('\n'))