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


Groups > comp.lang.postscript > #772

Re: setrgbcolor with lineto/curveto

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Sat, 30 Jun 2012 12:20:56 -0500
From John Deubert <john@acumentraining.com>
Organization Acumen Training
Newsgroups comp.lang.postscript
Date Sat, 30 Jun 2012 10:20:56 -0700
Message-ID <2012063010205688771-john@acumentrainingcom> (permalink)
References <jra5b7$mqu$1@reader1.panix.com>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Subject Re: setrgbcolor with lineto/curveto
User-Agent Unison/2.1.7
Lines 98
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-8N1bzjOpSwO702RnsJtZlDh6cxnwBhDCyvP0q27GMe16M69JF4EYhePO8Za9N4lyrq06Kik9RT486xa!lkYzoJQ2ciWhXApH3kVGfslY3r+pjw1ZAxbGLZxu3bm1rLXUDeOZa9Ux538/1sGYlfdHtIK1
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 4262
Xref csiph.com comp.lang.postscript:772

Show key headers only | 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 | Unroll thread


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