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


Groups > comp.lang.postscript > #1364

Re: merging colors..

X-Received by 10.224.157.1 with SMTP id z1mr8709015qaw.8.1364833630110; Mon, 01 Apr 2013 09:27:10 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!ca1no19811863qab.0!news-out.google.com!v17ni16135qad.0!nntp.google.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 Mon, 01 Apr 2013 11:27:09 -0500
From John Deubert <john@acumentraining.com>
Organization Acumen Training
Newsgroups comp.lang.postscript
Date Mon, 1 Apr 2013 09:27:09 -0700
Message-ID <2013040109270998040-john@acumentrainingcom> (permalink)
References <c866t.310117$PC7.285767@newsfe03.iad> <2013040107092515878-john@acumentrainingcom>
MIME-Version 1.0
Subject Re: merging colors..
User-Agent Unison/2.1.10
Lines 250
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-YQMANPcZZGnBHZyQD2W20Iuy3t4Sg2/DsUTN2DRqkofjpsUo5QJM3LiFkNMOpZmnZZUznX9j3K7OKLa!uJxUEhLXV9/GdMvCEMtmNIwX1wS7nL5nejkfQapdWvwv21Zxpi6msR7/M5W+M2spcSLyy1RS
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 7273
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Xref csiph.com comp.lang.postscript:1364

Show key headers only | View raw


On 2013-04-01 14:09:25 +0000, John Deubert said:

> On 2013-04-01 03:19:10 +0000, Robert Baer said:
> 
>> This is my first "fancy" program, three color-shaded circles.
>> It would be nice to have the colors appropriately combine/add in the 
>> overlap regions.
>> Is there a nice way to do that?
>> 
>> %!                    % three.ps
>> /inch {72 mul} def   % 72 pixels to the inch
>> /N 500 def           % steps
>> /red 1 def
>> /green {1 3 div} def
>> /blue {2 3 div} def
>> /size {dup inch exch inch scale} def
>> /circle
>> {
>> newpath
>> exch % order: hue sat on top
>> 0 0 moveto        % (circlestack) stack pop % ? where does it go?
>> 1 sethsbcolor % hue sat 1
>> 0 0 1     -270   90   arc % includes a straight line to the initial 
>> point of the arc
>> % x y  r    ang1 ang2       % from, to angles
>> closepath                   % and a curved section to the end of the arc.
>> pop
>> } def
>> 
>> gsave
>> 267 400 translate             % middle, landscape
>> 1 1 N                         % Set up the for operator to iterate
>> {
>> gsave                       % Enclose the ‘‘circle’’ operation in a 
>> gsave - grestore
>> %  radius must shrink as sat grows for proper shading..
>> dup N exch sub N div dup 3 mul size
>> 1 exch sub
>> red circle
>> gsave fill grestore        % Save the circle path for use after the fill.
>> grestore                    % Get out of the coordinate system left by circle.
>> } for                        % Close the procedure body and execute the 
>> for operator.
>> grestore
>> 
>> gsave
>> 400 200 translate             % middle, landscape
>> 1 1 N                         % Set up the for operator to iterate
>> {
>> gsave                       % Enclose the ‘‘circle’’ operation in a 
>> gsave - grestore
>> %  radius must shrink as sat grows for proper shading..
>> dup N exch sub N div dup 3 mul size
>> 1 exch sub
>> green circle
>> gsave fill grestore        % Save the circle path for use after the fill.
>> grestore                    % Get out of the coordinate system left by circle.
>> } for                        % Close the procedure body and execute the 
>> for operator.
>> grestore
>> 
>> gsave
>> 533 400 translate             % middle, landscape
>> 1 1 N                         % Set up the for operator to iterate
>> {
>> gsave                       % Enclose the ‘‘circle’’ operation in a 
>> gsave - grestore
>> %  radius must shrink as sat grows for proper shading..
>> dup N exch sub N div dup 3 mul size
>> 1 exch sub
>> blue circle
>> gsave fill grestore        % Save the circle path for use after the fill.
>> grestore                    % Get out of the coordinate system left by circle.
>> } for                        % Close the procedure body and execute the 
>> for operator.
>> grestore
>> gsave
>> /Helvetica findfont
>> 24 scalefont setfont
>> 320 580 moveto
>> ( Linear gradient) show
>> grestore
>> showpage
> 
> The simplest algorithm for the "three-circle-overlap" I know goes 
> something like this:
> 
> Given three overlapping circles A, B, and C:
> Do A; fill red
> Do B; gsave; clip; fill green
> Do A; Fill yellow
> grestore
> Do C; clip; Fill blue
> Do A; fill magenta
> Do B; clip; fill cyan
> Do A; fill white
> 
> This is for the classic red-green-blue circles (yielding overlaps of c, 
> m, y, and white); I sometimes present this as an extra-credit problem 
> in the PostScript Foundations class.
> 
> Here's a PostScript implementation:
> 
> % ========= cut here ========
> /CircleA
> { 300 500 100 0 360 arc } bind def
> 
> /CircleB
> { 375 425 100 0 360 arc } bind def
> 
> /CircleC
> { 225 425 100 0 360 arc } bind def
> 
> CircleA
> 1 0 0 setrgbcolor fill
> 
> gsave
> CircleB
> clip
> 0 1 0 setrgbcolor
> fill
> 
> CircleA
> 1 1 0 setrgbcolor
> fill
> grestore
> 
> CircleC
> clip
> 0 0 1 setrgbcolor
> fill
> 
> CircleA
> 1 0 1 setrgbcolor
> fill
> 
> CircleB
> clip
> 0 1 1 setrgbcolor
> fill
> 
> CircleA
> 1 setgray
> fill
> 
> showpage
> % ============ cut here ============
> 
> You can pretty easily adapt this for your quite nice-looking radial gradients.
> 
> - John
> 
> P.S. If you like gradients, you might want to look into PostScript's 
> smooth shading. The Acumen Journal has a brief introduction to the 
> topic way back in issue #1, November 2000. The Journal is free for the 
> downloading at www.acumentraining.com/acumenjournal.html.
> 
> - John


