Skip to content

Instantly share code, notes, and snippets.

@postspectacular
Last active July 9, 2022 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save postspectacular/0b34cb1dd67df2351a8d2a7d0d18d604 to your computer and use it in GitHub Desktop.
Save postspectacular/0b34cb1dd67df2351a8d2a7d0d18d604 to your computer and use it in GitHub Desktop.
Tiny ASCII art demo for https://thi.ng/text-canvas showing how to compose an overlay image with transparency mask with another text canvas...
import { SYSTEM } from "@thi.ng/random";
import { blitMask, canvas, canvasFromText, formatCanvas, hline } from "@thi.ng/text-canvas";
// overlay text canvas
const logo = canvasFromText([
"########### #### #### # #######",
"######### ░░░ ## ░░░ ## ░░░ ░░░░░░ ░░░░░░ ######",
"######## ░░░░░░░░░ ░░░░░░░░░ ░░░░░░░░░ ░░░░ ░░░░ #######",
"####### ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ #######",
"####### ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ #######",
"####### ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ #######",
"####### █░▓█▓▓▓█░▓█ █▓▓▓▓▓▓▓█ █░▓█ █░▓█ █░▓█ #######",
"####### █░░█ █░░█ █░░█ █░░█ █░░█ █░░█ #######",
"####### ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ #######",
"####### ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ #######",
"####### ░██░ ░██░ ░███████░ ░███████░ ░▒██▒░ ░▒██▒░ ######",
"##### ##",
"### ░░░ ░░░ ░░░ ░░░░░░░░░ ░░░░░░░░░░ ##",
"## ░░░░░░░░░ ░░░░░░░░░ ░░░░░░░░░ ░░░░░░░░░░░ ░░░░░░░░░░░ ##",
"## ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ##",
"## ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ #####",
"## ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓███████ #####",
"## █▓▓▓▓▓▓▓█ █░▓█ █░▓█▓▓▓█░▓█ █░▓▓▓▓▓▓▓█ █░▓▓▓▓▓█ #####",
"## █░░█ █░░█ █░░█ █░░█ █░░█ █░░█ #####",
"## ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ##### ▓▒▒▓ ##",
"## ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ##### ▒▓▓▓▓▓▓▓▓▓▒ ##",
"## ░███████░ ░███████░ ░██░ ░██░ ░██░ ##### ░████████░ ##",
"### ###### ##",
]);
// background text canvas
const bg = canvas(logo.width + 40, logo.height + 10, 0);
const w2 = bg.width >> 1;
// draw random & centered horizontal lines
for (let y = 0; y < bg.height; y++) {
const n = SYSTEM.minmaxInt(30, w2);
hline(bg, w2 - n, y, n * 2, "=", "=", "=");
}
// paste overlay image (using `#` for transparency mask)
blitMask(bg, w2 - logo.width / 2, 5, logo, "#");
console.log(formatCanvas(bg));
// ======================================================================================================
// ==============================================================================================
// ==================================================================================================
// ============================================================
// ====================================================================
// ============= ==== ==== = ==========
// ======================= ░░░ == ░░░ == ░░░ ░░░░░░ ░░░░░░ =====================
// ============= ░░░░░░░░░ ░░░░░░░░░ ░░░░░░░░░ ░░░░ ░░░░ =============
// ================= ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ==================
// ========= ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ==========
// =============== ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ ================
// ==== █░▓█▓▓▓█░▓█ █▓▓▓▓▓▓▓█ █░▓█ █░▓█ █░▓█ =====
// === █░░█ █░░█ █░░█ █░░█ █░░█ █░░█ ====
// == ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ===
// ======================= ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ========================
// ============ ░██░ ░██░ ░███████░ ░███████░ ░▒██▒░ ░▒██▒░ ============
// ================ ==============
// ================= ░░░ ░░░ ░░░ ░░░░░░░░░ ░░░░░░░░░░ =================
// ====== ░░░░░░░░░ ░░░░░░░░░ ░░░░░░░░░ ░░░░░░░░░░░ ░░░░░░░░░░░ =======
// =================== ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ░▒▒░ ====================
// ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ===
// ==================== ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓██▓ ▓███████ ========================
// = █▓▓▓▓▓▓▓█ █░▓█ █░▓█▓▓▓█░▓█ █░▓▓▓▓▓▓▓█ █░▓▓▓▓▓█ =====
// █░░█ █░░█ █░░█ █░░█ █░░█ █░░█ =
// ========== ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ▓▒▒▓ ===== ▓▒▒▓ ===========
// ===== ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ▒▓▓▒ ===== ▒▓▓▓▓▓▓▓▓▓▒ ======
// ============= ░███████░ ░███████░ ░██░ ░██░ ░██░ ===== ░████████░ ==============
// ======
// ==============================================================================================
// ==================================================================
// ============================================================================================================
// ==========================================================================================================
// ==================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment