chickadee » s9fes-char-graphics

s9fes-char-graphics

The Scheme 9 from Empty Space character graphics routines.

Char Canvas

This is a set of routines for drawing characters and lines on a scaled, character-based (a.k.a. "ASCII Art") canvas.

Assumes one character per column. Do not use wide characters.

Usage

(import (s9fes char-canvas))

make-canvas

make-canvas COLUMNS ROWS #!optional WIDTH HEIGHTprocedure

Creates a character canvas with a physical size of COLUMNS X ROWS characters. The virtual size of the canvas is WIDTH X HEIGHT "pixels".

"Real coordinates" relate to the physical size of the canvas. "Virtual coordinates" are translated to real coordinates by scaling. Both types of coordinates are specified in X/Y notation.

The origin 0/0 is at the lower left corner of the canvas. The new canvas will be filled with blanks initially.

canvas?

canvas-columns

canvas-rows

canvas-width

canvas-height

canvas? OBJprocedure
canvas-columns CANVASprocedure
canvas-rows CANVASprocedure
canvas-width CANVASprocedure
canvas-height CANVASprocedure

canvas-physical

canvas-physical CANVAS X Yprocedure

Returns the physical coordinates for the supplied virtual X Y.

canvas-virtual

canvas-virtual CANVAS X Yprocedure

Returns virtual coordinates for the supplied physical X Y.

Note canvas-virtual <=> canvas-physical is not guaranteed. So this routine is of little use.

canvas-dump

canvas-dump CANVASprocedure

Returns a list of strings that contain the characters written to the canvas. The list elements are the rows, the strings the columns.

canvas-print

canvas-print CANVASprocedure

Prints the CANVAS, one row per line.

canvas->string

canvas-string CANVASprocedure

Prints the CANVAS to a string.

canvas-clear

canvas-clear CANVASprocedure

canvas-draw

canvas-draw CANVAS X Y #!optional CHARprocedure

Draws character CHAR at position X/Y. It uses real coordinates. When the X or Y coordinate is outside of the canvas, C will not be drawn.

current-plotter-char

current-plotter-char #!optional CHARprocedure

Default char for drawing.

canvas-draw-string

canvas-draw-string CANVAS X Y STRINGprocedure

Draws a STRING at position X/Y. It uses real coordinates. When STRING extends beyond the limits of the canvas, it will be clipped.

canvas-plot

canvas-plot CANVAS X Y #!optional CHARprocedure

Draws the character CHAR at the virtual position X/Y.

Draws a line from the virtual position X/Y to DX/DY using the character CHAR. All arguments must be integers. Lines originating or extending outside of the canvas will be clipped.

canvas-plot-string

canvas-plot-string CANVAS X Y STRINGprocedure

Draws a STRING at virtual position X/Y. When STRING extends beyond the limits of the canvas, it will be clipped.

canvas-plot-line

canvas-plot-line CANVAS X Y DX DY #!optional CHARprocedure

canvas-plot-lines

canvas-plot-lines CANVAS LINES #!optional CONFIGprocedure
LINES
(list-of integer) ; list of line segment x y.
CONFIG
(or false char (list-of (or false char))) ; drawing pattern, n elements, #f for skip or a char to draw; default is (current-plotter-char).

Char Canvas Shape Oval

Usage

(import (s9fes char-canvas shape oval))

Shared Arguments & Types:

octant-plotter
(canvas fixnum fixnum fixnum fixnum -> boolean) ; returns continue?
octant-visitor
(canvas fixnum fixnum -> boolean) ; returns continue?

generate-circle-octant

generate-circle-octant CANVAS RADIUS VISITORprocedure

Generates the coordinates for the first octant of a circle of RADIUS. It uses real coordinates. The VISITOR is called for each generated point. Should the VISITOR return #f the generator halts early.

RADIUS
fixnum ; radius
VISITOR
octant-visitor

circle-octant-point

circle-octant-point OCTANT X0 Y0 X Yprocedure

Returns coordinates for octant 0 point X Y in the specified OCTANT, centered at X0 Y0.

OCTANT
fixnum ; octant, 0..7, coordinates to calculate
X0 Y0
fixnum fixnum ; center
X Y
fixnum fixnum ; offset

