You are looking at historical revision 42648 of this page. It may differ significantly from its current revision.
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
[procedure] (make-canvas FIX-X FIX-Y [INTEGER-X [INTEGER-Y]]) => canvasCreates a character canvas with a physical size of FIX-X X FIX-Y characters. The virtual size of the canvas is INTEGER-X (width) X INTEGER-Y (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
[procedure] (canvas? OBJ) => boolean[procedure] (canvas-columns CANVAS) => fixnum
[procedure] (canvas-rows CANVAS) => fixnum
[procedure] (canvas-width CANVAS) => integer
[procedure] (canvas-height CANVAS) => integer
canvas-physical
[procedure] (canvas-physical CANVAS INT-X INT-Y) -> FIX-X FIX-YReturns the physical coordinates for the supplied virtual INT-X INT-Y.
canvas-virtual
[procedure] (canvas-virtual CANVAS FIX-X FIX-Y) -> INT-X INT-YReturns virtual coordinates for the supplied physical FIX-X FIX-Y.
Note canvas-virtual <=> canvas-physical is not guaranteed. So this routine is of little use.
canvas-draw
[procedure] (canvas-draw CANVAS FIX-X FIX-Y CHAR)Draws character CHAR at position FIX-X/FIX-Y. It uses real coordinates. When the X or Y coordinate is outside of the canvas, C will not be drawn.
canvas-draw-string
[procedure] (canvas-draw-string CANVAS FIX-X FIX-Y STRING)Draws a STRING at position FIX-X/FIX-Y. It uses real coordinates. When STRING extends beyond the limits of the canvas, it will be clipped.
canvas-plot
[procedure] (canvas-plot CANVAS INT-X INT-Y CHAR)Draws the character CHAR at the virtual position INT-X/INT-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
[procedure] (canvas-plot-string CANVAS INT-X INT-Y STRING)Draws a STRING at virtual position INT-X/INT-Y. When STRING extends beyond the limits of the canvas, it will be clipped.
canvas-dump
[procedure] (canvas-dump CANVAS) => (list-of string)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
[procedure] (canvas-print CANVAS)Prints the CANVAS, one row per line.
canvas-clear
[procedure] (canvas-clear CANVAS)canvas-plot-line
[procedure] (canvas-plot-line CANVAS X Y DX DY CHAR)canvas-plot-lines
[procedure] (canvas-plot-lines CANVAS LINES CHAR)(let ((c (make-canvas 10 5 10 10))) (canvas-plot-line c 0 9 9 0 #\#) (canvas-plot-line c 0 0 9 9 #\*) (pp (canvas-dump c)) ) => ("## **" " ## ** " " ** " " ** ## " "** ##") === Char Plot ==== Usage <enscript language=scheme> (import (s9fes char-plot))
char-plot
[procedure] (char-plot LIST SYMBOL HEIGHT WDITH [COMPR?])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
[procedure] (draw-tree ROOT [MAX-WIDTH])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
Author
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.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