s9fes-char-graphics

The Scheme 9 from Empty Space character graphics routines.

  1. s9fes-char-graphics
    1. Char Canvas
      1. Usage
      2. make-canvas
      3. new-canvas
      4. canvas?
      5. canvas-columns
      6. canvas-rows
      7. canvas-width
      8. canvas-height
      9. canvas-physical
      10. canvas-virtual
      11. canvas-dump
      12. canvas-print
      13. ASCII-FRAME-CHARS
      14. THIN-FRAME-CHARS
      15. THICK-FRAME-CHARS
      16. string->canvas
      17. with-output-to-canvas
      18. canvas->vector
      19. canvas->list
      20. canvas->string
      21. current-plotter-char
      22. current-plotter-bkgd-char
      23. canvas-clear
      24. canvas-flood
      25. canvas-scroll
      26. canvas-copy
      27. canvas-paste
      28. canvas-clear-chars
      29. canvas-flood-chars
      30. canvas-scroll-chars
      31. canvas-copy-chars
      32. canvas-paste-chars
      33. canvas-draw
      34. canvas-draw-string
      35. canvas-draw-line
      36. canvas-draw-lines
      37. canvas-plot
      38. canvas-plot-string
      39. canvas-plot-line
      40. canvas-plot-lines
      41. make-char-canvas
      42. char-canvas?
      43. char-canvas-columns
      44. char-canvas-rows
      45. char-canvas-cmap
    2. Char Canvas Rectangle
      1. Usage
      2. rect
      3. rect?
      4. rect-x
      5. rect-y
      6. rect-wd
      7. rect-ht
      8. rect-x-end
      9. rect-y-end
      10. rect-x-min
      11. rect-y-min
      12. rect-x-max
      13. rect-y-max
      14. rect-copy
      15. rect-null
      16. rect-null?
      17. rect-bias
      18. rect-scale
      19. rect-bias!
      20. rect-scale!
      21. rect->list
      22. list->rect
      23. canvas->rect
      24. char-rect?
      25. char-canvas->rect
      26. rect-area
      27. rect-smaller?
      28. rect-larger?
      29. rect-relates
      30. rect-union
      31. rect-intersection
      32. rect-overlaps?
    3. Char Canvas Shape Shared Arguments & Types:
    4. Char Canvas Shape Box
      1. Usage
      2. shape-box
      3. virtual-shape-box
      4. draw-box
      5. plot-box
    5. Char Canvas Shape Oval
      1. Usage
      2. shape-oval
      3. virtual-shape-oval
      4. draw-circle
      5. plot-circle
      6. circle-polygon-lines
      7. circle-octant-plotter
      8. generate-circle-octant
      9. circle-octant-point
      10. circle-octant-visitor
      11. generate-virtual-circle-octant
      12. virtual-circle-octant-visitor
    6. Char Canvas Shape Cross
      1. Usage
      2. shape-cross-+
      3. shape-cross-x
      4. virtual-shape-cross-+
      5. virtual-shape-cross-x
    7. Char Canvas Shape Icon
      1. Usage
      2. read-icon
      3. write-icon
      4. load-icon
      5. store-icon
      6. string->icon
      7. shape-icon
      8. virtual-shape-icon
      9. draw-icon
      10. plot-icon
    8. Char Plot
      1. Usage
      2. char-plot
    9. Draw Tree
      1. Usage
      2. draw-tree
  2. Bugs & Limitations
  3. Notes
  4. Requirements
  5. Author
  6. Repository
  7. Version history
  8. License

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 COLUMNS ROWS [WIDTH [HEIGHT]]) -> canvas

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.

new-canvas

[procedure] (new-canvas CANVAS WIDTH HEIGHT) -> canvas

Creates a canvas, sharing the char-canvas of CANVAS, but with a virtual size of WIDTH X HEIGHT "pixels".

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 X Y) -> X Y

Returns the physical coordinates for the supplied virtual X Y.

canvas-virtual

