#:g1: com.informatimago.common-lisp.pictureの紹介

Posted 2014-10-27 15:00:00 GMT

(LISP Library 365参加エントリ)

 LISP Library 365 の301日目です。

com.informatimago.common-lisp.pictureとはなにか

 com.informatimago.common-lisp.pictureは、Pascal Bourguignon氏作の主にコンスセルのアスキーアートの描画機能を持つアスキーアートのライブラリです。

パッケージ情報

パッケージ名com.informatimago.common-lisp.picture
Quicklisp

インストール方法

(ql:quickload :com.informatimago.common-lisp.picture)

で対象のライブラリのみ。または、

(ql:quickload :com.informatimago.common-lisp)

で他のライブラリも一緒に読み込めます。

試してみる

 comp.lang.lispでは色々な質問の回答者としてお馴染のPascal Bourguignon氏ですが、com.informatimago.common-lispというライブラリ集を作っていて、様々なものが収められています。
今回紹介するcom.informatimago.common-lisp.pictureは2つのパッケージから構成されていますが、picutureの方は汎用のアスキーアートのライブラリで、cons-to-asciiはコンスセルのアスキーアートを作成するライブラリです。

(defvar *tree* '(-9 (-2 (9 10))))
*tree*
;=>  (-9 (-2 (9 10)))

(use-package '(:com.informatimago.common-lisp.picture.cons-to-ascii :com.informatimago.common-lisp.picture.picture))

(draw-list *tree*) ;=> +-----------------------------------------------+ ; | (-9 (-2 (9 10))) | ; | | ; | +---+---+ +---+---+ | ; | | * | * |-->| * |NIL| | ; | +---+---+ +---+---+ | ; | | | | ; | v v | ; | +----+ +---+---+ +---+---+ | ; | | -9 | | * | * |-->| * |NIL| | ; | +----+ +---+---+ +---+---+ | ; | | | | ; | v v | ; | +----+ +---+---+ +---+---+ | ; | | -2 | | * | * |-->| * |NIL| | ; | +----+ +---+---+ +---+---+ | ; | | | | ; | v v | ; | +---+ +----+ | ; | | 9 | | 10 | | ; | +---+ +----+ | ; +-----------------------------------------------+ ;

(let ((p (frame-rect (make-instance 'picture :width 72 :height 30 :background ".") 0 0 74 30))) (draw-cell p 2 25 *tree*)) ;=> +----------------------------------------------------------------------- ; |....................................................................... ; |....................................................................... ; |....................................................................... ; |.+---+---+...+---+---+................................................. ; |.| * | * |-->| * |NIL|................................................. ; |.+---+---+...+---+---+................................................. ; |...|...........|....................................................... ; |...v...........v....................................................... ; |.+----+......+---+---+...+---+---+..................................... ; |.|.-9.|......| * | * |-->| * |NIL|..................................... ; |.+----+......+---+---+...+---+---+..................................... ; |...............|...........|........................................... ; |...............v...........v........................................... ; |.............+----+......+---+---+...+---+---+......................... ; |.............|.-2.|......| * | * |-->| * |NIL|......................... ; |.............+----+......+---+---+...+---+---+......................... ; |...........................|...........|............................... ; |...........................v...........v............................... ; |.........................+---+.......+----+............................ ; |.........................|.9.|.......|.10.|............................ ; |.........................+---+.......+----+............................ ; |....................................................................... ; |....................................................................... ; |....................................................................... ; |....................................................................... ; |....................................................................... ; |....................................................................... ; |....................................................................... ; +----------------------------------------------------------------------- ;

(let ((p (frame-rect (make-instance 'picture :width 35 :height 20 :background ".") 0 0 80 30))) (draw-string p 0 0 "0") (draw-string p 10 0 "10") (draw-string p 20 0 "20") (draw-string p 30 0 "30") (draw-line p 0 0 10 10) (draw-line p 10 10 10 -5) (draw-line p 20 5 10 10) (draw-line p 30 15 10 -10) (draw-arrow p 23 15 5 0)) ;=> |.................................. ; |.................................. ; |.................................. ; |.................................. ; |......................----->.*.... ; |............................*.*... ; |...........................*...*.. ; |..........................*.....*. ; |.........................*.......* ; |.........**.............*......... ; |........*..**..........*.......... ; |.......*.....**.......*........... ; |......*........**....*............ ; |.....*...........**.*............. ; |....*..............*.............. ; |...*.............................. ; |..*............................... ; |.*................................ ; |*................................. ; *---------10--------20--------30--- ;

まとめ

 今回は、com.informatimago.common-lisp.pictureを紹介してみました。
Pascal Bourguignon氏は面白いものを沢山作っていますので、どんどん紹介していきたいと思っています。

comments powered by Disqus