chickadee » s9fes-char-graphics-shapes

s9fes-char-graphics

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

TOC »

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

pad-dims TOP BOTTOM LEFT RIGHTprocedure

ONE-DIMS

ONE-DIMSconstant

All ones, 1 1 1 1.

pad-chars

pad-chars TOP BOTTOM LEFT RIGHTprocedure

registered-shapes

registered-shapesprocedure

Returns a list of shape CLASS.

registered-shape-methods

registered-shape-methods IDprocedure
CLASS
symbol : shape name

shape-new

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

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

shape-class SHAPEprocedure
shape-coords SHAPEprocedure

create-shape

(create-shape CLASS ARGS ...) -> shapesyntax
(create-shape (CLASS COORDS) ARGS ...) -> shapesyntax

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

shape-creator

shape-creator SHAPE #!optional COORDSprocedure

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

shape-size

shape-size SHAPEprocedure

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

shape-center

shape-center SHAPEprocedure

Returns the floor ceiling of the shape center.

shape-center-rect

shape-center-rect SHAPEprocedure

Returns a rect of the shape center.

shape-cardinality

shape-cardinality SHAPEprocedure

Count of grouped shapes.

shape-elements

shape-elements SHAPEprocedure

Grouped shapes.

shape-contains?

shape-contains? SHAPE-A SHAPE-Bprocedure

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

shape-layout

shape-layout SHAPE BBprocedure

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?

shape-justified? SHAPEprocedure

Returns whether the shape is static;no elastic elemetns.

shape-read

shape-write

shape-load

shape-store

shape-read #!optional INprocedure
shape-write SHAPE #!optional OUTprocedure
shape-load PATHNAMEprocedure
shape-store SHAPE PATHNAMEprocedure

shapes-read

shapes-write

shapes-load

shapes-store

shapes-read #!optional IN MAXprocedure
shapes-write SHAPES #!optional OUTprocedure
shapes-load PATHNAMEprocedure
(shapes-store (list-of shape-plotter) PATHNAME -> void)procedure

shape-show

shape-show SHAPE CANVAS X Yprocedure

Dubious utility.

shape-fold

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

Dubious utility.

shape-reify

shape-reify INFOprocedure

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

shape-reflect

shape-reflect SHAPEprocedure

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

real-shape-box WD HT #!optional FRAME-CHARSprocedure
WD
fixnum ; width
HT
fixnum ; height

shape-box

shape-box WD HT #!optional FRAME-CHARSprocedure
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

real-shape-circle R #!optional CONFIGprocedure
R
fixnum ; radius

shape-circle

shape-circle R #!optional CONFIGprocedure
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-octant-plotter

circle-octant-plotter #!optional CONFIGprocedure

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

generate-circle-octant CANVAS RADIUS VISITORprocedure

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

circle-octant-point OCTANT X0 Y0 X Yprocedure

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

circle-octant-visitor X0 Y0 PLOTTERprocedure
X0 Y0
fixnum fixnum ; center
PLOTTER
octant-plotter

generate-virtual-circle-octant

generate-virtual-circle-octant CANVAS RADIUS VISITOR #!optional AVERAGE?procedure

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

virtual-circle-octant-visitor X0 Y0 PLOTTERprocedure

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-+

real-shape-cross-- WD #!optional HT CONFIGprocedure
real-shape-cross-vbar WD #!optional HT CONFIGprocedure
real-shape-cross-+ WD #!optional HT CONFIGprocedure
WD
fixnum
HT
fixnum ; default WD

real-shape-cross-obar

real-shape-cross-abar

real-shape-cross-x

real-shape-cross-obar WD #!optional HT CONFIGprocedure
real-shape-cross-abar WD #!optional HT CONFIGprocedure
real-shape-cross-x WD #!optional HT CONFIGprocedure
WD
fixnum
HT
fixnum ; default WD

shape-cross--

shape-cross-vbar

shape-cross-+

shape-cross-- WD #!optional HT CONFIGprocedure
shape-cross-vbar WD #!optional HT CONFIGprocedure
shape-cross-+ WD #!optional HT CONFIGprocedure
WD
integer
HT
integer ; default WD

shape-cross-obar

shape-cross-abar

shape-cross-x

shape-cross-obar WD #!optional HT CONFIGprocedure
shape-cross-abar WD #!optional HT CONFIGprocedure
shape-cross-x WD #!optional HT CONFIGprocedure
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

read-image #!optional INprocedure
write-image IMAGE #!optional OUTprocedure
load-image PATHprocedure
store-image IMAGE PATHprocedure
canvas->image CANVASprocedure
string->image STRprocedure
  • 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)
(real-shape-image IMAGE [TRANS]]) -> real-shape-plotterprocedure
(shape-image IMAGE [TRANS]]) -> shape-plotterprocedure

Char Canvas Shape Fpad

Usage

(import (s9fes char-canvas shape fpad))

real-shape-fpad

shape-fpad

real-shape-fpad SHAPE #!optional PAD-DIMS PAD-CHARSprocedure
shape-fpad SHAPE #!optional PAD-DIMS PAD-CHARSprocedure

Char Canvas Shape jpad

Usage

(import (s9fes char-canvas shape jpad))

real-shape-jpad

shape-jpad

real-shape-jpad SHAPE PAD-DIMS #!optional JUST-HORZ JUST-VERT PAD-CHARSprocedure
shape-jpad SHAPE PAD-DIMS #!optional JUST-HORZ JUST-VERT PAD-CHARSprocedure
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

(real-shape-hgroup SHAPES | SHAPE ...) -> real-shape-plotterprocedure
(shape-hgroup SHAPES | SHAPE ...) -> shape-plotterprocedure
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

(real-shape-vgroup SHAPES | SHAPE ...) -> real-shape-plotterprocedure
(shape-vgroup SHAPES | SHAPE ...) -> shape-plotterprocedure
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 s9fes-char-graphics

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

Contents »