[procedure] (canvas-virtual CANVAS X Y) -> X Y

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

[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 [FRAME])

Prints the CANVAS, one row per line, with an optional frame.

FRAME
(vector char char char char char char char char) ; top/bottom horizontal, top/bottom vertical, corner top left/right & bottom left/right chars; default #(#\- #\- #\| #\| #\+ #\+ #\+ #\+).
FRAME
#t ; use ASCII-FRAME-CHARS.

ASCII-FRAME-CHARS

THIN-FRAME-CHARS

THICK-FRAME-CHARS

ASCII-FRAME-CHARS
#(#\- #\- #\| #\| #\+ #\+ #\+ #\+)
THIN-FRAME-CHARS
#(#\─ #\─ #\│ #\│ #\┌ #\┐ #\└ #\┘)
THICK-FRAME-CHARS
#(#\━ #\━ #\┃ #\┃ #\┏ #\┓ #\┗ #\┛)

string->canvas

[procedure] (string->canvas STR) -> canvas

Returns a canvas from the line-feed-encoded STR.

STR
string : string w/ embedded #\newline for each row.

with-output-to-canvas

[procedure] (with-output-to-canvas THUNK) -> canvas

Returns a canvas from the read output of THUNK.

THUNK
procedure : 0 arguments & writes to current-output-port.

canvas->vector

[procedure] (canvas->vector CANVAS) -> (vector-of string)

Converts the CANVAS to a vector, row h-1 to row 0.

canvas->list

[procedure] (canvas->list CANVAS) -> (list-of string)

Converts the CANVAS to a list, row h-1 to row 0.

canvas->string

[procedure] (canvas->string CANVAS) -> string

Converts the CANVAS to a string, row h-1 to row 0, delimited by #\newline.

current-plotter-char

[procedure] (current-plotter-char [CHAR]) -> char

current-plotter-bkgd-char

[procedure] (current-plotter-bkgd-char [CHAR]) -> char

Default char for clearing.

canvas-clear

[procedure] (canvas-clear CANVAS [RGN])

Uses the (current-plotter-bkgd-char) to clear the CANVAS RGN.

RGN
rect : canvas sub-area, default is whole canvas.

canvas-flood

[procedure] (canvas-flood CANVAS FILL [RGN]))

Cover the CANVAS RGN with the FILL char.

FILL
char : fill char, default (current-plotter-char).
RGN
rect : canvas sub-area, default is whole canvas.

canvas-scroll

[procedure] (canvas-scroll CANVAS [DX [DY [RGN]]])

Scroll the CANVAS RGN.

DX
integer : negative (left) or positive (right)
DY
integer : negative (up) or positive (down)
RGN
rect : canvas sub-area, default is whole canvas.

canvas-copy

[procedure] (canvas-copy CANVAS [RGN]) -> canvas

Copy the CANVAS RGN.

RGN
rect : canvas sub-area, default is whole canvas.

canvas-paste

[procedure] (canvas-paste CANVAS SOURCE-CANVAS [X [Y]])

Paste the SOURCE-CANVAS into CANVAS at lower-left X Y.

X
integer : x, default is 0
Y
integer : y, default is 0

Note that the operation is performed using overwrite. Currently no canvas-composite.

canvas-clear-chars

[procedure] (canvas-clear-chars CANVAS [RGN])

Uses the (current-plotter-bkgd-char) to clear the CANVAS RGN.

RGN
char-rect : canvas sub-area, default is whole canvas.

canvas-flood-chars

[procedure] (canvas-flood-chars CANVAS FILL [RGN]))

Fill the CANVAS RGN with the FILL.

FILL
char : fill char, default (current-plotter-char).
RGN
char-rect : canvas sub-area, default is whole canvas.

canvas-scroll-chars

[procedure] (canvas-scroll-chars CANVAS [DX [DY [RGN]]])

Scroll the CANVAS RGN.

DX
fixnum : columns negative (left) or positive (right)
DY
fixnum : rows negative (up) or positive (down)
RGN
char-rect : canvas sub-area, default is whole canvas.

