Golly question

For scripts to aid with computation or simulation in cellular automata.
Post Reply
HartmutHolzwart
Posts: 841
Joined: June 27th, 2009, 10:58 am
Location: Germany

Golly question

Post by HartmutHolzwart » October 12th, 2014, 9:03 am

How do I save a pattern in #P fromat instead of .rle or .mc?

User avatar
dvgrn
Moderator
Posts: 10685
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI
Contact:

Re: Golly question

Post by dvgrn » October 12th, 2014, 11:10 am

HartmutHolzwart wrote:How do I save a pattern in #P fromat instead of .rle or .mc?
It's not one of Golly's native output formats, so you'll have to write a script to do it.

It could be a fairly short script, depending on what you want. I can write an inefficient version in a few minutes:

copy-in-#P-format.py:

Code: Select all

import golly as g

r=g.getselrect()
if r==[]: g.exit("No pattern selected.")
if len(g.getcells(r))%2: g.note("States above 1 will be reduced to 1.")
out="#P "+str(r[0])+","+str(r[1])+"\n"
for y in range(r[1],r[1]+r[3]):
  for x in range(r[0],r[0]+r[2]):
    out += "." if g.getcell(x,y)==0 else "*"
  out+="\n"
g.setclipstr(out)
This is designed to copy a pattern to the clipboard rather than saving it, but it's easy to adjust that. It will produce a big rectangle with an unnecessary number of trailing periods, but that's also easy to fix.

Maybe the right way to do it would be to break up the pattern into non-overlapping small rectangles, and save each one separately, to keep the pattern size reasonable for large objects. Would that be useful to you, or no?

HartmutHolzwart
Posts: 841
Joined: June 27th, 2009, 10:58 am
Location: Germany

Re: Golly question

Post by HartmutHolzwart » October 12th, 2014, 11:23 am

It's meant to produce input files for gencols only. So just small files...

Post Reply