Last active
July 9, 2022 20:48
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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