canvas-copy-chars

[procedure] (canvas-copy-chars CANVAS [RGN]) -> canvas

Copy the CANVAS RGN.

RGN
char-rect : canvas sub-area, default is whole canvas.

canvas-paste-chars

[procedure] (canvas-paste-chars CANVAS SOURCE-CANVAS [X [Y]])

Paste the SOURCE-CANVAS into CANVAS at lower-left X Y.

X
fixnum : x, default is 0
Y
fixnum : y, default is 0

The returned canvas is the TARGET-CANVAS.

canvas-draw

[procedure] (canvas-draw CANVAS X Y [CHAR])

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

canvas-draw-string

[procedure] (canvas-draw-string CANVAS X Y STRING)

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-draw-line

[procedure] (canvas-draw-line CANVAS X0 Y0 X1 Y1 [CHAR])

Draws a line from X0 Y0 to X1 Y1, using CHAR.

X0 Y0 X1 Y1
fixnum ; .
CHAR
char ; drawing character, default (current-plotter-char).

canvas-draw-lines

[procedure] (canvas-draw-lines CANVAS LINES [CONFIG])
LINES
(list-of fixnum) ; 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).

canvas-plot

[procedure] (canvas-plot CANVAS X Y [CHAR])

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

[procedure] (canvas-plot-string CANVAS X Y STRING)

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

canvas-plot-line

[procedure] (canvas-plot-line CANVAS X0 Y0 X1 Y1 [CHAR])

Plots a line from X0 Y0 to X1 Y1, using CHAR.

X0 Y0 X1 Y1
fixnum ; .
CHAR
char ; drawing character, default (current-plotter-char).

canvas-plot-lines

[procedure] (canvas-plot-lines CANVAS LINES [CONFIG])
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).

make-char-canvas

char-canvas?

char-canvas-columns

char-canvas-rows

char-canvas-cmap

[procedure] (make-char-canvas COLS ROWS CHAR-OR-CMAP) -> char-canvas
[procedure] (char-canvas? OBJ) -> boolean
[procedure] (char-canvas-columns CHAR-CANVAS) -> fixnum
[procedure] (char-canvas-rows CHAR-CANVAS) -> fixnum
[procedure] (char-canvas-cmap CHAR-CANVAS) -> cmap

Char Canvas Rectangle

Usage

(import (s9fes char-canvas rect))

Shared Arguments & Types:

X
integer : x (column) coordinate.
Y
integer : y (row) coordinate. 0 in the lower-left!
WD
integer : width (columns) size.
{HT}}
integer : height (rows) size.

rect

rect?

rect-x

rect-y

rect-wd

rect-ht

[procedure] (rect X Y WD HT) -> rect
[procedure] (rect? OBJ) -> boolean
[procedure] (rect-x RECT) -> integer
[procedure] (rect-y RECT) -> integer
[procedure] (rect-wd RECT) -> integer
[procedure] (rect-ht RECT) -> integer

rect-x-end

[procedure] (rect-x-end RECT) -> integer

One beyond the canvas horizontal.

rect-y-end

[procedure] (rect-y-end RECT) -> integer

One beyond the canvas vertical.

rect-x-min

[procedure] (rect-x-min RECT) -> integer

Same as rect-x. For symmetry.

rect-y-min

[procedure] (rect-y-min RECT) -> integer

Same as rect-y. For symmetry.

rect-x-max

[procedure] (rect-x-max RECT) -> integer

Right-most horizontal coordinate.

rect-y-max

[procedure] (rect-y-max RECT) -> integer

Top-most vertical coordinate.

rect-copy

[procedure] (rect-copy RECT) -> rect

rect-null

[procedure] (rect-null) -> rect

Returns an empty rectangle.

rect-null?

[procedure] (rect-null? OBJ) -> boolean

Is the rectangle empty? (0 rect-wd or rect-ht)

rect-bias

