Difference between revisions of "Run Length Encoded"

From LifeWiki
Jump to navigation Jump to search
(a typo; formatting; consistent formatting for bulleted lists)
(35 intermediate revisions by 10 users not shown)
Line 1: Line 1:
The '''Run Length Encoded''' (or '''RLE''' for short) file format is commonly-used for storing large [[pattern|patterns]]. It is more cryptic than some other file formats such as [[plaintext]] and [[Life 1.06]], but is still quite readable. RLE files are saved with a .rle file extension.  
The '''Run Length Encoded''' (or '''RLE''' for short) [[File formats|file format]] is commonly-used for storing [[pattern]]s. It is more cryptic than some other file formats such as [[plaintext]] and [[Life 1.06]], but is still quite readable. Many features of the RLE file format are incorporated in the [[MCell (file format)|MCell]] file format. RLE files are saved with a <tt>.rle</tt> file extension.  


==Description of format==
==Description of format==
The first line is a header line, which has the form
The first line is a header line, which has the form


<code>x = m, y = n</code>
x = m, y = n


where m and n are the width and height of the pattern, respectively. The pattern itself begins on the next line and is encoded as a sequence if items of the form &lt;run_count&gt;&lt;tag&gt;, where &lt;run_count&gt; is the number of occurrences of &lt;tag&gt; and &lt;tag&gt; is one of the following three characters:
where m and n are the width and height of the pattern, respectively. The pattern itself begins on the next line and is encoded as a sequence of items of the form &lt;run_count&gt;&lt;tag&gt;, where &lt;run_count&gt; is the number of occurrences of &lt;tag&gt; and &lt;tag&gt; is one of the following three characters:


