45std::size_t parse_size(
const char *text,
const std::size_t fallback)
50 const unsigned long value = std::strtoul(text, &end, 10);
51 if (end == text or *end !=
'\0' or
value == 0
52 or
value > std::numeric_limits<std::size_t>::max())
54 return static_cast<std::size_t
>(
value);
57double seeded_noise(
const std::uint64_t master,
const Coord_Vec<2> &coord)
59 const std::uint64_t
h = cell_seed<2>(master, 0, coord);
60 return static_cast<double>(
h >> 11) * (1.0 / 9007199254740992.0) - 0.5;
63void seed_initial_frame(Gray_Lattice &lat)
65 constexpr std::uint64_t
seed = 0x5eed1234abcddcbaull;
71 side = std::min(side, std::min(
rows,
cols));
76 for (
ca_size_t c = c0; c < c0 + side; ++c)
79 const double z = 0.03 * seeded_noise(
seed, coord);
80 lat.set(coord, Cell{0.50 + z, 0.25 - z});
84std::uint8_t byte(
const double value)
86 const double x = std::clamp(
value, 0.0, 1.0);
87 return static_cast<std::uint8_t
>(255.0 * x + 0.5);
90struct Gray_Scott_Colour
92 [[nodiscard]]
RGB8 operator()(
const Cell &
cell)
const noexcept
95 byte(1.35 * (1.0 -
cell.u)),
96 byte(0.25 + 1.7 * (
cell.u -
cell.v))};
103 const std::string
output = argc >= 2 ? argv[1] :
"gray_scott.html";
104 const std::size_t
steps = argc >= 3 ? parse_size(argv[2], 360) : 360;
107 Gray_Lattice lat({n, n}, Cell{1.0, 0.0});
108 seed_initial_frame(lat);
118 opts.
title =
"Gray-Scott reaction diffusion";
123 const std::size_t stride = std::max<std::size_t>(1,
steps / 48);
124 for (std::size_t step = 0; step <=
steps; ++step)
126 if (step % stride == 0)
133 std::cout <<
"Wrote " << html.size() <<
" Gray-Scott frames to " <<
output <<
'\n';
static int cell(const aleph_ca_engine_t *e, size_t r, size_t c)
size_t size_t int32_t value
Self-contained HTML trajectory player for CA frames.
Fixed 2-D convolution kernels for continuous cellular automata.
Reproducible random-number support for stochastic CA rules (Phase 8).
Gray-Scott reaction-diffusion rule.
Sink that writes a self-contained HTML playback file.
Lattice that adds boundary-aware access on top of a storage.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Synchronous double-buffered engine.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Options for generated HTML players.
unsigned cell_size
canvas pixel size per CA cell
unsigned fps
playback frames per second
std::string title
document title
Zero-gradient (Neumann) boundary.
RGB byte triplet used by PPM exporters.
Two-field state for reaction-diffusion cellular automata.
Continuous and memory-bearing CA rules (Phase 9).
Synchronous double-buffered engine for cellular automata.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).