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


Groups > comp.lang.postscript > #1363

Re: merging colors..

X-Received by 10.224.207.2 with SMTP id fw2mr5768026qab.6.1364825365437; Mon, 01 Apr 2013 07:09:25 -0700 (PDT)
Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!ca1no19694739qab.0!news-out.google.com!v17ni15796qad.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 09:09:24 -0500
From John Deubert <john@acumentraining.com>
Organization Acumen Training
Newsgroups comp.lang.postscript
Date Mon, 1 Apr 2013 07:09:25 -0700
Message-ID <2013040107092515878-john@acumentrainingcom> (permalink)
References <c866t.310117$PC7.285767@newsfe03.iad>
MIME-Version 1.0
Subject Re: merging colors..
User-Agent Unison/2.1.10
Lines 173
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-dLSsK3PZJhUU1ysesfYhJfD7dKO7Mt1LxwFTzXtIXCs1HsOKMIoeUYoMW3MqCuysmm7nZMAfRKUXxrQ!LZ0VD2wnbQuZSt/+rsm6UU4Y+GZlfndDbZ20Thj5VeYVa2iWS+LWctoLo0Qb9aZLXwm65AgS
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 5682
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Received-Bytes 5986
Xref csiph.com comp.lang.postscript:1363

Show key headers only | View raw


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



-- 
========
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 | Next 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