Generate a byte-stable preview PNG for every docs snippet, as the visual- regression oracle foundation of #381. A changed image means the snippet's behaviour changed and wants review. Pipeline (no C++ change; existing headless build suffices): - _seed.py: chained as the FIRST --exec so random.seed(42) governs the snippet's RNG before it draws (snippets draw at import; seeding after is too late). Shared-interpreter seeding covers all 25 random-module snippets. - _screenshot.py: chained as the LAST --exec; steps setup frames then automation.screenshot(). Kept separate from _harness.py so the pass/fail suite stays fast and untouched. - tools/generate_snippet_shots.py: orchestrator; runs seed->snippet->shot, writes gitignored snippet-shots/ (images belong in the doc-site repo, which pulls them from here). Per-snippet capture params live in a sidecar OVERRIDES table, not the mcrf: header (which would fight stamp_snippets and can't hold Phase-3 interaction scripts). - make snippet-shots target; snippet-shots/ gitignored. The 4 BSP snippets that needed deterministic pixels (060, 102, 224, 243) now pass seed=42 — libtcod's global RNG is time(0)-seeded and unreachable from Python, and seed= also documents reproducible generation for readers. Validated: 272 captured, 10 skipped (noshot opt-outs), 0 failed; all 272 byte-identical across two full runs (~49s). Addresses #381. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LTh2ZW7bd3XSd9qK86Z2CE
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# mcrf: objects=[BSP,Color,ColorLayer,Grid,HeightMap,NoiseSource,Scene] verified=0.2.8-dev status=ok
|
|
import mcrfpy
|
|
|
|
scene = mcrfpy.Scene("heightmap-demo")
|
|
mcrfpy.current_scene = scene
|
|
|
|
grid = mcrfpy.Grid(grid_size=(20, 20))
|
|
scene.children.append(grid)
|
|
|
|
# Create a heightmap
|
|
hmap = mcrfpy.HeightMap((20, 20))
|
|
|
|
# Method chaining for terrain generation
|
|
hmap.fill(0.5).add_hill((10, 10), 8, 0.3).normalize()
|
|
|
|
# Subscript access
|
|
value = hmap[5, 5]
|
|
|
|
# Combine multiple heightmaps
|
|
noise_source = mcrfpy.NoiseSource(dimensions=2, algorithm='simplex', seed=42)
|
|
noise_map = noise_source.sample((20, 20))
|
|
hmap.multiply(noise_map) # Apply as mask
|
|
|
|
# Convert BSP to heightmap
|
|
bsp = mcrfpy.BSP(pos=(0, 0), size=(20, 20))
|
|
bsp.split_recursive(depth=3, min_size=(4, 4), seed=42)
|
|
rooms = bsp.to_heightmap(select='leaves', shrink=1)
|
|
hmap.add(rooms)
|
|
|
|
# Visualize the heightmap on the grid via a ColorLayer gradient
|
|
color_layer = mcrfpy.ColorLayer(z_index=1, name="height_color")
|
|
grid.add_layer(color_layer)
|
|
color_layer.apply_gradient(hmap, (0.0, 1.0), mcrfpy.Color(0, 0, 0), mcrfpy.Color(255, 255, 255))
|