Created
August 17, 2020 16:44
-
-
Save apaap/3a37a2f86456dd0464d54dd9fb4b3576 to your computer and use it in GitHub Desktop.
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
#importRLE.py import multiple rle encoded patterns from a string on the clipboard | |
import golly as g | |
import os | |
from math import ceil, floor, sqrt | |
txt = g.getclipstr() | |
constructPatt = False | |
rleList = [] | |
patt = [] | |
idx = -1 | |
for line in txt.splitlines(True): | |
# if(line): g.show(line) | |
if(line[0:4] == "x = "): | |
constructPatt = True | |
rleList.append("") | |
idx += 1 | |
else: | |
if(constructPatt == True): | |
rleList[idx] += line | |
if '!' in line: | |
constructPatt = False | |
N = len(rleList) | |
idx = 0 | |
spacing = 100 | |
rows = 5 # Use ceil(sqrt(N))) for squarish grid | |
for rle in rleList: | |
i, j = divmod(idx, rows) | |
#i, j = idx, 0 # Hack to support tall patterns | |
idx += 1 | |
patt = g.join(patt, g.parse(rle, spacing*int(i), (spacing+20)*int(j))) | |
# g.note(str(patt)) | |
# g.exit() | |
g.new("Preview patterns") | |
g.putcells(patt) | |
g.fit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment