Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.PICTURE.PICTURE

This package exports functions to draw ASCII-ART pictures. ASCII-ART primitives. A picture is a matrix of characters. There are primitives to draw points, lines, rectangles, circles and ellipses, and strings. The coordinate system is the direct one: - x increases toward the right, - y increases toward the top. Bottom left is (0,0). License: AGPL3 Copyright Pascal J. Bourguignon 2002 - 2012 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Private

COPY-DEPLACEMENT (SEQUENCE)

Return a copy of SEQUENCE which is EQUAL to SEQUENCE but not EQ.

STRING-CACHE-SPLIT (STRING SEPARATOR)

PRIVATE

TEST-PICTURE-OBJECT

DO: Creates a test picture. RETURN: the picture string.

Undocumented

DEPLACEMENT-DX (STRUCTURE)

SETFDEPLACEMENT-DX (NEW-VALUE STRUCTURE)

DEPLACEMENT-DY (STRUCTURE)

SETFDEPLACEMENT-DY (NEW-VALUE STRUCTURE)

DEPLACEMENT-LINE-DX (STRUCTURE)

SETFDEPLACEMENT-LINE-DX (NEW-VALUE STRUCTURE)

DEPLACEMENT-LINE-DY (STRUCTURE)

SETFDEPLACEMENT-LINE-DY (NEW-VALUE STRUCTURE)

DEPLACEMENT-NAME (STRUCTURE)

SETFDEPLACEMENT-NAME (NEW-VALUE STRUCTURE)

MAKE-DEPLACEMENT (&KEY ((NAME DUM227) NIL) ((DX DUM228) NIL) ((DY DUM229) NIL) ((LINE-DX DUM230) NIL) ((LINE-DY DUM231) NIL))

TO-CHAR (STUFF)

GENERIC-FUNCTION

Public

DRAW-ARROW (PICT X Y W H &KEY TAIL)

DO: Draw a line between (x,y) and (x+w-1,y+h-1) and end it with with an arrow tip. If TAIL is specified, draw it at the start. RETURN: PICT

DRAW-LINE (PICT X Y W H &KEY FOREGROUND (FOREGROUND *))

DO: Draw a line between (x,y) and (x+w-1,y+h-1) with the foreground character. RETURN: PICT

DRAW-ON-PICTURE (SPRITE PICT X Y &OPTIONAL FRAME)

DO: Draws the frame FRAME of the SPRITE on the picture PICT, placing the spot of the sprite at coordinates (X,Y). Transparent pixels are not drawn.

DRAW-POINT (PICT X Y FOREGROUND)

PRE: inside = (AND (<= 0 X) (<= 0 Y) (< Y (HEIGHT PICT)) (< X (WIDTH PICT))) old-point = (POINT-AT PICT X Y) POST: inside ==> (EQ FOREGROUND (POINT-AT PICT X Y)) (NOT inside) ==> (EQ old-point (POINT-AT PICT X Y)) RETURN: PICT

DRAW-STRING (PICT X Y STRING &KEY DIRECTION (DIRECTION E))

PRE: (MEMBER DIRECTION '(:E :W :N :S :NE :NW :SE :SW :NNE :NNW :SSE :SSW :ENE :ESE :WNW :WSW :LEFT :RIGHT :UP :DOWN NIL) :TEST (FUNCTION 'EQ)) DO: Draws the STRING in the given DIRECTION (default :RIGHT = :E). STRING may be anything, it will be formated with ~A. If it contains +NEW-LINE+ characters then it's split and each line is written ''under'' the other, according to the DIRECTION. RETURN: PICT

ERASE-RECT (PICT X Y W H)

DO: Fills the specified rectangle with (BACKGROUND PICT). RETURN: PICT

FILL-RECT (PICT X Y W H &KEY FOREGROUND (FOREGROUND *))

DO: Fills the specified rectangle with FOREGROUND. RETURN: PICT

FRAME-RECT (PICT X Y W H &KEY TOP-LEFT TOP-RIGHT BOTTOM-LEFT BOTTOM-RIGHT TOP BOTTOM LEFT RIGHT (TOP-LEFT +) (TOP-RIGHT +) (BOTTOM-LEFT +) (BOTTOM-RIGHT +) (TOP -) (BOTTOM -) (LEFT |) (RIGHT |))

DO: Draws the frame of a rect parallel to the axis whose diagonal is [(x,y),(x+w-1,y+h-1)]. RETURN: PICT

FRAMES (SPRITE)

RETURN: The number of frames in the SPRITE.

HEIGHT (OBJECT)

RETURN: The height of the object.

POINT-AT (PICT X Y)

PRE: inside = (AND (<= 0 X) (< X (WIDTH PICT)) (<= 0 Y) (< Y (HEIGHT PICT))) RETURN: inside ==> The character at coordinate (X,Y). (NOT inside) ==> (BACKGROUND PICT)

SET-DATA (SPRITE DATA)

DATA may be either: - a single string with frames separated by FF and lines separated by LF, - a list of string frames with lines separated by LF, - a list of list of string lines. - a list of list of list of single character strings or symbols or characters or character codes. - a tri-dimentional array of characters. RETURN: SPRITE

SIZE-STRING (PICT STRING &KEY DIRECTION (DIRECTION E))

RETURN: left bottom width height of the rectangle in which the STRING will be drawn by DRAW-STRING, relative to the point where it'll drawn.

TO-STRING (PICT)

RETURN: A string containing the picture characters, (pict height) lines of (pict width) characters.

WIDTH (OBJECT)

RETURN: The width of the object.

SLOT-ACCESSOR

Public

BACKGROUND (PICTURE)

The The background character of the picture.

SETFBACKGROUND (NEW-VALUE OBJECT)

Set the The background character of the picture.

DATA (SPRITE)

The Sprite data.

SETFDATA (NEW-VALUE OBJECT)

Set the Sprite data.

NAME (SPRITE)

The Name of this sprite.

SETFNAME (NEW-VALUE OBJECT)

Set the Name of this sprite.

SPOT-X (SPRITE)

The X coordinate of the spot of the sprite.

SETFSPOT-X (NEW-VALUE OBJECT)

Set the X coordinate of the spot of the sprite.

SPOT-Y (SPRITE)

The Y coordinate of the spot of the sprite

SETFSPOT-Y (NEW-VALUE OBJECT)

Set the Y coordinate of the spot of the sprite

TRANSPARENT (SPRITE)

The The transparent character of the sprite.

SETFTRANSPARENT (NEW-VALUE OBJECT)

Set the The transparent character of the sprite.

VARIABLE

Private

*STRING-CACHE*

PRIVATE

+FORM-FEED+

A string containing a single +form-feed+ character.

+NEW-LINE+

A string containing a single +new-line+ character.

Undocumented

+DEPLACEMENTS+

CLASS

Public

PICTURE

A picture is a bi-dimentional (y,x) array of characters.

SPRITE

A sprite is a tri-dimentional (time,y,x) array of characters.