74 bool parse_steps(
const char *text, std::size_t &
out)
76 if (text ==
nullptr or text[0] ==
'-')
80 const unsigned long long value = std::strtoull(text, &end, 10);
81 if (errno == ERANGE or end == text or *end !=
'\0'
82 or
value > std::numeric_limits<std::size_t>::max())
84 out =
static_cast<std::size_t
>(
value);
88 std::vector<std::pair<int, int>> pattern_for(
const std::string &name)
90 if (name ==
"blinker")
91 return {{0, -1}, {0, 0}, {0, 1}};
92 if (name ==
"r-pentomino")
93 return {{0, 1}, {0, 2}, {1, 0}, {1, 1}, {2, 1}};
96 {4,0}, {4,1}, {5,0}, {5,1},
97 {2,12}, {2,13}, {3,11}, {3,15}, {4,10}, {4,16},
98 {5,10}, {5,14}, {5,16}, {5,17}, {6,10}, {6,16},
99 {7,11}, {7,15}, {8,12}, {8,13},
100 {0,24}, {1,22}, {1,24}, {2,20}, {2,21}, {3,20},
101 {3,21}, {4,20}, {4,21}, {5,22}, {5,24}, {6,24},
102 {2,34}, {2,35}, {3,34}, {3,35}
104 return {{0, 1}, {1, 2}, {2, 0}, {2, 1}, {2, 2}};
107 void stamp(Grid &grid,
110 const std::vector<std::pair<int, int>> &cells)
114 for (
const auto &[dr, dc] : cells)
122 void write_final_exports(
const std::filesystem::path &dir,
124 const std::string &pattern,
128 std::ofstream
out(dir /
"final.rle");
130 opts.
name = pattern +
" after " + std::to_string(
steps) +
" steps";
131 opts.
comment =
"Generated by Aleph::CA ca_export_example";
136 std::ofstream
out(dir /
"final.csv");
140 std::ofstream
out(dir /
"final.json");
143 opts.
rule =
"B3/S23";
147 std::ofstream
out(dir /
"final.tex");
161 std::size_t
steps = 32;
162 if (argc >= 2
and not parse_steps(argv[1],
steps))
164 std::cerr <<
"Invalid steps argument\n";
168 const std::filesystem::path out_dir = argc >= 3 ? argv[2] :
"ca_export_output";
169 const std::string pattern = argc >= 4 ? argv[3] :
"glider";
173 if (pattern ==
"gosper")
180 pattern_for(pattern));
184 const auto frames_dir = out_dir /
"frames";
187 stream_opts.
prefix =
"frame";
188 stream_opts.
format = Frame_Output_Format::PPM;
192 for (std::size_t t = 0; t <=
steps; ++t)
200 std::filesystem::create_directories(out_dir);
201 write_final_exports(out_dir,
engine.frame(), pattern,
steps);
204 <<
" frames to " << frames_dir <<
'\n';
205 std::cout <<
"Final snapshots: " << (out_dir /
"final.rle") <<
", "
206 << (out_dir /
"final.csv") <<
", "
207 << (out_dir /
"final.json") <<
", "
208 << (out_dir /
"final.tex") <<
'\n';
size_t size_t int32_t value
size_t size_t int32_t * out
Convenience builders for the Phase 3 synchronous engine.
Directory-backed frame sinks for CA trajectories.
File-format readers and writers for cellular-automata frames.
TikZ renderers for cellular-automata frames.
Common typedefs and tag types for the Cellular Automata module.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Directory-backed sink for CA frames.
std::string montage_command_hint(const std::string &output_file="ca.mp4", unsigned fps=24) const
Return an ffmpeg command hint for the current frame sequence.
void accept(std::size_t step, const Lattice &frame)
Accept a frame and write it if it passes the stride filter.
const Array< std::pair< std::size_t, std::filesystem::path > > & written_frames() const noexcept
Return the frame files written so far.
void flush() const
Write the optional manifest.
Lattice that adds boundary-aware access on top of a storage.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
void write_rle(std::ostream &out, const Lattice &frame, const RLE_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
Write a 2D frame in Conway RLE format.
Game_Of_Life_Engine make_gol_engine(ca_size_t rows, ca_size_t cols)
Build a Conway's Game of Life engine of the given shape.
void write_csv(std::ostream &out, const Lattice &frame, const CSV_Options &opts={})
Write a numeric CSV snapshot.
void write_json(std::ostream &out, const Lattice &frame, const JSON_Write_Options &opts={})
Write a JSON snapshot.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
void render_lattice_tikz(std::ostream &out, const Lattice &frame, Palette &&palette, const Rect_Tikz_Options &opts={})
Render any supported 2D CA lattice as TikZ.
and
Check uniqueness with explicit hash + equality functors.
Default binary TikZ palette.
Options for directory-backed frame streams.
std::filesystem::path directory
destination directory
Frame_Output_Format format
exporter format
std::string prefix
filename prefix
std::size_t zero_pad
step field width in filenames
Options controlling JSON snapshot output.
bool pretty
pretty-print with indentation
std::string rule
optional rule field
Options controlling Conway RLE output.
std::string comment
optional #C lines, split on newlines
bool trim_dead_border
crop to the live-cell bounding box
std::string name
optional #N line
TikZ rendering options for rectangular frames.
double cell_size
cell side length in centimetres
std::string grid_colour
TikZ colour used for grid lines.
The lattice wraps around on every axis.
Cellular automata lattice with pluggable boundary policies.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).