{| class="wikitable" style="margin-left:auto;margin-right:auto;text-align:center;"
{| class="wikitable" style="margin-left:auto;margin-right:auto;text-align:center;"
Line 25: Line 25:
&lt;run_count&gt; can be omitted if it is equal to 1. The last &lt;run_count&gt;&lt;tag&gt; item is followed by a ! character. Dead cells at the end of a pattern line do not need to be encoded, nor does the end of the last line of the pattern. Whitespace is permitted between &lt;run_count&gt;&lt;tag&gt; items (and between the last &lt;run_count&gt;&lt;tag&gt; item and the following !), but except for carriage returns and line feeds this is not recommended. It is not permitted to place whitespace in the middle of a &lt;run_count&gt;&lt;tag&gt; item.
&lt;run_count&gt; can be omitted if it is equal to 1. The last &lt;run_count&gt;&lt;tag&gt; item is followed by a ! character. Dead cells at the end of a pattern line do not need to be encoded, nor does the end of the last line of the pattern. Whitespace is permitted between &lt;run_count&gt;&lt;tag&gt; items (and between the last &lt;run_count&gt;&lt;tag&gt; item and the following !), but except for carriage returns and line feeds this is not recommended. It is not permitted to place whitespace in the middle of a &lt;run_count&gt;&lt;tag&gt; item.


Lines in the RLE file must not exceed 70 characters, although it's a good idea for RLE readers to be able to cope with longer lines. DOS, Unix and Mac newline conventions are all acceptable.
Lines in the RLE file must not exceed 70 characters, although it is a good idea for RLE readers to be able to cope with longer lines. DOS, Unix and Mac newline conventions are all acceptable.


Anything after the final ! is ignored. It used to be common to put comments here (starting on a new line), but the usual method for adding comments is now by means of #C lines (see below).
Anything after the final ! is ignored. It used to be common to put comments here (starting on a new line), but the usual method for adding comments is now by means of #C lines (see below).


==Additional features==
===# lines===


The header line may be preceded by any number of lines beginning with the # character. The # character is followed by a letter indicating the type of information that line provides. These letters generally follow the conventions for [[XLife]] files, which are described in the file xlife.man in the XLife distribution. Here is a list of letters likely to be encountered in practice:
The header line may be preceded by any number of lines beginning with the # character. The # character is followed by a letter indicating the type of information that line provides. These letters generally follow the conventions for [[XLife]] files, which are described in the file <tt>xlife.man</tt> in the XLife distribution. Here is a list of letters likely to be encountered in practice:


{| class="wikitable" style="margin-left:auto;margin-right:auto;text-align:left;"
{| class="wikitable" style="margin-left:auto;margin-right:auto;text-align:left;"
Line 57: Line 57:
|-
|-
| r
| r
| Gives the [[rule]] for the pattern in the form survival_counts/birth_counts (e.g. 23/3 for Life). This line is usually present in RLE files created by XLife, but the standard method of indicating the rule is described below.<br />Example: #r 23/3
| Gives the [[rules]] for the pattern in the form survival_counts/birth_counts (e.g. 23/3 for Life). This line is usually present in RLE files created by XLife, but the standard method of indicating the rule is described below.<br />Example: #r 23/3
|}
|}
===Other features===


The rule for which the pattern is designed can be indicated in the header line, which then takes the form
The rule for which the pattern is designed can be indicated in the header line, which then takes the form


<code>x = m, y = n, rule = abc</code>
x = m, y = n, rule = abc


where abc is the rule's designation, such as B3/S23 for Life or B36/S23 for [[HighLife]]. This type of extended header line is usual whenever the pattern is not intended for Conway's Life. As with ordinary header lines, RLE writers should adhere to the spacing shown, but RLE readers are best not to assume it.
where abc is the rule's designation, such as B3/S23 for Life or B36/S23 for [[HighLife]]. This type of extended header line is usual whenever the pattern is not intended for Conway's Life. As with ordinary header lines, RLE writers should adhere to the spacing shown, but RLE readers are best not to assume it.


Letters other than b and o may be used for the <tag>s to represent extra states. Unless the cellular automaton has more than 26 states it's a good idea to stick to lowercase letters. RLE readers that cannot handle more than two states should treat all letters other than b (and perhaps B) as equivalent to o.
Letters other than b and o may be used for the <tag>s to represent extra states. Unless the cellular automaton has more than 26 states it is a good idea to stick to lowercase letters. RLE readers that cannot handle more than two states should treat all letters other than b (and perhaps B) as equivalent to o.


==Examples==
==Examples==
The following is a [[glider]] in RLE format:
The following is a [[glider]] in RLE format:


<code>
<pre>
&#35;C This is a glider.
&#35;C This is a glider.
<br />x = 3, y = 3
x = 3, y = 3
<br />3o$o$bo!
bo$2bo$3o!
</code>
</pre>


The following is the [[Gosper glider gun]] in RLE format:
The following is the [[Gosper glider gun]] in RLE format:


<code>&#35;N Gosper glider gun<br />
<pre>&#35;N Gosper glider gun
&#35;C This was the first gun discovered.<br />
&#35;C This was the first gun discovered.
&#35;C As its name suggests, it was discovered by Bill Gosper.<br />
&#35;C As its name suggests, it was discovered by Bill Gosper.
x = 36, y = 9, rule = B3/S23<br />
x = 36, y = 9, rule = B3/S23
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b<br />
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b
obo$10bo5bo7bo$11bo3bo$12b2o!
obo$10bo5bo7bo$11bo3bo$12b2o!
</code>
</pre>
 
==Downloading LifeWiki patterns==
There are four ways to obtain pattern RLEs from LifeWiki:
* Click the "show" link in the "Pattern file" section of a pattern's infobox
* For a pattern that is open in the LifeViewer: advance it a tick; rewind it; click anywhere on the grid; press <tt>Ctrl-C</tt> to copy the pattern to the clipboard
* Use a "Download RLE: click here" link under a pattern image or "RLE: here" link under an embedded LifeViewer display
* To download the entire LifeWiki pattern collection: [https://conwaylife.com/patterns/all.zip Pattern collection zip file]
 
==See also==
* [[Macrocell]]
* [[apgcode]]
* [[File formats]]
 
==External links==
* {{LinkGollyHelp|formats.html#rle|title=Extended RLE format}}
* {{LinkMirek|ca_files_formats.html|title=Cellular automata file formats}}
* {{LinkLexicon|lex_r.htm#rle}}


==External Links==
[[Category:Everything else]]
*[http://psoup.math.wisc.edu/mcell/ca_files_formats.html Cellular automata file formats] at Mirek's Cellebration
[[Category:File formats]]
*[http://www.argentum.freeserve.co.uk/lex_r.htm#rle RLE] at the Life Lexicon

Revision as of 07:16, 3 June 2022

The Run Length Encoded (or RLE for short) file format is commonly-used for storing patterns. It is more cryptic than some other file formats such as plaintext and Life 1.06, but is still quite readable. Many features of the RLE file format are incorporated in the MCell file format. RLE files are saved with a .rle file extension.

Description of format

The first line is a header line, which has the form

x = m, y = n

where m and n are the width and height of the pattern, respectively. The pattern itself begins on the next line and is encoded as a sequence of items of the form <run_count><tag>, where <run_count> is the number of occurrences of <tag> and <tag> is one of the following three characters:

<tag> description
b dead cell
o alive cell
$ end of line

<run_count> can be omitted if it is equal to 1. The last <run_count><tag> item is followed by a ! character. Dead cells at the end of a pattern line do not need to be encoded, nor does the end of the last line of the pattern. Whitespace is permitted between <run_count><tag> items (and between the last <run_count><tag> item and the following !), but except for carriage returns and line feeds this is not recommended. It is not permitted to place whitespace in the middle of a <run_count><tag> item.

Lines in the RLE file must not exceed 70 characters, although it is a good idea for RLE readers to be able to cope with longer lines. DOS, Unix and Mac newline conventions are all acceptable.

Anything after the final ! is ignored. It used to be common to put comments here (starting on a new line), but the usual method for adding comments is now by means of #C lines (see below).

# lines

The header line may be preceded by any number of lines beginning with the # character. The # character is followed by a letter indicating the type of information that line provides. These letters generally follow the conventions for XLife files, which are described in the file xlife.man in the XLife distribution. Here is a list of letters likely to be encountered in practice:

letter description
C Indicates that a line of comment follows. This is the only really common use of # lines.
Example: #C 'Twas brillig and the slithy toves
c Same as C, but not recommended.
N The name of the pattern.
Example: #N My awesome pattern
O Says when and by whom the file was created. RLE files produced by XLife usually have this line.
Example: #O John Smith john@gmail.com Fri Apr 30 19:38:52 1999
P Essentially the same as R, below. This line is produced by Life32, which generates coordinates which should represent the top-left corner of the Life pattern.
Example: #P 90 136
R Gives the coordinates of the top-left corner of the pattern. RLE files produced by XLife usually have this line, and the coordinates are usually negative, with the intention of placing the centre of the pattern at the origin.
Example: #R -22 -57
r Gives the rules for the pattern in the form survival_counts/birth_counts (e.g. 23/3 for Life). This line is usually present in RLE files created by XLife, but the standard method of indicating the rule is described below.
Example: #r 23/3

Other features

The rule for which the pattern is designed can be indicated in the header line, which then takes the form

x = m, y = n, rule = abc

where abc is the rule's designation, such as B3/S23 for Life or B36/S23 for HighLife. This type of extended header line is usual whenever the pattern is not intended for Conway's Life. As with ordinary header lines, RLE writers should adhere to the spacing shown, but RLE readers are best not to assume it.

Letters other than b and o may be used for the <tag>s to represent extra states. Unless the cellular automaton has more than 26 states it is a good idea to stick to lowercase letters. RLE readers that cannot handle more than two states should treat all letters other than b (and perhaps B) as equivalent to o.

Examples

The following is a glider in RLE format:

#C This is a glider.
x = 3, y = 3
bo$2bo$3o!

The following is the Gosper glider gun in RLE format:

#N Gosper glider gun
#C This was the first gun discovered.
#C As its name suggests, it was discovered by Bill Gosper.
x = 36, y = 9, rule = B3/S23
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b
obo$10bo5bo7bo$11bo3bo$12b2o!

Downloading LifeWiki patterns

There are four ways to obtain pattern RLEs from LifeWiki:

  • Click the "show" link in the "Pattern file" section of a pattern's infobox
  • For a pattern that is open in the LifeViewer: advance it a tick; rewind it; click anywhere on the grid; press Ctrl-C to copy the pattern to the clipboard
  • Use a "Download RLE: click here" link under a pattern image or "RLE: here" link under an embedded LifeViewer display
  • To download the entire LifeWiki pattern collection: Pattern collection zip file

See also

External links