Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
[[tags: egg]] == 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 === Char Canvas Shape Shape ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape shape)) </enscript> ==== pad-dims <procedure>(pad-dims TOP BOTTOM LEFT RIGHT) -> pad-dims</procedure> ==== ONE-DIMS <constant>ONE-DIMS</constant> All ones, {{1 1 1 1}}. ==== pad-chars <procedure>(pad-chars TOP BOTTOM LEFT RIGHT) -> pad-chars</procedure> ==== registered-shapes <procedure>(registered-shapes) -> (list-of symbol)</procedure> Returns a {{list}} of ''shape'' {{CLASS}}. ==== registered-shape-methods <procedure>(registered-shape-methods ID) -> (list-of symbol)</procedure> ; {{CLASS}} : {{symbol}} : shape name ==== shape-class ==== shape-coords <procedure>(shape-class SHAPE) -> symbol</procedure> <procedure>(shape-coords SHAPE) -> symbol</procedure> ==== create-shape <syntax>(create-shape CLASS ARGS ...) -> shape</syntax> <syntax>(create-shape (CLASS COORDS) ARGS ...) -> shape</syntax> Returns the {{shape-plotter}} for the ''shape'' {{CLASS COORDS}} & supplied configuration arguments {{ARGS ...}}. ==== shape-creator <procedure>(shape-creator SHAPE [COORDS]) -> procedure</procedure> Returns the procedure for creating instances of the class of the supplied {{shape}}. ==== shape-size <procedure>(shape-size SHAPE) -> integer integer</procedure> Returns the {{width}} & {{height}} ({{columns}} & {{rows}}) for the {{shape}}. ==== shape-center <procedure>(shape-center SHAPE) -> integer integer integer integer</procedure> Returns the {{floor ceiling}} of the {{shape}} ''center''. ==== shape-center-rect <procedure>(shape-center-rect SHAPE) -> rect</procedure> Returns a {{rect}} of the {{shape}} ''center''. ==== shape-cardinality <procedure>(shape-cardinality SHAPE) -> fixnum</procedure> Count of grouped shapes. ==== shape-elements <procedure>(shape-elements SHAPE) -> (list-of shape)</procedure> Grouped shapes. ==== shape-contains? <procedure>(shape-contains? SHAPE-A SHAPE-B) -> (list-of shape)</procedure> Does {{SHAPE-A}} contain {{SHAPE-B}} as an ''element''? ==== shape-layout <procedure>(shape-layout SHAPE BB) -> shape</procedure> 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</procedure> Returns whether the {{shape}} is ''static'';no ''elastic'' elemetns. ==== shape-read ==== shape-write ==== shape-load ==== shape-store <procedure>(shape-read [IN]) -> shape</procedure> <procedure>(shape-write SHAPE [OUT])</procedure> <procedure>(shape-load PATHNAME) -> shape</procedure> <procedure>(shape-store SHAPE PATHNAME)</procedure> ==== shapes-read ==== shapes-write ==== shapes-load ==== shapes-store <procedure>(shapes-read [IN [MAX]]) -> (list-of shape)</procedure> <procedure>(shapes-write SHAPES [OUT])</procedure> <procedure>(shapes-load PATHNAME) -> (list-of shape-plotter)</procedure> <procedure>(shapes-store (list-of shape-plotter) PATHNAME -> void)</procedure> ==== shape-show <procedure>(shape-show SHAPE CANVAS X Y) -> canvas</procedure> Dubious utility. ==== shape-fold <procedure>(shape-fold SHAPE FUNC SEED) -> SEED-TYPE</procedure> ; {{SEED-TYPE}} : {{'a}} ; type-of {{SEED}} ; {{FUNC}} : {{(shape-plotter 'a -> 'a)}} ; Dubious utility. ==== shape-reify <procedure>(shape-reify INFO) -> shape</procedure> Returns the {{shape-plotter}} for the ''marshaled'' {{shape-info}}. ==== shape-reflect <procedure>(shape-reflect SHAPE) -> shape-info</procedure> Returns the ''marshaled'' defining data for the {{shape}}. === Char Canvas Shape Box ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape box)) </enscript> Default {{FRAME-CHARS}} are {{(s9fes char-canvas) ASCII-FRAME-CHARS}}. ==== real-shape-box <procedure>(real-shape-box WD HT [FRAME-CHARS]) -> real-shape-plotter</procedure> ; {{WD}} : {{fixnum}} ; width ; {{HT}} : {{fixnum}} ; height ==== shape-box <procedure>(shape-box WD HT [FRAME-CHARS]) -> shape-plotter</procedure> ; {{WD}} : {{integer}} ; width ; {{HT}} : {{integer}} ; height === Char Canvas Shape Circle ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape circle)) </enscript> 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</procedure> ; {{R}} : {{fixnum}} ; radius ==== shape-circle <procedure>(shape-circle R [CONFIG]) -> shape-plotter</procedure> ; {{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)}}. <enscript language=scheme> (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) ) ;=> +----------+ | *** | | * * | | * * | | * *| | * *| | * *| | * * | | * * | | *** | | | +----------+ </enscript> ==== circle-polygon-lines <procedure>(circle-polygon-lines X0 Y0 RADIUS [N [ANGLE]) -> (list-of integer)</procedure> 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}} <enscript language=scheme> (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) ) ;=> ****** * * * * * * * * * * * * * * * * ****** </enscript> * Note how restricting the number of segments coarsens the image, even clipping. ({{(circle-polygon-lines 50 50 49 4)}} produces an ''ok'' diamond.) <enscript language=scheme> (let ((cv (make-canvas 10 10 100 100))) (canvas-plot-lines cv (circle-polygon-lines 50 50 50 4)) (canvas-print cv #t) ) ;=> +----------+ | * * | | * * | | * * | | * *| |* | | * *| | * ** | | * * | | * * | | * | +----------+ </enscript> ==== circle-octant-plotter <procedure>(circle-octant-plotter [CONFIG]) -> octant-plotter</procedure> 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)</procedure> 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</procedure> 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</procedure> ; {{X0 Y0}} : {{fixnum fixnum}} ; center ; {{PLOTTER}} : {{octant-plotter}} ==== generate-virtual-circle-octant <procedure>(generate-virtual-circle-octant CANVAS RADIUS VISITOR [AVERAGE?])</procedure> Same as {{generate-circle-octant}} but w/ virtual coordinates (see above). ; {{RADIUS}} : {{integer}} ; radius ; {{VISITOR}} : {{octant-visitor}} <enscript language=scheme> (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) ) ;=> *** * * * * * * *** </enscript> ==== virtual-circle-octant-visitor <procedure>(virtual-circle-octant-visitor X0 Y0 PLOTTER) -> octant-visitor</procedure> Same as {{circle-octant-visitor}} but w/ virtual coordinates (see above). ; {{X0 Y0}} : {{integer integer}} ; center ; {{PLOTTER}} : {{octant-plotter}} <enscript language=scheme> (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) ) ;=> *** * * * * * * *** </enscript> === Char Canvas Shape Cross ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape cross)) </enscript> === 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> <procedure>(real-shape-cross-vbar WD [HT [CONFIG]]) -> real-shape-plotter</procedure> <procedure>(real-shape-cross-+ WD [HT [CONFIG]]) -> real-shape-plotter</procedure> ; {{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> <procedure>(real-shape-cross-abar WD [HT [CONFIG]]) -> real-shape-plotter</procedure> <procedure>(real-shape-cross-x WD [HT [CONFIG]]) -> real-shape-plotter</procedure> ; {{WD}} : {{fixnum}} ; {{HT}} : {{fixnum}} ; default {{WD}} ==== shape-cross-- ==== shape-cross-vbar ==== shape-cross-+ <procedure>(shape-cross-- WD [HT [CONFIG]]) -> shape-plotter</procedure> <procedure>(shape-cross-vbar WD [HT [CONFIG]]) -> shape-plotter</procedure> <procedure>(shape-cross-+ WD [HT [CONFIG]]) -> shape-plotter</procedure> ; {{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> <procedure>(shape-cross-abar WD [HT [CONFIG]]) -> shape-plotter</procedure> <procedure>(shape-cross-x WD [HT [CONFIG]]) -> shape-plotter</procedure> ; {{WD}} : {{integer}} ; {{HT}} : {{integer}} ; default {{WD}} <enscript language=scheme> (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) ) ;=> ** ** ** ** ** ** ** ** ** </enscript> === Char Canvas Shape image ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape image)) </enscript> ==== read-image ==== write-image ==== load-image ==== store-image ==== canvas->image ==== string->image ==== real-shape-image ==== shape-image <procedure>(read-image [IN]) -> image</procedure> <procedure>(write-image IMAGE [OUT])</procedure> <procedure>(load-image PATH) -> image</procedure> <procedure>(store-image IMAGE PATH)</procedure> <procedure>(canvas->image CANVAS) -> image</procedure> <procedure>(string->image STR) -> image</procedure> * 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>(real-shape-image IMAGE [TRANS]]) -> real-shape-plotter</procedure> <procedure>(shape-image IMAGE [TRANS]]) -> shape-plotter</procedure> === Char Canvas Shape Fpad ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape fpad)) </enscript> ==== real-shape-fpad ==== shape-fpad <procedure>(real-shape-fpad SHAPE [PAD-DIMS [PAD-CHARS]]) -> real-shape-plotter</procedure> <procedure>(shape-fpad SHAPE [PAD-DIMS [PAD-CHARS]])) -> shape-plotter</procedure> === Char Canvas Shape jpad ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape jpad)) </enscript> ==== real-shape-jpad ==== shape-jpad <procedure>(real-shape-jpad SHAPE PAD-DIMS [JUST-HORZ [JUST-VERT [PAD-CHARS]]]) -> real-shape-plotter</procedure> <procedure>(shape-jpad SHAPE PAD-DIMS [JUST-HORZ [JUST-VERT [PAD-CHARS]]])) -> shape-plotter</procedure> ; {{JUST-HORZ}} : {{symbol}} ; left | center | right ; {{JUST-VERT}} : {{symbol}} ; top | center | bottom === Char Canvas Shape hgroup ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape hgroup)) </enscript> ==== real-shape-hgroup ==== shape-hgroup <procedure>(real-shape-hgroup SHAPES | SHAPE ...) -> real-shape-plotter</procedure> <procedure>(shape-hgroup SHAPES | SHAPE ...) -> shape-plotter</procedure> ; {{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 <enscript language=scheme> (import (s9fes char-canvas shape vgroup)) </enscript> ==== real-shape-vgroup ==== shape-vgroup <procedure>(real-shape-vgroup SHAPES | SHAPE ...) -> real-shape-plotter</procedure> <procedure>(shape-vgroup SHAPES | SHAPE ...) -> shape-plotter</procedure> ; {{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 [[utf8]] [[srfi-1]] [[record-variants]] [[test]] [[test-utils]] == Author [[/users/kon-lovett|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|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 [[/egg-svn-checkout|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
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 8 from 5?