circle-octant-visitor

circle-octant-visitor X0 Y0 PLOTTERprocedure
X0 Y0
fixnum fixnum ; center
PLOTTER
octant-plotter

circle-octant-plotter

circle-octant-plotter #!optional CONFIGprocedure

Returns a canvas-drawing procedure for the specified octant drawing pattern CONFIG.

CONFIG
(or false char (list-of (or false char))) ; octant drawing pattern, 8 elements, octant 0 to octant 8, #f for skip or a char to draw; default is (current-plotter-char).

generate-virtual-circle-octant

generate-virtual-circle-octant CANVAS RADIUS VISITOR #!optional AVERAGE?procedure

Same as generate-circle-octant but w/ virtual coordinates (see above).

RADIUS
integer ; radius
VISITOR
octant-visitor

virtual-circle-octant-visitor

virtual-circle-octant-visitor X0 Y0 PLOTTERprocedure

Same as circle-octant-visitor but w/ virtual coordinates (see above).

X0 Y0
integer integer ; center
PLOTTER
octant-plotter

Char Canvas Shape Cross

Shared Arguments & Types:

shape-plotter
(canvas #!optional fixnum fixnum -> void)

Usage

(import (s9fes char-canvas shape cross))

cross-+-plotter

cross-+-plotter WD #!optional HT CONFIGprocedure
WD
integer
HT
integer ; default WD
CONFIG
(or false char (list-of (or false char))) ; drawing pattern, 2 elements, #f for skip or a char to draw; default is (current-plotter-char).

cross-x-plotter

cross-x-plotter WD #!optional HT CONFIGprocedure
WD
integer
HT
integer ; default WD
CONFIG
(or false char (list-of (or false char))) ; drawing pattern, 2 elements, #f for skip or a char to draw; default is (current-plotter-char).
(let ((cv (make-canvas 10 5 10 10)))
  (cross-x-plotter cv 10)
  (canvas-print cv) )
=>
##      **
  ##  **
    **
  **  ##
**      ##

Char Plot

Usage

(import (s9fes char-plot))

char-plot

char-plot LIST SYMBOL HEIGHT WDITH #!optional COMPR?procedure

Creates a character canvas (see make-canvas), marks the data points in LIST with #\X and draws a line through the points with #\-. SYMBOL will be used to label the X axis (on which the data points will be distributed).

HEIGHT and WDITH specify the physical dimensions of the char canvas. Its virtual dimensions will be computed in such a way that all data points can be displayed.

When the COMPR? (compression) argument is set to #t, then the X axis will start at the magnitude of the least data point instead of zero, so that the entire width of the canvas is available for distributing the supplied data points. The default is #t.

(char-plot '(0 1 2 3 4 5 6 7 8 9) 'foo 7 35 #f)</procedure>
=>
----------- foo --> -----------------
|                              -X   |
|                          --X-     |
|                   --X--X-         |
|                -X-                |
|         -X---X-                   |
|     --X-                          |
|X--X-                              |
----------- foo --> -----------------

Draw Tree

Usage

(import (s9fes draw-tree))

draw-tree

draw-tree ROOT #!optional MAX-WIDTHprocedure

Draws a character graphic representation of the tree LIST on (current-output-port).

ROOT
pair ; tree root node.
MAX-WIDTH
fixnum ; maximum printed node width, in characters. default is 7.
(draw-tree '((a) (b . c) (d e)))
=>
[o|o]---[o|o]---[o|/]
  |       |       |
[o|/]     |     [o|o]---[o|/]
  |       |       |       |
  a       |       d       e
          |
        [o|o]---  c
          |
          b

Requirements

utf8 format

test test-utils

Author

Kon Lovett

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/s9fes-char-graphics

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Version history

1.4.2
.
1.4.1
.
1.4.0
Add current-plotter-char, shape oval & shape cross.
1.3.2
Fix octant stream.
1.3.1
Fix canvas? type.
1.3.0
Add generate-circle-octant & friends.
1.2.0
Add canvas-plot-string.
1.1.0
Add canvas-print, canvas-physical, canvas-virtual.
1.0.1
.
1.0.0
Initial release.

License

Public Domain

Contents »