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 Organization: Acumen Training Newsgroups: comp.lang.postscript Date: Sat, 30 Jun 2012 10:20:56 -0700 Message-ID: <2012063010205688771-john@acumentrainingcom> References: 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 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