hell0cat

``````import Data.List
import Data.Char
import System.Environment

digitsToLED :: Int -> Int -> String -> String
digitsToLED z p xs = concatMap (++"\n") \$ map joinS \$ transpose \$ map (zoom z) \$ map figlet \$ xs where
-- padW n 将字符串中间的那个字符扩充n倍，保持两端字符不动，用来扩充宽度。
padW n = \x -> [x!!0] ++ replicate n (x!!1) ++ [x!!2]
-- padH n 将每一个扩充宽度的，扩充数量 n-1，并将这些的中间横线去掉，然后在加上扩充宽度后的字符，用来拉伸高度
padH n = \x -> map (map (\c -> if c == '_' then ' ' else c)) (replicate (n-1) x) ++ [x]
zoom n st = let
hd = padW n \$ st !! 0
bd = padH n \$ padW n \$ st !! 1
ft = padH n \$ padW n \$ st !! 2
in [hd] ++ bd ++ ft
joinS = intercalate \$ concat \$ replicate p " "
-- 将字符串映射成图
figlet x    | x == '0'  = [" _ ", "| |", "|_|"]
| x == '1'  = ["   ", "  |", "  |"]
| x == '2'  = [" _ ", " _|", "|_ "]
| x == '3'  = [" _ ", " _|", " _|"]
| x == '4'  = ["   ", "|_|", "  |"]
| x == '5'  = [" _ ", "|_ ", " _|"]
| x == '6'  = [" _ ", "|_ ", "|_|"]
| x == '7'  = [" _ ", "  |", "  |"]
| x == '8'  = [" _ ", "|_|", "|_|"]
| x == '9'  = [" _ ", "|_|", " _|"]
| otherwise = ["   ", "   ", "   "] -- 或者替换成 ["   ", [' ',x,' '], [' ',x,' ']] 以保留特殊字符

main :: IO ()
main = do
args <- getArgs
let n = if length args > 0 then (\x -> read x :: Int) \$ head args else 1
let p = if length args > 1 then (\x -> read x :: Int) \$ args !! 1 else 0
let s = if length args > 2 then args !! 2 else "0123456789"
putStrLn \$ digitsToLED (max n 1) p s
``````

``````[jesse@Jesse-iMac:~/project/test/haskell\$] runhaskell led.hs
_     _  _     _  _  _  _  _
| |  | _| _||_||_ |_   ||_||_|
|_|  ||_  _|  | _||_|  ||_| _|
``````
``````[jesse@Jesse-iMac:~/project/test/haskell\$] runhaskell led.hs 2
__      __  __      __  __  __  __  __
|  |   |   |   ||  ||   |      ||  ||  |
|  |   | __| __||__||__ |__    ||__||__|
|  |   ||      |   |   ||  |   ||  |   |
|__|   ||__  __|   | __||__|   ||__| __|

``````
``````[jesse@Jesse-iMac:~/project/test/haskell\$] runhaskell led.hs 3
___       ___  ___       ___  ___  ___  ___  ___
|   |    |    |    ||   ||    |        ||   ||   |
|   |    |    |    ||   ||    |        ||   ||   |
|   |    | ___| ___||___||___ |___     ||___||___|
|   |    ||        |    |    ||   |    ||   |    |
|   |    ||        |    |    ||   |    ||   |    |
|___|    ||___  ___|    | ___||___|    ||___| ___|

``````

``````[jesse@Jesse-iMac:~/project/test/haskell\$] ghc -o led led.hs
[jesse@Jesse-iMac:~/project/test/haskell\$] watch -n 1 './led 2 1 \$(date "+%T")'
``````

### 评论(3)

#### 引用来自“蓝水晶飞机”的评论

Jeff.Zhong
2018/08/08
0
0

anddlecn
2016/09/06
0
0

0x11901
2018/07/01
0
0
【目录】电子发烧友, 持续更新

990487026
2015/09/26
0
0
pcDuino运行LED Matrix Kit

LED Matrix Kit是一种串行驱动的 8×8 LED 点阵屏套件，由MAX7219供电，使用只需要简单的三根数据线和两根电源线，并且兼容于Arduino。现在我想在pcDuino上运行 LED Matrix ，让它显示一个完...

pc朵拉
2013/07/02
0
0

Hanlp中N最短路径分词详细介绍

N-最短路径 是中科院分词工具NLPIR进行分词用到的一个重要算法，张华平、刘群老师在论文《基于N-最短路径方法的中文词语粗分模型》中做了比较详细的介绍。该算法算法基本思想很简单，就是给定...

32分钟前
1
0
es 在数据量很大的情况下（数十亿级别）如何提高查询效率啊？

33分钟前
7
0
php面试题常见面试题

39分钟前
3
0

50分钟前
1
0

#个人习惯或要求安装目录cd /usr/local/mkdir rediscd redis#下载rediswget http://download.redis.io/releases/redis-5.0-rc4.tar.gz#解压tar -zxvf redis-5.0-rc4.tar.gz ...

56分钟前
1
0