[procedure] (rect-bias RECT DX DY) -> rect

Shift the RECT by DX in the horizontal and DY in the vertical. Does not change the size.

DX
integer : negative (left) or positive (right)
DY
integer : negative (up) or positive (down)

rect-scale

[procedure] (rect-scale RECT SX SY) -> rect

Grow the RECT by SX in the horizontal and SY in the vertical. Does not change the position.

SX
integer : negative (thin) or positive (widen)
SY
integer : negative (shorten) or positive (lengthen)

rect-bias!

[procedure] (rect-bias! RECT DX DY) -> rect

Bias the RECT in-place.

rect-scale!

[procedure] (rect-scale! RECT SX SY) -> rect

Scale the RECT in-place.

rect->list

[procedure] (rect->list RECT) -> (list integer integer integer integer)

list->rect

[procedure] (list->rect LS) -> rect
LS
(list integer integer integer integer)

canvas->rect

[procedure] (canvas->rect CANVAS) -> rect

Returns a rect from the CANVAS dimensions.

char-rect?

[procedure] (char-rect? OBJ) -> boolean

Note that a char-rect is-a rect, just restricted to fixnum.

char-canvas->rect

[procedure] (char-canvas->rect CHAR-CANVAS) -> rect

rect-area

[procedure] (rect-area RECT) -> integer

Returns the size of the rectangle.

rect-smaller?

[procedure] (rect-smaller? RECT1 RECT2) -> boolean

rect-larger?

[procedure] (rect-larger? RECT1 RECT2) -> boolean

rect-relates

[procedure] (rect-relates RECT1 RECT2) -> (list-of symbol)

Returns a, possibly empty, list of symbols describing the spatial relationship of RECT1 & RECT2.

left right
x
above below
y
thinner wider
width
shorter taller
height

rect-union

[procedure] (rect-union RECT1 RECT2) -> rect

Returns the encompassing rectangle of RECT1 & RECT2.

rect-intersection

[procedure] (rect-intersection RECT1 RECT2) -> rect

Returns the overlapping rectangle of RECT1 & RECT2, which may be empty.

rect-overlaps?

[procedure] (rect-overlaps? RECT1 RECT2) -> boolean

Does RECT1 intersect RECT2?

Char Canvas Shape Shared Arguments & Types:

Shapes are functions, either taking no arguments and returning the constructing parameters, or taking at least a canvas, rendering the shape, then returning the canvas.

shape-plotter
([CANVAS [XM [YM]]] -> (or CANVAS PARAMS))
XM YM
fixnum fixnum ; center
PARAMS
list ; defining parameters (from the constructor)
virtual-shape-plotter
([CANVAS [XM [YM]]] -> (or CANVAS PARAMS))
XM YM
integer integer ; center
PARAMS
list ; defining parameters (from the constructor)

Char Canvas Shape Box

Usage

(import (s9fes char-canvas shape box))

Shared Arguments & Types

FRAME
(vector char char char char char char char char) ; top/bottom horizontal, top/bottom vertical, corner top left/right & bottom left/right chars; default #(#\- #\- #\| #\| #\+ #\+ #\+ #\+).
FRAME
#t ; use ASCII-FRAME-CHARS.

shape-box

[procedure] (shape-box WD HT [FRAME]) -> shape-plotter
WD
fixnum ; width
HT
fixnum ; height

virtual-shape-box

[procedure] (virtual-shape-box WD HT [FRAME]) -> shape-plotter
WD
integer ; width
HT
integer ; height

draw-box

[procedure] (draw-box CANVAS RGN [FRAME])
RGN
char-rect : box.

plot-box

[procedure] (plot-box CANVAS RGN [FRAME])
RGN
rect : box.

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?

shape-oval

[procedure] (shape-oval R [CONFIG]) -> shape-plotter
R
fixnum ; radius
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).

virtual-shape-oval

[procedure] (virtual-shape-oval R [CONFIG]) -> virtual-shape-plotter
R
integer ; radius
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).
(import (s9fes char-canvas) (s9fes char-canvas shape oval))

