Skip to content

Instantly share code, notes, and snippets.

@PEZ
Created June 14, 2022 22:30
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 PEZ/e93d3c6781b5ecbf72de507b64caf6cf to your computer and use it in GitHub Desktop.
Save PEZ/e93d3c6781b5ecbf72de507b64caf6cf to your computer and use it in GitHub Desktop.
flf2a$ 6 4 6 -1 4
3x5 font by Richard Kirk (rak@crosfield.co.uk).
Ported to figlet, and slightly changed (without permission :-})
by Daniel Cabeza Gras (bardo@dia.fi.upm.es)
@
@
@
@
@
@@
@
# @
# @
# @
@
# @@
@
# # @
# # @
@
@
@@
@
# # @
### @
# # @
### @
# # @@
@
## @
## @
### @
## @
## @@
@
# # @
# @
# @
# @
# # @@
@
# @
# @
## @
# # @
### @@
@
# @
# @
# @
@
@@
@
# @
# @
# @
# @
# @@
@
# @
# @
# @
# @
# @@
@
# @
### @
# @
### @
# @@
@
@
# @
### @
# @
@@
@
@
@
@
# @
# @@
@
@
@
### @
@
@@
@
@
@
@
@
# @@
@
# @
# @
# @
# @
# @@
@
### @
# # @
# # @
# # @
### @@
@
# @
## @
# @
# @
### @@
@
### @
# @
### @
# @
### @@
@
### @
# @
## @
# @
### @@
@
# # @
# # @
### @
# @
# @@
@
### @
# @
### @
# @
### @@
@
### @
# @
### @
# # @
### @@
@
### @
# @
# @
# @
# @@
@
### @
# # @
### @
# # @
### @@
@
### @
# # @
### @
# @
### @@
@
@
# @
@
# @
@@
@
@
# @
@
# @
# @@
@
# @
# @
# @
# @
# @@
@
@
### @
@
### @
@@
@
# @
# @
# @
# @
# @@
@
### @
# @
## @
@
# @@
@
### @
# # @
# @
### @
@@
@
# @
# # @
### @
# # @
# # @@
@
## @
# # @
## @
# # @
## @@
@
## @
# @
# @
# @
## @@
@
## @
# # @
# # @
# # @
## @@
@
### @
# @
## @
# @
### @@
@
### @
# @
## @
# @
# @@
@
## @
# @
# # @
# # @
## @@
@
# # @
# # @
### @
# # @
# # @@
@
### @
# @
# @
# @
### @@
@
## @
# @
# @
# # @
# @@
@
# # @
# # @
## @
# # @
# # @@
@
# @
# @
# @
# @
### @@
@
# # @
### @
### @
# # @
# # @@
@
### @
# # @
# # @
# # @
# # @@
@
# @
# # @
# # @
# # @
# @@
@
## @
# # @
## @
# @
# @@
@
# @
# # @
# # @
## @
# @@
@
## @
# # @
## @
# # @
# # @@
@
## @
# @
# @
# @
## @@
@
### @
# @
# @
# @
# @@
@
# # @
# # @
# # @
# # @
### @@
@
# # @
# # @
# # @
# # @
# @@
@
# # @
# # @
### @
### @
# # @@
@
# # @
# # @
# @
# # @
# # @@
@
# # @
# # @
# @
# @
# @@
@
### @
# @
# @
# @
### @@
@
## @
# @
# @
# @
## @@
@
# @
# @
# @
# @
# @@
@
## @
# @
# @
# @
## @@
@
# @
# # @
@
@
@@
@
@
@
@
@
### @@
@
# @
# @
# @
@
@@
@
@
## @
# # @
### @
@@
@
# @
### @
# # @
### @
@@
@
@
### @
# @
### @
@@
@
# @
### @
# # @
### @
@@
@
@
### @
## @
### @
@@
@
## @
# @
### @
# @
## @@
@
@
### @
# # @
## @
### @@
@
# @
### @
# # @
# # @
@@
@
# @
@
# @
## @
@@
@
# @
@
# @
# @
# @@
@
# @
# # @
## @
# # @
@@
@
# @
# @
# @
## @
@@
@
@
### @
### @
# # @
@@
@
@
## @
# # @
# # @
@@
@
@
### @
# # @
### @
@@
@
@
### @
# # @
### @
# @@
@
@
### @
# # @
### @
# @@
@
@
### @
# @
# @
@@
@
@
## @
# @
## @
@@
@
# @
### @
# @
## @
@@
@
@
# # @
# # @
### @
@@
@
@
# # @
# # @
# @
@@
@
@
# # @
### @
### @
@@
@
@
# # @
# @
# # @
@@
@
@
# # @
### @
# @
### @@
@
@
## @
# @
## @
@@
@
## @
# @
## @
# @
## @@
@
# @
# @
# @
# @
# @@
@
## @
# @
## @
# @
## @@
@
# @
### @
# @
@
@@
@
# # @
# @
# # @
### @
# # @@
@
# # @
### @
# # @
# # @
### @@
@
# # @
@
# # @
# # @
### @@
@
# # @
## @
# # @
### @
@@
@
# # @
### @
# # @
### @
@@
@
# # @
@
# # @
### @
@@
@
### @
## @
# # @
## @
# @@
(ns figlet-writing
(:require [clojure.string :as string]
[clojure.edn :as edn]))
;; 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")})
(defn transpose [v]
(apply mapv vector v))
(defn display
"Returns `sentence` rendered as lines of ascii-chars as defined by the FIGFont of `font`"
[font sentence]
(let [alphabet (glyphs font)]
(assert (some? alphabet) (str "Font " font " not found. Available fonts: '" (keys glyphs)))
(let [lines (string/split-lines sentence)]
(flatten
(map (fn [line]
(->> (if (empty? line) " " line)
(map alphabet)
(transpose)
(map #(apply str %))))
lines)))))
(comment
(fig-parse "../repl_sessions/ansi-regular.fif")
(display :3x5 "Hello World")
(display :ansi-regular "Hello\nWorld!")
(display :banner3 "Hello\nWorld!")
(display :no-such-font "Hello World")
)
(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\")})")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment