Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #772

Re: setrgbcolor with lineto/curveto

From John Deubert <john@acumentraining.com>
Organization Acumen Training
Newsgroups comp.lang.postscript
Date 2012-06-30 10:20 -0700
Message-ID <2012063010205688771-john@acumentrainingcom> (permalink)
References <jra5b7$mqu$1@reader1.panix.com>
Subject Re: setrgbcolor with lineto/curveto

Show all headers | View raw


Just for the record, here's a smooth shading (partial) solution. It's 
smaller and cleaner (I think), but does require a Level 3 interpreter. 
Also, this produces the desired results only if you are stroking a 
single line segment or not-very-curvy bezier; it won’t fail with a more 
complex path, but will probably not give the results you want. A final 
solution would require some surgery on the code.

% ============== cut here ===========
/ShadingDict		<<			% This dict defines the gradient.
	/ShadingType 2			% We'll use a linear gradient...
	/ColorSpace [ /DeviceRGB ]	% ...in RGB
	/Coords [ 200 200 400 400 ] 	% These are the same as line segment endpoints
	/Domain [ 0 1 ]			% Internal parameter
	/Function	<<			% This defines how the color should vary...
		/FunctionType 2		% ...across the line
		/Domain [ 0 1 ]
		/Range [ 0 1 0 1 0 1 ]	% R, G, & B each can vary from 0 to 1
		/C0	[ 1 0 0 ]		% Start Color
		/C1	[ 0 1 0 ]		% End Color
		/N	1			% Varies linearly
	>>
>> def

3 setlinewidth				% Construct our path
200 200 moveto 400 400 lineto
strokepath clip				% Turn it into a clipping region
ShadingDict shfill				% Fill it with out gradient; Bob's your uncle!

showpage
% ============== cut here ===========


As long as I’m messing about with this (and what do *you* do on a 
Saturday morning?) here’s the same technique turned into a procedure 
named strokegradientline:

% ============== cut here ===========
/ShadingDict		<<			% Same ShadingDict as earlier.
	/ShadingType 2
	/ColorSpace [ /DeviceRGB ]
	/Coords [ 200 200 400 400 ]
	/Domain [ 0 1 ]
	/Function	<<
		/FunctionType 2	
		/Domain [ 0 1 ]
		/Range [ 0 1 0 1 0 1 ]
		/C0	[ 1 0 0 ]
		/C1	[ 0 1 0 ]
		/N	1
	>>
>> def


/strokegradientline	% [ r0 g0 b0 ] [ r1 g1 b1 ]  x0 y0 x1 y1  => ---
{
	gsave
	4 copy moveto lineto		% first let's the line
	strokepath clip				% and turn it into a clipping path
	ShadingDict begin			% Go get our Shading dictionary
	4 array astore				% Put the xy's into an array
	/Coords exch def			% And use it for the Coords entry
	Function begin				% Get the function dictionary
	/C1 exch def				% Put our colors into it as C0 and C1
	/C2 exch def
	end end						% Clean up the dict stack
	ShadingDict shfill			% And shfill it.
	grestore					% Restore our clipping path
} bind def

% And now try this puppy out
3 setlinewidth
[ 1 0 0 ][ 0 0 1 ] 200 200 400 400 strokegradientline
[ 0 1 1 ][ 1 1 0 ] 300 200 500 400 strokegradientline

showpage
% ============== cut here ===========

Again, this isn't a final solution to the problem of an arbitrary path, 
but I thought a
Smooth Shading example was called for.

If you’re curious about Smooth Shading, I wrote an article on the 
subject for my Acumen  Journal ages ago (let’s look that up...ah. 
November 2000; issue 1, actually). You can get it free for the 
downloading at www.acumentraining.com/acumenjournal.html.


-- 
========
John Deubert
Acumen Training
PostScript & PDF Engineering Classes & Consulting
www.acumentraining.com

Learn PostScript programming techniques
Read the free Acumen Journal
acumentraining.com/acumenjournal.html

Back to comp.lang.postscript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-06-13 13:41 +0000
  Re: setrgbcolor with lineto/curveto Helge Blischke <h.blischke@acm.org> - 2012-06-13 16:16 +0200
    Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-06-13 16:04 +0000
    Re: setrgbcolor with lineto/curveto Odysseus <odysseus1479-at@yahoo-dot.ca> - 2012-06-13 20:20 -0600
      Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-06-14 04:05 +0000
      Re: setrgbcolor with lineto/curveto luser- -droog <mijoryx@yahoo.com> - 2012-06-16 14:45 -0700
  Re: setrgbcolor with lineto/curveto luser- -droog <mijoryx@yahoo.com> - 2012-06-13 16:20 -0700
    Re: setrgbcolor with lineto/curveto luser- -droog <mijoryx@yahoo.com> - 2012-06-13 17:16 -0700
      Re: setrgbcolor with lineto/curveto luser- -droog <mijoryx@yahoo.com> - 2012-06-13 17:36 -0700
        Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-06-14 04:11 +0000
          Re: setrgbcolor with lineto/curveto luser- -droog <mijoryx@yahoo.com> - 2012-06-14 09:05 -0700
  Re: setrgbcolor with lineto/curveto gernot.hoffmann@hs-emden-leer.de - 2012-06-16 11:00 -0700
  Re: setrgbcolor with lineto/curveto gernot.hoffmann@hs-emden-leer.de - 2012-06-16 10:55 -0700
    Re: setrgbcolor with lineto/curveto gernot.hoffmann@hs-emden-leer.de - 2012-06-16 11:23 -0700
    Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-06-19 07:00 +0000
      Re: setrgbcolor with lineto/curveto gernot.hoffmann@hs-emden-leer.de - 2012-06-19 00:34 -0700
        Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-06-19 08:12 +0000
  Re: setrgbcolor with lineto/curveto John Deubert <john@acumentraining.com> - 2012-06-30 10:20 -0700
    Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-07-04 03:07 +0000
      Re: setrgbcolor with lineto/curveto luser- -droog <mijoryx@yahoo.com> - 2012-07-05 16:24 -0700
        Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-07-06 14:23 +0000
          Re: setrgbcolor with lineto/curveto JohnF <john@please.see.sig.for.email.com> - 2012-07-11 01:57 +0000
        Re: setrgbcolor with lineto/curveto tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-07-11 01:08 -0400
          Re: setrgbcolor with lineto/curveto luser- -droog <mijoryx@yahoo.com> - 2012-07-12 03:12 -0700
            Re: setrgbcolor with lineto/curveto tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-07-12 22:20 -0400

csiph-web