(define canvas-plot-oval@40 (virtual-shape-oval 40))

(let ((cv (make-canvas 10 10 100 100)))
  (canvas-plot-oval@40 cv 50 50)
  (canvas-print cv #t) )
;=>
+----------+
|    ***   |
|   *   *  |
|  *     * |
| *       *|
| *       *|
| *       *|
|  *     * |
|   *   *  |
|    ***   |
|          |
+----------+

draw-circle

[procedure] (draw-circle CANVAS X0 Y0 R [CONFIG])
X0 Y0
fixnum fixnum ; center
R
fixnum ; radius
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).

plot-circle

[procedure] (plot-circle CANVAS X0 Y0 R [CONFIG])
X0 Y0
integer integer ; center
R
integer ; radius
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).
(import (s9fes char-canvas) (s9fes char-canvas shape oval))

(let ((cv (make-canvas 10 10 100 100)))
  (plot-circle cv 50 50 40)
  (canvas-print cv #t) )
;=>
+----------+
|    ***   |
|   *   *  |
|  *     * |
| *       *|
| *       *|
| *       *|
|  *     * |
|   *   *  |
|    ***   |
|          |
+----------+

circle-polygon-lines

[procedure] (circle-polygon-lines X0 Y0 RADIUS [N [ANGLE]) -> (list-of integer)

Returns a list of virtual coordinates suitable for use w/ canvas-plot-lines. A closed, convex, polygon is described.

X0 Y0
integer integer ; circle center in virtual coordinates
RADIUS
integer ; circle radius in virtual coordinates
N
fixnum ; number of points ; default 360
ANGLE
fixnum ; starting degree ; default 0
(import (s9fes char-canvas) (s9fes char-canvas shape oval))

(let ((cv (make-canvas 10 10 100 100)))
  (canvas-plot-lines cv (circle-polygon-lines 50 50 50))
  (canvas-print cv) )
;=>
  ******
 *      *
*        *
*        *
*        *
*        *
*        *
*        *
 *      *
  ******
(let ((cv (make-canvas 10 10 100 100)))
  (canvas-plot-lines cv (circle-polygon-lines 50 50 50 4))
  (canvas-print cv #t) )
;=>
+----------+
|    * *   |
|   *   *  |
|  *     * |
| *       *|
|*         |
| *       *|
|  *    ** |
|  *   *   |
|   * *    |
|    *     |
+----------+

circle-octant-plotter

[procedure] (circle-octant-plotter [CONFIG]) -> octant-plotter

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-circle-octant

[procedure] (generate-circle-octant CANVAS RADIUS VISITOR)

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

[procedure] (circle-octant-point OCTANT X0 Y0 X Y) -> fixnum fixnum

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

[procedure] (circle-octant-visitor X0 Y0 PLOTTER) -> octant-visitor
X0 Y0
fixnum fixnum ; center
PLOTTER
octant-plotter

generate-virtual-circle-octant

[procedure] (generate-virtual-circle-octant CANVAS RADIUS VISITOR [AVERAGE?])

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

RADIUS
integer ; radius
VISITOR
octant-visitor
(import (s9fes char-canvas) (s9fes char-canvas shape oval))

(define (canvas-draw-circle cv c r w #!optional (pl (circle-octant-plotter)))
  (generate-circle-octant cv w (circle-octant-visitor c r pl)) )

(let* ((rw 5) (cl 5)
       (cr (quotient rw 2)) (cc (quotient cl 2)) (rd cc)
       (cv (make-canvas cl rw)) )
  (canvas-draw-circle cv cc cr rd)
  (canvas-print cv) )
;=>
 ***
*   *
*   *
*   *
 ***

virtual-circle-octant-visitor

[procedure] (virtual-circle-octant-visitor X0 Y0 PLOTTER) -> octant-visitor

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

X0 Y0
integer integer ; center
PLOTTER
octant-plotter
(import (s9fes char-canvas) (s9fes char-canvas shape oval))

(define (canvas-plot-circle cv x y r #!optional (pl (circle-octant-plotter)))
  (generate-virtual-circle-octant cv r (virtual-circle-octant-visitor x y pl)) )

(let* ((rw 5) (cl 5) (wd 100) (ht 250)
       (x0 (round (/ wd 2))) (y0 (round (/ ht 2))) (rd y0)
       (cv (make-canvas rw cl wd ht)) )
  (canvas-plot-circle cv x0 y0 rd)
  (canvas-print cv) )
;=>
 ***
*   *
*   *
*   *
 ***

Char Canvas Shape Cross

Usage

(import (s9fes char-canvas shape cross))

shape-cross-+

[procedure] (shape-cross-+ WD [HT [CONFIG]]) -> shape-plotter
WD
fixnum
HT
fixnum ; 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).

shape-cross-x

[procedure] (shape-cross-x WD [HT [CONFIG]]) -> shape-plotter
WD
fixnum
HT
fixnum ; 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).

virtual-shape-cross-+

[procedure] (virtual-shape-cross-+ WD [HT [CONFIG]]) -> virtual-shape-plotter
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).

virtual-shape-cross-x

[procedure] (virtual-shape-cross-x WD [HT [CONFIG]]) -> virtual-shape-plotter
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).
(import (s9fes char-canvas) (s9fes char-canvas shape cross))

(define canvas-plot-x@100x100 (virtual-shape-cross-x 100))

(let ((cv (make-canvas 10 5 100 100)))
  (canvas-plot-x@100x100 cv)
  (canvas-print cv) )
;=>
**      **
  **  **
    **
  **  **
**      **

Char Canvas Shape Icon

Usage

(import (s9fes char-canvas shape icon))

read-icon

write-icon

load-icon

store-icon

string->icon

shape-icon

virtual-shape-icon

draw-icon

plot-icon

[procedure] (read-icon [IN]) -> icon
[procedure] (write-icon ICON [OUT])
[procedure] (load-icon PATH) -> icon
[procedure] (store-icon ICON PATH)
[procedure] (string->icon STR) -> icon
[procedure] (shape-icon ICON) -> shape-plotter
[procedure] (virtual-shape-icon ICON) -> virtual-shape-plotter
[procedure] (draw-icon CANVAS ICON [X [Y]])
[procedure] (plot-icon CANVAS ICON [X [Y]])

Char Plot

Usage

(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

Bugs & Limitations

Notes

Requirements

utf8 srfi-1 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.13.0
Add (s9fes char-canvas shape icon) module.
1.12.1
Fix box shape plotter position.
1.12.0
Rename to (s9fes char-canvas rect). Add rect-null, rect-null?, rect-area, rect-overlaps?, rect-union, rect-intersection, rect-smaller?, rect-larger?, rect-relates.
1.11.0
Add string->canvas & with-output-to-canvas. canvas-print takes optional frame (remove canvas-print/frame). Add (s9fes char-canvas shape box).
1.10.0
Add canvas-print/frame, new-canvas, canvas-flood, canvas-scroll, canvas-copy, canvas-paste, canvas-flood-chars, canvas-scroll-chars, canvas-copy-chars, canvas-paste-chars, canvas->list, canvas->vector. Add (s9fes rect) module. Add shape introspection.
1.9.1
shape-oval & virtual-shape-oval proper shapes (optional center).
1.9.0
Add shape-oval & virtual-shape-oval.
1.8.1
Fix (s9fes char-canvas shape cross) naming, again.
1.8.0
Fix (s9fes char-canvas shape cross) naming.
1.7.1
Smaller.
1.7.0
Fix shape-point-plotter, takes center, not top-left. Add cross-x-drawer & cross-+-drawer.
1.6.0
Add canvas-draw-line & canvas-draw-lines.
1.5.0
.
1.4.4
Prevent division-by-zero in canvas-plot-line.
1.4.3
.
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