scmJS docs

Fog

trigscript/fog draws pictures in the fog of war. The fog is a canvas that starts every frame dark: what a program lights this frame is what shows this frame. Watch it on the minimap, where a tile is a pixel. The Bad Apple!! showcase is a video played this way.

import { fog } from "trigscript/fog";

const heart = fog.picture([".##.##.", "#######", ".#####.", "..###.."]);

program(async () => {
  fog.reveal(P1);                    // the whole map lit once: from now on, dark is fog and not black
  while (true) {
    const m = first({ owner: P1, type: units.TerranMarine });
    if (m) fog.light(P1, m.x >> 5, m.y >> 5, 3 + ((memory.game.frame >> 3) % 6));   // a disc that pulses round the Marine
    fog.light(P1, 60, 40, heart);    // a picture, its top left on tile (60, 40)
    await nextFrame();
  }
});

How it draws. A brush is a flying unit made on a tile and taken away in the same frame; the tiles its sight revealed stay lit through that frame. Its size is the unit's sight range, so there are eleven brushes, sizes 1 (3 tiles across) to 11 (23 across), each a flying hero that ordinary maps do not place: Kukulza's Mutalisk and Guardian, Yggdrasill, the Magellan, Gantrithor, the Hyperion, the Norad II, Tom Kazansky, Danimoth, Mojo and Artanis. A map that places one of them will see odd sight from it. The game makes about 800 brushes a frame at most. Tiles count from the map's top left, (0, 0).

There is no dark brush, since the game's sight only ever reveals. To draw dark shapes, light around them: a picture with { ink: "dark" }. Dark ink is also the sharper one: a lit part is at least a brush wide, while a dark line one tile wide stays one tile wide.

What it looks like. With Classic graphics (Options ▸ Graphics), a tile is one pixel of the minimap, sharp; Remastered graphics blurs it a few tiles wide. The tiles under the picture decide how far apart lit and fog look. On Remastered's minimap, plain snow of the Ice tileset is the brightest board.

Name What it does
fog.reveal(player) Light the whole map once, so dark shows as fog (grey) rather than as never seen (black). Takes a frame.
fog.light(player, x, y, size) A disc of size 1 to 11, centred on tile (x, y), this frame.
fog.light(player, x, y, picture) A picture, its top left on tile (x, y).
fog.light(player, x, y, video, frame) Frame frame of a video the script imports.
fog.picture(rows, { ink? }) A picture from rows of text, # the ink, made when the script is built. Takes an image's halftone() too.
fog.rect(player, x, y, width, height) A lit rectangle, all five of which may change every frame: a wall, a bar of a chart.
fog.columns(player, x, y, layout, heights, faces?) Columns side by side, each as tall as the program says: the walls of a raycaster, a bar chart.
fog.play(player, video, x?, y?) Play a video, a frame of it every frame; resolves at its end.
fog.show(n) Keep this frame's picture for n frames and wait them out: a picture drawn every other frame at half the cost.
fog.SHAPES Each brush's shape, as rows of text.

The module adds a program of its own, which clears the board every frame, and it takes one of the map's free locations. Pictures and videos come from files the script imports (Files the script imports).