s9fes-char-graphics

A Shape extemsopm tp the Scheme 9 from Empty Space'' character graphics library; the s9fes-char-graphics-shape egg.

  1. s9fes-char-graphics
    1. Char Canvas Shape Shared Arguments & Types:
    2. Char Canvas Shape Shape
      1. Usage
      2. pad-dims
      3. ONE-DIMS
      4. pad-chars
      5. registered-shapes
      6. registered-shape-methods
      7. shape-new
      8. shape-class
      9. shape-coords
      10. create-shape
      11. shape-creator
      12. shape-size
      13. shape-center
      14. shape-center-rect
      15. shape-cardinality
      16. shape-elements
      17. shape-contains?
      18. shape-layout
      19. shape-justified?
      20. shape-read
      21. shape-write
      22. shape-load
      23. shape-store
      24. shapes-read
      25. shapes-write
      26. shapes-load
      27. shapes-store
      28. shape-show
      29. shape-fold
      30. shape-reify
      31. shape-reflect
    3. Char Canvas Shape Box
      1. Usage
      2. real-shape-box
      3. shape-box
    4. Char Canvas Shape Circle
      1. Usage
      2. real-shape-circle
      3. shape-circle
      4. circle-polygon-lines
      5. circle-octant-plotter
      6. generate-circle-octant
      7. circle-octant-point
      8. circle-octant-visitor
      9. generate-virtual-circle-octant
      10. virtual-circle-octant-visitor
    5. Char Canvas Shape Cross
      1. Usage
    6. Char Canvas Shape Cross Shared Arguments & Types:
      1. real-shape-cross--
      2. real-shape-cross-vbar
      3. real-shape-cross-+
      4. real-shape-cross-obar
      5. real-shape-cross-abar
      6. real-shape-cross-x
      7. shape-cross--
      8. shape-cross-vbar
      9. shape-cross-+
      10. shape-cross-obar
      11. shape-cross-abar
      12. shape-cross-x
    7. Char Canvas Shape image
      1. Usage
      2. read-image
      3. write-image
      4. load-image
      5. store-image
      6. canvas->image
      7. string->image
      8. real-shape-image
      9. shape-image
    8. Char Canvas Shape Fpad
      1. Usage
      2. real-shape-fpad
      3. shape-fpad
    9. Char Canvas Shape jpad
      1. Usage
      2. real-shape-jpad
      3. shape-jpad
    10. Char Canvas Shape hgroup
      1. Usage
      2. real-shape-hgroup
      3. shape-hgroup
    11. Char Canvas Shape vgroup
      1. Usage
      2. real-shape-vgroup
      3. shape-vgroup
  2. Bugs & Limitations
  3. Notes
  4. Requirements
  5. Author
  6. Repository
  7. Version history
  8. License

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
(#!optional ccanvas integer integer-> (or canvas shape-info))
real-shape-plotter
(#!optional canvas fixnum fixnum -> (or canvas shape-info))
real-shape-plotter
shape-potter ; restricted to real coordinates.

: x y ; integer integer ; virtual coordinates : x y ; fixnum fixnum ; real coordinates

pad-dims
(vector integer integer integer integer) ; top bottom left right
pad-chars
(vector (or false char) (or false char) (or false char) (or false char)) ; top bottom left right
frame-chars
(vector char char char char char char char char) ; top/bottom horizontal, top/bottom vertical, corner top left/right & bottom left/right chars; default #(#\- #\- #\| #\| #\+ #\+ #\+ #\+).
real-shape
real-shape-plotter
shape
shape-plotter
shape-info
(list symbol symbol ...) ; defining parameters
class
symbol ; class name
method
symbol ; method name

Char Canvas Shape Shape

Usage

(import (s9fes char-canvas shape shape))

pad-dims

[procedure] (pad-dims TOP BOTTOM LEFT RIGHT) -> pad-dims

ONE-DIMS

[constant] ONE-DIMS

All ones, 1 1 1 1.

pad-chars

[procedure] (pad-chars TOP BOTTOM LEFT RIGHT) -> pad-chars

registered-shapes

[procedure] (registered-shapes) -> (list-of symbol)

Returns a list of shape CLASS.

registered-shape-methods

[procedure] (registered-shape-methods ID) -> (list-of symbol)
CLASS
symbol : shape name

shape-new

[procedure] (shape-new CLASS CTOR [REAL-CTOR] METHOD FUNC ...) -> void

Create a new shape CLASS. Required METHOD are size & show. Optional METHOD reflect & reify must be added as a pair. Optional METHOD layout & justified? must be added as a pair.

The shape CLASS is not persisted, nor can it be.

          (#!rest -> shape-plotter)
 ;optional
          (#!rest -> real-shape-plotter)

 ;required-method
       'size (self self-info) -> integer integer
    'reflect (self self-info) -> (reified-)shape-info
      'reify ((reified-)self-info) -> shape-plotter
       'show (canvas x y) -> void

 ;optional-method
       'real (#!rest -> real-shape-plotter)
     'layout (self self-info rect) -> hape-plotter
 'justified? (self self-info) -> bookean

 ;rest-method
     'METHOD (self self-info . args) -> . *

shape-class

shape-coords

[procedure] (shape-class SHAPE) -> symbol
[procedure] (shape-coords SHAPE) -> symbol

create-shape

[syntax] (create-shape CLASS ARGS ...) -> shape
[syntax] (create-shape (CLASS COORDS) ARGS ...) -> shape

Returns the shape-plotter for the shape CLASS COORDS & supplied configuration arguments ARGS ....

shape-creator

[procedure] (shape-creator SHAPE [COORDS]) -> procedure

Returns the procedure for creating instances of the class of the supplied shape.

shape-size

[procedure] (shape-size SHAPE) -> integer integer

Returns the width & height (columns & rows) for the shape.

shape-center

[procedure] (shape-center SHAPE) -> integer integer integer integer

Returns the floor ceiling of the shape center.

shape-center-rect

[procedure] (shape-center-rect SHAPE) -> rect

Returns a rect of the shape center.

shape-cardinality

[procedure] (shape-cardinality SHAPE) -> fixnum

Count of grouped shapes.

shape-elements

[procedure] (shape-elements SHAPE) -> (list-of shape)

Grouped shapes.

shape-contains?

[procedure] (shape-contains? SHAPE-A SHAPE-B) -> (list-of shape)

Does SHAPE-A contain SHAPE-B as an element?

shape-layout

[procedure] (shape-layout SHAPE BB) -> shape

Returns a static shape (no elastic elements) for the supplied shape.

BB
rect ; bounding-box, available space for layout

All shapes are justified (lay'ed out) or static, except jpad, hgroup, & vgroup. These will apportion available space in the layout bounding-box to the wrapped shapes, returning a new, static, shape.

shape-justified?

[procedure] (shape-justified? SHAPE) -> boolean

Returns whether the shape is static;no elastic elemetns.

shape-read

shape-write

shape-load

shape-store

[procedure] (shape-read [IN]) -> shape
[procedure] (shape-write SHAPE [OUT])
[procedure] (shape-load PATHNAME) -> shape
[procedure] (shape-store SHAPE PATHNAME)

shapes-read

shapes-write

shapes-load

shapes-store

[procedure] (shapes-read [IN [MAX]]) -> (list-of shape)
[procedure] (shapes-write SHAPES [OUT])
[procedure] (shapes-load PATHNAME) -> (list-of shape-plotter)
[procedure] (shapes-store (list-of shape-plotter) PATHNAME -> void)

shape-show

[procedure] (shape-show SHAPE CANVAS X Y) -> canvas

Dubious utility.

shape-fold

[procedure] (shape-fold SHAPE FUNC SEED) -> SEED-TYPE
SEED-TYPE
'a ; type-of SEED
FUNC
(shape-plotter 'a -> 'a) ;

Dubious utility.

shape-reify

[procedure] (shape-reify INFO) -> shape

Returns the shape-plotter for the marshaled shape-info.

shape-reflect

[procedure] (shape-reflect SHAPE) -> shape-info

Returns the marshaled defining data for the shape.

Char Canvas Shape Box

Usage

(import (s9fes char-canvas shape box))

Default FRAME-CHARS are (s9fes char-canvas) ASCII-FRAME-CHARS.

real-shape-box

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

shape-box

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

Char Canvas Shape Circle

Usage

(import (s9fes char-canvas shape circle))

Shared Arguments & Types:

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

real-shape-circle

[procedure] (real-shape-circle R [CONFIG]) -> real-shape-plotter
R
fixnum ; radius

shape-circle

[procedure] (shape-circle R [CONFIG]) -> shape-plotter
R
integer ; radius
CONFIG
(or false char plotter-configuration) ; 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 circle))

(define canvas-plot-circle@40 (shape-circle 40))

(let ((cv (make-canvas 10 10 100 100)))
  (canvas-plot-circle@40 cv 50 50)
  (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 circle))

(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 plotter-configuration) ; 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, center 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 circle))

(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 circle))