The Smooth Shading version of this was calling to me; I had to do it. Had to!

% =========== Snip =========

/FcnDict 	<<
	/FunctionType  2	
	/Domain	[ 0 1 ]	
	/Range	[ 0 1 0 1 0 1 ]	
	/C0		[ 1 0 0 ]	
	/C1		[ 1 1 1 ]
	/N		1.5
>> def

/DoShfill	% << shade dict >> [ r g b ]	=> ---
{
	FcnDict /C0 3 -1 roll put
	shfill
} bind def

/CircleA
{ 300 500 100 0 360 arc } bind def

/CircleAShadingDict	<<
	/ShadingType	3
	/ColorSpace	[ /DeviceRGB ]
	/Coords		[ 300 500 0 300 500 100 ]
	/Function	FcnDict
>> def

/CircleB
{ 375 425 100 0 360 arc } bind def

/CircleBShadingDict	<<
	/ShadingType	3
	/ColorSpace	[ /DeviceRGB ]
	/Coords		[ 375 425 0 375 425 100 ]
	/Function	FcnDict
>> def

/CircleC
{ 225 425 100 0 360 arc } bind def

/CircleCShadingDict	<<
	/ShadingType	3
	/ColorSpace	[ /DeviceRGB ]
	/Coords		[ 225 425 0 225 425 100 ]
	/Function	FcnDict
>> def

CircleAShadingDict [ 1 0 0 ] DoShfill

gsave
CircleB
clip newpath
CircleBShadingDict [ 0 1 0 ] DoShfill

CircleAShadingDict [ 1 1 0 ] DoShfill
grestore

CircleC
clip newpath
CircleCShadingDict [ 0 0 1 ] DoShfill

CircleAShadingDict [ 1 0 1 ] DoShfill

CircleB
clip newpath
CircleBShadingDict [ 0 1 1 ] DoShfill

CircleAShadingDict [ 1 1 1 ] DoShfill

showpage

% =========== Snip =========

This can probably be streamlined some.

- J

-- 
========
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 | Next — Previous in thread | Find similar | Unroll thread


Thread

merging colors.. Robert Baer <robertbaer@localnet.com> - 2013-03-31 19:19 -0800
  Re: merging colors.. luser- -droog <mijoryx@yahoo.com> - 2013-03-31 23:18 -0700
    Re: merging colors.. luser- -droog <mijoryx@yahoo.com> - 2013-03-31 23:24 -0700
    Re: merging colors.. Robert Baer <robertbaer@localnet.com> - 2013-04-01 20:48 -0800
      Re: merging colors.. luser- -droog <mijoryx@yahoo.com> - 2013-04-02 21:06 -0700
  Re: merging colors.. gernot.hoffmann@hs-emden-leer.de - 2013-04-01 02:04 -0700
    Re: merging colors.. Don Lancaster <don@tinaja.com> - 2013-04-02 17:03 -0700
  Re: merging colors.. John Deubert <john@acumentraining.com> - 2013-04-01 07:09 -0700
    Re: merging colors.. John Deubert <john@acumentraining.com> - 2013-04-01 09:27 -0700

csiph-web