|
(ns pez-writing-in-the-sky |
|
"Writing with blocks in the sky. |
|
(Limited by my use of a seven-segment display simulation I had lying around.)" |
|
(:require [lambdaisland.witchcraft :as wc] |
|
[figlet-writing :as writing])) |
|
|
|
(def me (wc/player)) |
|
|
|
(comment |
|
(wc/fly! me) |
|
(wc/teleport me [4371 62.875 2477]) |
|
) |
|
|
|
;; The figlet-writing/display gives us rows/slíces of strings with |
|
;; either "#", where there should be a block, or " " where there |
|
;; shouldn't be one. |
|
;; All we do here is prepend each slice with its y coordinate. |
|
|
|
(defn sentence-slices [font sentence] |
|
(let [rows (writing/display font sentence)] |
|
(map (fn [y row] |
|
[y row]) |
|
(range (count rows) 0 -1) |
|
rows))) |
|
|
|
(comment |
|
(sentence-slices :3x5 "Love") |
|
;; => ([6 " "] |
|
;; [5 "# "] |
|
;; [4 "# ### # # ### "] |
|
;; [3 "# # # # # ## "] |
|
;; [2 "# ### # ### "] |
|
;; [1 "### "]) |
|
) |
|
|
|
;; Turn a slice into a sequence of the blocks needed. |
|
|
|
(defn y-block-slice [material [y sentence-slice]] |
|
(keep-indexed (fn [x c] |
|
(when-not (= \space c) |
|
{:x x :y y :z -50 :material material})) |
|
sentence-slice)) |
|
|
|
(comment |
|
(def anchor (wc/loc (wc/player))) |
|
|
|
;; I hope you like pink. =) |
|
(wc/set-blocks (->> "Hello\nWorld!" |
|
(sentence-slices :3x5) |
|
(map (partial y-block-slice :pink-wool)) |
|
flatten) |
|
{:anchor anchor}) |
|
|
|
(wc/undo!) |
|
|
|
(def s2 "(defn y-block-slice [material [y sentence-slice]] |
|
(keep-indexed (fn [x c] |
|
(when-not (= \\space c) |
|
{:x x :y y :z -50 :material material})) |
|
sentence-slice))") |
|
(def s ";; Crudest ever FIGdriver |
|
;; http://www.jave.de/figlet/figfont.html |
|
|
|
(def fig-chars (let [ascii (range 32 127 1) |
|
german [196 214 220 228 246 252 223] |
|
all (into (vec ascii) german)] |
|
(map char all))) |
|
|
|
(defn fig-parse [fif-file] |
|
(let [text (slurp fif-file) |
|
lines (string/split-lines text) |
|
[_signature height-s _base-line _max-length _old-layout comment-lines-s] (string/split (first lines) #\"\\s+\") |
|
height (edn/read-string height-s) |
|
comment-lines (edn/read-string comment-lines-s) |
|
glyph-lines (drop (inc comment-lines) lines) |
|
glyph-chunks (partition height glyph-lines) |
|
glyphs (map (fn [chunk] |
|
(map (fn [slice] |
|
(let [spaced-slice (string/replace slice #\"[ $ ]\" \" \")] |
|
(subs spaced-slice 0 (.indexOf slice \"@\")))) |
|
chunk)) |
|
glyph-chunks)] |
|
(->> glyphs |
|
(interleave fig-chars) |
|
(apply hash-map)))) |
|
|
|
(def glyphs {:3x5 (fig-parse \"../repl_sessions/3x5.fif\") |
|
:ansi-regular (fig-parse \"../repl_sessions/ansi-regular.fif\") |
|
:banner3 (fig-parse \"../repl_sessions/banner3.fif\")})") |
|
) |