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 The ''Scheme 9 from Empty Space'' character graphics routines. === 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 <enscript language=scheme> (import (s9fes char-canvas)) </enscript> ==== make-canvas <procedure>(make-canvas COLUMNS ROWS [WIDTH [HEIGHT]]) -> canvas</procedure> 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. ==== canvas? ==== canvas-columns ==== canvas-rows ==== canvas-width ==== canvas-height <procedure>(canvas? OBJ) -> boolean</procedure> <procedure>(canvas-columns CANVAS) -> fixnum</procedure> <procedure>(canvas-rows CANVAS) -> fixnum</procedure> <procedure>(canvas-width CANVAS) -> integer</procedure> <procedure>(canvas-height CANVAS) -> integer</procedure> ==== canvas-physical <procedure>(canvas-physical CANVAS X Y) -> X Y</procedure> Returns the physical coordinates for the supplied virtual {{X Y}}. ==== canvas-virtual <procedure>(canvas-virtual CANVAS X Y) -> X Y</procedure> 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)</procedure> 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)</procedure> Prints the {{CANVAS}}, one row per line. ==== canvas->string <procedure>(canvas-string CANVAS) -> string</procedure> Prints the {{CANVAS}} to a {{string}}. ==== canvas-clear <procedure>(canvas-clear CANVAS)</procedure> ==== current-plotter-char <procedure>(current-plotter-char [CHAR]) -> char</procedure> Default {{char}} for drawing. ==== canvas-draw <procedure>(canvas-draw CANVAS X Y [CHAR])</procedure> 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)</procedure> 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])</procedure> 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])</procedure> ; {{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])</procedure> 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)</procedure> 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])</procedure> 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])</procedure> ; {{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)}}. === Char Canvas Shape Oval ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape oval)) </enscript> 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]) -> (CANVAS X0 Y0 -> void)</procedure> ; {{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)}}. ==== virtual-shape-oval <procedure>(virtual-shape-oval R [CONFIG]) -> (CANVAS X0 Y0 -> void)</procedure> ; {{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)}}. <enscript language=scheme> (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) ) ;=> *** * * * * * * * * * * * * * * *** </enscript> ==== draw-circle <procedure>(draw-circle CANVAS X0 Y0 R [CONFIG])</procedure> ; {{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])</procedure> ; {{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)}}. <enscript language=scheme> (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) ) ;=> *** * * * * * * * * * * * * * * *** </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 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 40 4)) (canvas-print cv) ) ;=> * * * * * * * * * * * * * * * * </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 (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)</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}}, 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</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 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) ) ;=> *** * * * * * * *** </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 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) ) ;=> *** * * * * * * *** </enscript> === Char Canvas Shape Cross Shared Arguments & Types: ; {{shape-plotter}} : {{(CANVAS #!optional XM YM -> void)}} ; {{XM YM}} : {{fixnum fixnum}} ; center ; {{virtual-shape-plotter}} : {{(CANVAS #!optional XM YM -> void)}} ; {{XM YM}} : {{integer integer}} ; center ==== Usage <enscript language=scheme> (import (s9fes char-canvas shape cross)) </enscript> ==== shape-cross-+ <procedure>(shape-cross-+ WD [HT [CONFIG]]) -> shape-plotter</procedure> ; {{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</procedure> ; {{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</procedure> ; {{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</procedure> ; {{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)}}. <enscript language=scheme> (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) ) ;=> ** ** ** ** ** ** ** ** ** </enscript> === Char Plot ==== Usage <enscript language=scheme> (import (s9fes char-plot)) </enscript> ==== char-plot <procedure>(char-plot LIST SYMBOL HEIGHT WDITH [COMPR?])</procedure> 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}}. <enscript language=scheme> (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 --> ----------------- </enscript> === Draw Tree ==== Usage <enscript language=scheme> (import (s9fes draw-tree)) </enscript> ==== draw-tree <procedure>(draw-tree ROOT [MAX-WIDTH])</procedure> 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}}. <enscript language=scheme> (draw-tree '((a) (b . c) (d e))) ;=> [o|o]---[o|o]---[o|/] | | | [o|/] | [o|o]---[o|/] | | | | a | d e | [o|o]--- c | b </enscript> == Requirements [[utf8]] [[srfi-1]] [[format]] [[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.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
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 10 from 17?