s9fes-char-graphics
A Shape extemsopm tp the Scheme 9 from Empty Space'' character graphics library; the s9fes-char-graphics-shape egg.
- s9fes-char-graphics
- Char Canvas Shape Shared Arguments & Types:
- Char Canvas Shape Shape
- Usage
- pad-dims
- ONE-DIMS
- pad-chars
- registered-shapes
- registered-shape-methods
- shape-class
- shape-coords
- create-shape
- shape-creator
- shape-size
- shape-center
- shape-center-rect
- shape-cardinality
- shape-elements
- shape-contains?
- shape-layout
- shape-justified?
- shape-read
- shape-write
- shape-load
- shape-store
- shapes-read
- shapes-write
- shapes-load
- shapes-store
- shape-show
- shape-fold
- shape-reify
- shape-reflect
- Char Canvas Shape Box
- Char Canvas Shape Circle
- Char Canvas Shape Cross
- Char Canvas Shape Cross Shared Arguments & Types:
- Char Canvas Shape image
- Char Canvas Shape Fpad
- Char Canvas Shape jpad
- Char Canvas Shape hgroup
- Char Canvas Shape vgroup
- Bugs & Limitations
- Notes
- Requirements
- Author
- Repository
- Version history
- 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
Char Canvas Shape Shape
Usage
(import (s9fes char-canvas shape shape))
pad-dims
[procedure] (pad-dims TOP BOTTOM LEFT RIGHT) -> pad-dimsONE-DIMS
[constant] ONE-DIMSAll ones, 1 1 1 1.
pad-chars
[procedure] (pad-chars TOP BOTTOM LEFT RIGHT) -> pad-charsregistered-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-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]) -> procedureReturns the procedure for creating instances of the class of the supplied shape.
shape-size
[procedure] (shape-size SHAPE) -> integer integerReturns the width & height (columns & rows) for the shape.
shape-center
[procedure] (shape-center SHAPE) -> integer integer integer integerReturns the floor ceiling of the shape center.
shape-center-rect
[procedure] (shape-center-rect SHAPE) -> rectReturns a rect of the shape center.
shape-cardinality
[procedure] (shape-cardinality SHAPE) -> fixnumCount 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) -> shapeReturns 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) -> booleanReturns 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) -> canvasDubious 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) -> shapeReturns the shape-plotter for the marshaled shape-info.
shape-reflect
[procedure] (shape-reflect SHAPE) -> shape-infoReturns 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) ) ;=> ****** * * * * * * * * * * * * * * * * ******
- Note how restricting the number of segments coarsens the image, even clipping. ((circle-polygon-lines 50 50 49 4) produces an ok diamond.)
(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-plotterReturns 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 fixnumReturns 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-visitorSame 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
- images are "composited" using the (current-plotter-bkgd-char) as the "alpha-channel". Source background is ignored and only foreground characters are placed. (see canvas-paste)
[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
- None. A thing of beauty.
Notes
- Shape position as the center is different. The lower-left is probably expected.
- The plot/virtual API with the draw/real distinction follows the original pattern. However, except as implementation details, using the draw/real is unlikely to be worth the effort. For performance have pixels always be chars: don't specify a virtual canvas size.
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.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