How to get the codes for patterns?

For discussion directly related to ConwayLife.com, such as requesting changes to how the forums or home page function.
Post Reply
User avatar
hotcrystal0
Posts: 2114
Joined: July 3rd, 2020, 5:32 pm
Location: United States

How to get the codes for patterns?

Post by hotcrystal0 » July 3rd, 2020, 8:42 pm

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!

User avatar
yujh
Posts: 3066
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?

Post by yujh » July 3rd, 2020, 8:52 pm

hotcrystal0 wrote:
July 3rd, 2020, 8:42 pm
Can anyone tell me how to get the code for various patterns?
Do you mean apgcode?

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()
(py)
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!

User avatar
hotcrystal0
Posts: 2114
Joined: July 3rd, 2020, 5:32 pm
Location: United States

Re: How to get the codes for patterns?

Post by hotcrystal0 » July 3rd, 2020, 8:55 pm

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!

Hunting
Posts: 4395
Joined: September 11th, 2017, 2:54 am

Re: How to get the codes for patterns?

Post by Hunting » July 3rd, 2020, 9:03 pm

hotcrystal0 wrote:
July 3rd, 2020, 8:55 pm
No, I mean the ones like $0B65$97$2e1
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.

User avatar
Saka
Posts: 3627
Joined: June 19th, 2015, 8:50 pm
Location: Indonesia
Contact:

Re: How to get the codes for patterns?

Post by Saka » July 3rd, 2020, 9:43 pm

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.

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

Re: How to get the codes for patterns?

Post by dvgrn » July 3rd, 2020, 10:37 pm

Saka wrote:
July 3rd, 2020, 9:43 pm
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.
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.

User avatar
rowett
Moderator
Posts: 3776
Joined: January 31st, 2013, 2:34 am
Location: UK
Contact:

Re: How to get the codes for patterns?

Post by rowett » July 3rd, 2020, 11:10 pm

dvgrn wrote:
July 3rd, 2020, 10:37 pm
Saka wrote:
July 3rd, 2020, 9:43 pm
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.
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.
When there is no selection then Ctrl+C will copy the entire pattern to both the internal (LifeViewer) and external (System) clipboards.
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.

User avatar
hotcrystal0
Posts: 2114
Joined: July 3rd, 2020, 5:32 pm
Location: United States

Re: How to get the codes for patterns?

Post by hotcrystal0 » July 4th, 2020, 4:26 pm

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!

User avatar
hotcrystal0
Posts: 2114
Joined: July 3rd, 2020, 5:32 pm
Location: United States

Re: How to get the codes for patterns?

Post by hotcrystal0 » July 4th, 2020, 4:28 pm

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!

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

Re: How to get the codes for patterns?

Post by dvgrn » July 4th, 2020, 6:27 pm

hotcrystal0 wrote:
July 4th, 2020, 4:28 pm
So how do I get the script for a pattern?
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.

User avatar
hotcrystal0
Posts: 2114
Joined: July 3rd, 2020, 5:32 pm
Location: United States

Re: How to get the codes for patterns?

Post by hotcrystal0 » July 5th, 2020, 10:50 am

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!

User avatar
Ian07
Moderator
Posts: 891
Joined: September 22nd, 2018, 8:48 am
Location: New Jersey, US

Re: How to get the codes for patterns?

Post by Ian07 » July 5th, 2020, 11:27 am

hotcrystal0 wrote:
July 5th, 2020, 10:50 am
The script for putting LifeViewers in posts.
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!

Post Reply