Skip to content

Instantly share code, notes, and snippets.

@apaap
Created August 17, 2020 16:44
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 apaap/3a37a2f86456dd0464d54dd9fb4b3576 to your computer and use it in GitHub Desktop.
Save apaap/3a37a2f86456dd0464d54dd9fb4b3576 to your computer and use it in GitHub Desktop.
#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