How to get the codes for patterns?
- hotcrystal0
- Posts: 2208
- Joined: July 3rd, 2020, 5:32 pm
- Location: United States
How to get the codes for patterns?
Can anyone tell me how to get the code for various patterns?
Code: Select all
x = 192, y = 53, rule = B3/S23
33$42b4o$41b6o$40b2ob4o$41b2o3$41b2o$39bo6bo$38bo8bo$38bo8bo$38b9o3$42b
4o$41b6o$40b2ob4o$41b2o!
- yujh
- Posts: 3068
- Joined: February 27th, 2020, 11:23 pm
- Location: I'm not sure where I am, so please tell me if you know
- Contact:
Re: How to get the codes for patterns?
Do you mean apgcode?hotcrystal0 wrote: ↑July 3rd, 2020, 8:42 pmCan anyone tell me how to get the code for various patterns?
Code: Select all
import golly as g
# Golly selection to apgcode (in clipboard)
# stolen shamelessly from apgsearch. Thanks Adam!
def bijoscar(maxsteps):
initpop = int(g.getpop())
initrect = g.getrect()
if (len(initrect) == 0):
return 0
inithash = g.hash(initrect)
for i in xrange(maxsteps):
g.run(1)
if (int(g.getpop()) == initpop):
prect = g.getrect()
phash = g.hash(prect)
if (phash == inithash):
period = i + 1
if (prect == initrect):
return period
else:
return -period
return -1
def canonise():
p = bijoscar(1000)
representation = "#"
for i in range(abs(p)):
rect = g.getrect()
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0], rect[1], 1, 0, 0, 1))
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0]+rect[2]-1, rect[1], -1, 0, 0, 1))
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0], rect[1]+rect[3]-1, 1, 0, 0, -1))
representation = compare_representations(representation, canonise_orientation(rect[2], rect[3], rect[0]+rect[2]-1, rect[1]+rect[3]-1, -1, 0, 0, -1))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0], rect[1], 0, 1, 1, 0))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0]+rect[2]-1, rect[1], 0, -1, 1, 0))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0], rect[1]+rect[3]-1, 0, 1, -1, 0))
representation = compare_representations(representation, canonise_orientation(rect[3], rect[2], rect[0]+rect[2]-1, rect[1]+rect[3]-1, 0, -1, -1, 0))
g.run(1)
if (p<0):
prefix = "q"+str(abs(p))
elif (p==1):
prefix = "s"+str(g.getpop())
else:
prefix = "p"+str(p)
g.setclipstr("x"+prefix+"_"+representation)
# A subroutine used by canonise:
def canonise_orientation(length, breadth, ox, oy, a, b, c, d):
representation = ""
chars = "0123456789abcdefghijklmnopqrstuvwxyz"
for v in xrange(int((breadth-1)/5)+1):
zeroes = 0
if (v != 0):
representation += "z"
for u in xrange(length):
baudot = 0
for w in xrange(5):
x = ox + a*u + b*(5*v + w)
y = oy + c*u + d*(5*v + w)
baudot = (baudot >> 1) + 16*g.getcell(x, y)
if (baudot == 0):
zeroes += 1
else:
if (zeroes > 0):
if (zeroes == 1):
representation += "0"
elif (zeroes == 2):
representation += "w"
elif (zeroes == 3):
representation += "x"
else:
representation += "y"
representation += chars[zeroes - 4]
zeroes = 0
representation += chars[baudot]
return representation
# Compares strings first by length, then by lexicographical ordering.
# A hash character is worse than anything else.
def compare_representations(a, b):
if (a == "#"):
return b
elif (b == "#"):
return a
elif (len(a) < len(b)):
return a
elif (len(b) < len(a)):
return b
elif (a < b):
return a
else:
return b
g.duplicate()
g.clear(1)
canonise()
Rule modifier
B34kz5e7c8/S23-a4ityz5k
b2n3-q5y6cn7s23-k4c8
B3-kq6cn8/S2-i3-a4ciyz8
B3-kq4z5e7c8/S2-ci3-a4ciq5ek6eik7
Bored of Conway's Game of Life? Try Pedestrian Life -- not pedestrian at all!
B34kz5e7c8/S23-a4ityz5k
b2n3-q5y6cn7s23-k4c8
B3-kq6cn8/S2-i3-a4ciyz8
B3-kq4z5e7c8/S2-ci3-a4ciq5ek6eik7
Bored of Conway's Game of Life? Try Pedestrian Life -- not pedestrian at all!
- hotcrystal0
- Posts: 2208
- Joined: July 3rd, 2020, 5:32 pm
- Location: United States
Re: How to get the codes for patterns?
No, I mean the ones like $0B65$97$2e1
Code: Select all
x = 192, y = 53, rule = B3/S23
33$42b4o$41b6o$40b2ob4o$41b2o3$41b2o$39bo6bo$38bo8bo$38bo8bo$38b9o3$42b
4o$41b6o$40b2ob4o$41b2o!
Re: How to get the codes for patterns?
Welcome! RLE is definitely not something like "$0B65$97$2e1".
Do you have Golly? It should generate the RLE in your clipboard when you copy a pattern.
Re: How to get the codes for patterns?
Yep, like Hunting said, if you have Golly, you can select a pattern and then Ctrl+C it and it'll put the "code" (RLE) in your clipboard, ready to paste. On lifeviewer, click the "Sync" button first to turn enable copying to the external clipboard. After that, just Ctrl+C as usual and the RLE will be in your clipboard.
Re: How to get the codes for patterns?
Ordinarily, if a pattern hasn't started running yet, or if you hit R to reset to the T=0 version of the pattern, Ctrl+C will work fine without any need to click the Sync button.
It's only when you're doing things in LifeViewer that might create very large RLEs -- e.g., editing and running a pattern for a long time -- that the requirement to enable Sync goes into effect.
Re: How to get the codes for patterns?
When there is no selection then Ctrl+C will copy the entire pattern to both the internal (LifeViewer) and external (System) clipboards.dvgrn wrote: ↑July 3rd, 2020, 10:37 pmOrdinarily, if a pattern hasn't started running yet, or if you hit R to reset to the T=0 version of the pattern, Ctrl+C will work fine without any need to click the Sync button.
It's only when you're doing things in LifeViewer that might create very large RLEs -- e.g., editing and running a pattern for a long time -- that the requirement to enable Sync goes into effect.
When there is a selection then Ctrl+C will copy the selection to the internal (LifeViewer) clipboard. If Sync is enabled then it will also copy the selection to the external (System) clipboard.
LifeViewer https://lazyslug.com/lifeviewer
- hotcrystal0
- Posts: 2208
- Joined: July 3rd, 2020, 5:32 pm
- Location: United States
Re: How to get the codes for patterns?
I mean by “code” is script.
Code: Select all
x = 192, y = 53, rule = B3/S23
33$42b4o$41b6o$40b2ob4o$41b2o3$41b2o$39bo6bo$38bo8bo$38bo8bo$38b9o3$42b
4o$41b6o$40b2ob4o$41b2o!
- hotcrystal0
- Posts: 2208
- Joined: July 3rd, 2020, 5:32 pm
- Location: United States
Re: How to get the codes for patterns?
So how do I get the script for a pattern?
Code: Select all
x = 192, y = 53, rule = B3/S23
33$42b4o$41b6o$40b2ob4o$41b2o3$41b2o$39bo6bo$38bo8bo$38bo8bo$38b9o3$42b
4o$41b6o$40b2ob4o$41b2o!
Re: How to get the codes for patterns?
What is a specific example of a pattern that you want a script for? What kind of script (Python? Lua?) Where did you get the impression that patterns have associated scripts?
Some patterns have been converted into script form, and many others could be, but for the most part a pattern is communicated by its RLE encoding, which can be retrieved from LifeViewer or Golly via Ctrl+C, just as Hunting and Saka have said.
Trivial side note: Your double post above is a perfect example of a case where other forum users would really appreciate it if you would edit your previous message instead of posting a separate one-liner -- see the forum rules, #3a.
- hotcrystal0
- Posts: 2208
- Joined: July 3rd, 2020, 5:32 pm
- Location: United States
Re: How to get the codes for patterns?
The script for putting LifeViewers in posts.
Code: Select all
x = 192, y = 53, rule = B3/S23
33$42b4o$41b6o$40b2ob4o$41b2o3$41b2o$39bo6bo$38bo8bo$38bo8bo$38b9o3$42b
4o$41b6o$40b2ob4o$41b2o!
Re: How to get the codes for patterns?
Well, if you want to make the LifeViewer show up embedded in the post itself, click the "viewer" tag and then paste the RLE inside it. However, this is often frowned upon due to how much space it takes up, so instead it's generally preferred to use the "code" tag instead (fifth button from the left) which, if it has a valid RLE inside, will produce a "show in viewer" button that creates a popup LifeViewer window:
Code: Select all
x = 3, y = 3, rule = B3/S23
bo$2bo$3o!