You are looking at historical revision 42635 of this page. It may differ significantly from its current revision.

tags: egg

s9fes-char-graphics

The Scheme 9 from Empty Space character graphics routines.

(canvas-draw canvas integer-X integer-Y char) ==> unspecific
(canvas-draw-string canvas int-X int-Y string) ==> unspecific
(canvas-dump canvas) ==> vector
(canvas-plot canvas integer-X integer-Y char) ==> unspecific
(canvas-plot-line canvas X Y DX DY char) ==> unspecific
(make-canvas int-X int-Y int-W int-H) ==> canvas
(load-from-library "char-canvas.scm")
This is a set of routines for drawing characters and lines on
a scaled, character-based (a.k.a. "ASCII Art") canvas.
MAKE-CANVAS creates a char canvas with a physical size of
x=INT-X times y=INT-Y characters. The virtual size of the
canvas is INT-W (width) times INT-H (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-DRAW draws character CHAR at position INTEGER-X/INTEGER-Y.
It uses real coordinates. CANVAS-DRAWSTRING draws a string
instead of a single character. When the X or Y coordinate is
outside of the canvas, C will not be drawn. When STRING extends
beyond the limits of the canvas, it will be clipped.
CANVAS-PLOT draws the character CHAR at the virtual position
INTEGER-X/INTEGER-Y. CANVAS-PLOT-LINE 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-DUMP returns a vector of strings that contain the
characters written to the canvas. The vector indexes are the
Y-coordinates, the string offsets the X-coordinates.
Example
(let ((c (make-canvas 10 5 10 10)))
(canvas-plot-line c 0 9 9 0 #\#)
(canvas-plot-line c 0 0 9 9 #\*)
(canvas-dump c)) ==> #("## **"
" ## ** "
" ** "
" ** ## "
"** ##")
(char-plot list symbol integer1 integer2 boolean) ==> unspecific
CHAR-PLOT 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).
INTEGER1 (height) and INTEGER2 ; (width) specify the physical
dimenions of the char canvas. Its virtual dimensions will be
computed in such a way that all data points can be displayed.
When the BOOLEAN (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.
(Example)
(char-plot '(0 1 2 3 4 5 6 7 8 9) 'foo 7 35 #f) ==> unspecific
; output
----------- foo --> -----------------
; | --|
; | --X- |
; | --X---X- |
; | --X- |
; | --X---X- |
; | --X- |
; |X--X- |
; ----------- foo --> -----------------
(draw-tree object) ==> unspecific
Print a tree structure resembling a Scheme datum. Each cons
cell is represented by [o|o] with lines leading to their car
and cdr parts. Conses with a cdr value of () are represented
by [o|/].
(Example)
(draw-tree '((a) (b . c) (d e))) ==> unspecific
Output
[o|o]---[o|o]---[o|/]
| | |
[o|/] | [o|o]---[o|/]
| | | |
a | d e
|
[o|o]--- c
|
b