(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))

Char Canvas Shape Cross Shared Arguments & Types:

CONFIG
(or false char plotter-configuration) ; drawing pattern, 2 elements, #f for skip or a char to draw; default is (current-plotter-char).

real-shape-cross--

real-shape-cross-vbar

real-shape-cross-+

[procedure] (real-shape-cross-- WD [HT [CONFIG]]) -> real-shape-plotter
[procedure] (real-shape-cross-vbar WD [HT [CONFIG]]) -> real-shape-plotter
[procedure] (real-shape-cross-+ WD [HT [CONFIG]]) -> real-shape-plotter
WD
fixnum
HT
fixnum ; default WD

real-shape-cross-obar

real-shape-cross-abar

real-shape-cross-x

[procedure] (real-shape-cross-obar WD [HT [CONFIG]]) -> real-shape-plotter
[procedure] (real-shape-cross-abar WD [HT [CONFIG]]) -> real-shape-plotter
[procedure] (real-shape-cross-x WD [HT [CONFIG]]) -> real-shape-plotter
WD
fixnum
HT
fixnum ; default WD

shape-cross--

shape-cross-vbar

shape-cross-+

[procedure] (shape-cross-- WD [HT [CONFIG]]) -> shape-plotter
[procedure] (shape-cross-vbar WD [HT [CONFIG]]) -> shape-plotter
[procedure] (shape-cross-+ WD [HT [CONFIG]]) -> shape-plotter
WD
integer
HT
integer ; default WD

