groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] A tip for arbitrary colours in PIC


From: Ted Harding
Subject: [Groff] A tip for arbitrary colours in PIC
Date: Sat, 12 Sep 2009 16:43:36 +0100 (BST)

Hi Folks,
I don't know if this has been discussed before. If not, people
may be interested in the following technique for setting up
arbitrary ("RGB") colours in PIC.

The problem with using the "colo[u]r[ed]" attribute, and similar,
in PIC is that you have to give it the name of a colour, which in
turn has to have been predefined for troff (e.g. in ps.tmac), as
described in 'info pic'.

However, in some applications you may want to use a colour which
depends on values of variables in pic which cannot be predicted.
Therefore the corresponding colours cannot be predefined. An example
of such an application is the drawing of colour-shaded contour plots.

The following PIC code fills a square with horizontal lines, in
a colour continuously graduated from green to red according to the
height of the line above the base of the square, by passing the
PostScript command

  p (1-p) 0 setrgbcolour

where p is a number between 0 and 1 computed internally in PIC.

8<--------------------------------------------------------------

.PS 5i 
for i=0 to 1000 do {
  red = i/1000 ; green = 1-red
  sprintf("\Z\'\X\'ps: exec %.4f %.4f 0 setrgbcolor\'\'",red,green)
  line from (0,5*i/1000) to (5,5*i/1000) thick 0.5
}
line from (0,0) to (5,0) to (5,5) to (0,5) to (0,0) colour "black"
.PE
\X'ps: exec 1 1 1 setrgbcolor'\c
.ce
\fBExample of Colour Shading\fP

8<--------------------------------------------------------------

Clearly the trick can be extended to more complicated examples.
Best wishes to all,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 12-Sep-09                                       Time: 16:43:32
------------------------------ XFMail ------------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]