Difference between revisions of "Pic language"

From Christoph's Personal Wiki
Jump to: navigation, search
 
(External links)
 
Line 45: Line 45:
 
*[http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/web/pic.html Making Pictures With GNU PIC]
 
*[http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/web/pic.html Making Pictures With GNU PIC]
 
*[http://www.kohala.com/start/troff/troff.html Troff resources (see the "pic" section)]
 
*[http://www.kohala.com/start/troff/troff.html Troff resources (see the "pic" section)]
*[http://www.kohala.com/start/troff/pic2html.html Turning PIC into HTML
+
*[http://www.kohala.com/start/troff/pic2html.html Turning PIC into HTML]
*[http://www.ece.uwaterloo.ca/~aplevich/dpic/ DPIC], an implementation of the PIC language by Dwight Aplevich. This implementation has a few nice extensions and outputs many different image formats.
+
*[http://www.ece.uwaterloo.ca/~aplevich/dpic/ DPIC], an implementation of the PIC language by Dwight Aplevich. This implementation has a few nice extensions and outputs many different image formats.
*[http://www.ece.uwaterloo.ca/~aplevich/dpic/ DPIC] — by Dwight Aplevich
+
  
 
[[category:Linux Command Line Tools]]
 
[[category:Linux Command Line Tools]]
 
[[category:Graphics software]]
 
[[category:Graphics software]]

Latest revision as of 05:47, 3 July 2007

Pic is a domain-specific language by Brian Kernighan for specifying diagrams in terms of objects such as boxes with arrows between them. The pic compiler translates this description into concrete drawing commands. Pic is a procedural programming language, with variable assignment, macros, conditionals, and looping.

Pic has some similarity with MetaPost and the DOT language.

Example PIC file

Create a file, foo.pic, with the following:

.PS
# Draw a demonstration up left arrow with grid box overlay
define gridarrow
{
    move right 0.1
    [
        {arrow up left $1;}
        box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
        for i = 2 to ($1 / 0.5) do
        {
            box wid 0.5 ht 0.5 dotted with .sw at last box .se;
        }
        move down from last arrow .center;
        [
            if ( $1 == boxht ) \
            then { "\fBline up left\fP" } \
            else { sprintf("\fBarrow up left %g\fP", $1) };
        ]
    ]
    move right 0.1 from last [] .e;
}
gridarrow(0.5);
gridarrow(1);
gridarrow(1.5);
gridarrow(2);
undef gridarrow
.PE

Now, turn this PIC into a PNG with:

pic2plot -T png -f 0.012 --bitmap-size 1000x1000 foo.pic >foo.png
convert -crop 0x0 foo.png foo.png

References

  • Kernighan BW (1982). "PIC: a language for typesetting graphics". Software Practice Experience, 12:1-20.

External links