shape-cross-obar

shape-cross-abar

shape-cross-x

[procedure] (shape-cross-obar WD [HT [CONFIG]]) -> shape-plotter
[procedure] (shape-cross-abar WD [HT [CONFIG]]) -> shape-plotter
[procedure] (shape-cross-x WD [HT [CONFIG]]) -> shape-plotter
WD
integer
HT
integer ; default WD
(import (s9fes char-canvas) (s9fes char-canvas shape cross))

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

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

Char Canvas Shape image

Usage

(import (s9fes char-canvas shape image))

read-image

write-image

load-image

store-image

canvas->image

string->image

real-shape-image

shape-image

[procedure] (read-image [IN]) -> image
[procedure] (write-image IMAGE [OUT])
[procedure] (load-image PATH) -> image
[procedure] (store-image IMAGE PATH)
[procedure] (canvas->image CANVAS) -> image
[procedure] (string->image STR) -> image
[procedure] (real-shape-image IMAGE [TRANS]]) -> real-shape-plotter
[procedure] (shape-image IMAGE [TRANS]]) -> shape-plotter

Char Canvas Shape Fpad

Usage

(import (s9fes char-canvas shape fpad))

real-shape-fpad

shape-fpad

[procedure] (real-shape-fpad SHAPE [PAD-DIMS [PAD-CHARS]]) -> real-shape-plotter
[procedure] (shape-fpad SHAPE [PAD-DIMS [PAD-CHARS]])) -> shape-plotter

Char Canvas Shape jpad

Usage

(import (s9fes char-canvas shape jpad))

real-shape-jpad

shape-jpad

[procedure] (real-shape-jpad SHAPE PAD-DIMS [JUST-HORZ [JUST-VERT [PAD-CHARS]]]) -> real-shape-plotter
[procedure] (shape-jpad SHAPE PAD-DIMS [JUST-HORZ [JUST-VERT [PAD-CHARS]]])) -> shape-plotter
JUST-HORZ
symbol ; left | center | right
JUST-VERT
symbol ; top | center | bottom

Char Canvas Shape hgroup

Usage

(import (s9fes char-canvas shape hgroup))

real-shape-hgroup

shape-hgroup

[procedure] (real-shape-hgroup SHAPES | SHAPE ...) -> real-shape-plotter
[procedure] (shape-hgroup SHAPES | SHAPE ...) -> shape-plotter
SHAPES
(list-of shape) ; single-argument & a list
SHAPE ...
list-of shape ; single-argument & not a list or multi-argument

Char Canvas Shape vgroup

Usage

(import (s9fes char-canvas shape vgroup))

real-shape-vgroup

shape-vgroup

[procedure] (real-shape-vgroup SHAPES | SHAPE ...) -> real-shape-plotter
[procedure] (shape-vgroup SHAPES | SHAPE ...) -> shape-plotter
SHAPES
(list-of shape) ; single-argument & a list
SHAPE ...
list-of shape ; single-argument & not a list or multi-argument

Bugs & Limitations

Notes

Requirements

utf8 srfi-1 record-variants

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.5.1
Update layout. Add shape-new. Fix for CHICKEN 6.
1.5.0
Add shape-creator, pad-dims, ONE-DIMS., pad-chars.
1.4.0
Add create-shape, shape-read/write/load/store, shapes-read/write/load/store.
1.3.0
plotter-configuration change.
1.2.1
Fix .egg.
1.2.0
Add fpad, jpad, hgroup, vgroup.
1.1.0
Rename problematic cross symbols.
1.0.0
Move shapes from the s9fes-char-canvas) egg.

License

Public Domain