Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1359 > unrolled thread
| Started by | Robert Baer <robertbaer@localnet.com> |
|---|---|
| First post | 2013-03-31 19:19 -0800 |
| Last post | 2013-04-01 09:27 -0700 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.postscript
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
| From | Robert Baer <robertbaer@localnet.com> |
|---|---|
| Date | 2013-03-31 19:19 -0800 |
| Subject | merging colors.. |
| Message-ID | <c866t.310117$PC7.285767@newsfe03.iad> |
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
[toc] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-03-31 23:18 -0700 |
| Message-ID | <8b07620d-f047-4c58-85c0-dcf05bb7c2c7@googlegroups.com> |
| In reply to | #1359 |
On Sunday, March 31, 2013 9:18:49 PM UTC-5, Robert Baer wrote: > 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? > You'll have to define the separate regions separately. Postscript doesn't have any sort of blending or rasterops. But remember there's `clip` and `eoclip` which are very powerful. Btw, I wrote some code for gradients you might find useful. http://stackoverflow.com/a/7900346/733077
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-03-31 23:24 -0700 |
| Message-ID | <18987828-0fba-40cf-845e-9d7036fb9c53@googlegroups.com> |
| In reply to | #1360 |
On Monday, April 1, 2013 1:18:55 AM UTC-5, luser- -droog wrote: > On Sunday, March 31, 2013 9:18:49 PM UTC-5, Robert Baer wrote: > > > 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? > > > You'll have to define the separate regions separately. > Postscript doesn't have any sort of blending or rasterops. > But remember there's `clip` and `eoclip` which are very powerful. > Thought it through just after posting... Yes! Construct the path for one circle, clip. Construct the path for the second circle, clip. All further drawing will be bounded by the intersection of these paths. Even simpler, just clip to the *other* circles. The one you're actually drawing is already "within its own bounds", right?
[toc] | [prev] | [next] | [standalone]
| From | Robert Baer <robertbaer@localnet.com> |
|---|---|
| Date | 2013-04-01 20:48 -0800 |
| Message-ID | <Mxs6t.2679$qE5.1531@newsfe01.iad> |
| In reply to | #1360 |
luser- -droog wrote: > On Sunday, March 31, 2013 9:18:49 PM UTC-5, Robert Baer wrote: >> 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? >> > > > You'll have to define the separate regions separately. > Postscript doesn't have any sort of blending or rasterops. > But remember there's `clip` and `eoclip` which are very powerful. > > Btw, I wrote some code for gradients you might find useful. > http://stackoverflow.com/a/7900346/733077 Verrrry nice! Now have a lot of reading to do. Thanks!
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-04-02 21:06 -0700 |
| Message-ID | <5103784e-71fd-4073-8ed3-97fa3c847289@googlegroups.com> |
| In reply to | #1365 |
On Monday, April 1, 2013 10:47:58 PM UTC-5, Robert Baer wrote: > luser- -droog wrote: > > > > Btw, I wrote some code for gradients you might find useful. > > > http://stackoverflow.com/a/7900346/733077 > > Verrrry nice! > > Now have a lot of reading to do. > > Thanks! I'm assuming this is a "blanket" thank you to Gernot and John for contributing very nice code rather than links. :) And you're welcome, I'm sure. We'd love to see the result when it's finished (or help more if you need it).
[toc] | [prev] | [next] | [standalone]
| From | gernot.hoffmann@hs-emden-leer.de |
|---|---|
| Date | 2013-04-01 02:04 -0700 |
| Message-ID | <aa53244c-2124-4b29-b5ed-192db33c4c6f@googlegroups.com> |
| In reply to | #1359 |
Am Montag, 1. April 2013 04:18:49 UTC+2 schrieb Robert Baer:
> 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
Some examples:
http://docs-hoffmann.de/ciegraph17052004.pdf
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 567 567
%%Creator: Gernot Hoffmann
%%Title: CMY-Circles
%%CreationDate: June 07 / 2006
/mm {2.834646 mul} def
/sc 80 mm def
/x0 100 mm def
/y0 100 mm def
/BBox
{ 0 0 567 567 rectstroke
} def
% BBox
/E 0.5 def
/R 0.7 def
/ac 180 def
/am 300 def
/ay 60 def
/xc ac cos E mul def
/yc ac sin E mul def
/xm am cos E mul def
/ym am sin E mul def
/xy ay cos E mul def
/yy ay sin E mul def
x0 y0 translate
sc sc scale
gsave
1 0 0 0 setcmykcolor
xc yc R 0 360 arc fill
0 1 0 0 setcmykcolor
xm ym R 0 360 arc fill
0 0 1 0 setcmykcolor
xy yy R 0 360 arc fill
grestore
gsave
newpath xc yc R 0 360 arc clip
newpath xm ym R 0 360 arc clip
1 1 0 0 setcmykcolor
xc yc R 0 360 arc fill
grestore
gsave
newpath xm ym R 0 360 arc clip
newpath xy yy R 0 360 arc clip
0 1 1 0 setcmykcolor
xm ym R 0 360 arc fill
grestore
gsave
newpath xy yy R 0 360 arc clip
newpath xc yc R 0 360 arc clip
1 0 1 0 setcmykcolor
xy yy R 0 360 arc fill
grestore
gsave
newpath xc yc R 0 360 arc clip
newpath xm ym R 0 360 arc clip
newpath xy yy R 0 360 arc clip
1 1 1 0 setcmykcolor
xc yc R 0 360 arc fill
showpage
---------------------
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 567 567
%%Creator: Gernot Hoffmann
%%Title: RGB-Circles
%%CreationDate: June 07 / 2006
/mm {2.834646 mul} def
/sc 80 mm def
/x0 100 mm def
/y0 100 mm def /BBox
{ 0 0 567 567 rectstroke
} def
% BBox
/E 0.5 def
/R 0.7 def
/ar 0 def
/ag 120 def
/ab 240 def
/xr ar cos E mul def
/yr ar sin E mul def
/xg ag cos E mul def
/yg ag sin E mul def
/xb ab cos E mul def
/yb ab sin E mul def
x0 y0 translate
sc sc scale
gsave
1 0 0 setrgbcolor
xr yr R 0 360 arc fill
0 1 0 setrgbcolor
xg yg R 0 360 arc fill
0 0 1 setrgbcolor
xb yb R 0 360 arc fill
grestore
gsave
newpath xr yr R 0 360 arc clip
newpath xg yg R 0 360 arc clip
1 1 0 setrgbcolor
xr yr R 0 360 arc fill
grestore
gsave
newpath xg yg R 0 360 arc clip
newpath xb yb R 0 360 arc clip
0 1 1 setrgbcolor
xg yg R 0 360 arc fill
grestore
gsave
newpath xb yb R 0 360 arc clip
newpath xr yr R 0 360 arc clip
1 0 1 setrgbcolor
xb yb R 0 360 arc fill
grestore
gsave
newpath xr yr R 0 360 arc clip
newpath xg yg R 0 360 arc clip
newpath xb yb R 0 360 arc clip
1 1 1 setrgbcolor
xr yr R 0 360 arc fill
showpage
[toc] | [prev] | [next] | [standalone]
| From | Don Lancaster <don@tinaja.com> |
|---|---|
| Date | 2013-04-02 17:03 -0700 |
| Message-ID | <as19uiFet9hU1@mid.individual.net> |
| In reply to | #1362 |
On 4/1/2013 2:04 AM, gernot.hoffmann@hs-emden-leer.de wrote:
> Am Montag, 1. April 2013 04:18:49 UTC+2 schrieb Robert Baer:
>> 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
>
> Some examples:
>
> http://docs-hoffmann.de/ciegraph17052004.pdf
>
> %!PS-Adobe-3.0 EPSF-3.0
> %%BoundingBox: 0 0 567 567
> %%Creator: Gernot Hoffmann
> %%Title: CMY-Circles
> %%CreationDate: June 07 / 2006
>
> /mm {2.834646 mul} def
>
> /sc 80 mm def
> /x0 100 mm def
> /y0 100 mm def
>
> /BBox
> { 0 0 567 567 rectstroke
> } def
>
> % BBox
>
> /E 0.5 def
> /R 0.7 def
>
> /ac 180 def
> /am 300 def
> /ay 60 def
>
> /xc ac cos E mul def
> /yc ac sin E mul def
> /xm am cos E mul def
> /ym am sin E mul def
>
> /xy ay cos E mul def
> /yy ay sin E mul def
>
> x0 y0 translate
> sc sc scale
>
> gsave
> 1 0 0 0 setcmykcolor
> xc yc R 0 360 arc fill
>
> 0 1 0 0 setcmykcolor
> xm ym R 0 360 arc fill
>
> 0 0 1 0 setcmykcolor
> xy yy R 0 360 arc fill
>
> grestore
> gsave
> newpath xc yc R 0 360 arc clip
> newpath xm ym R 0 360 arc clip
>
> 1 1 0 0 setcmykcolor
> xc yc R 0 360 arc fill
>
> grestore
> gsave
> newpath xm ym R 0 360 arc clip
> newpath xy yy R 0 360 arc clip
>
> 0 1 1 0 setcmykcolor
> xm ym R 0 360 arc fill
>
> grestore
> gsave
> newpath xy yy R 0 360 arc clip
> newpath xc yc R 0 360 arc clip
>
> 1 0 1 0 setcmykcolor
> xy yy R 0 360 arc fill
>
> grestore
> gsave
> newpath xc yc R 0 360 arc clip
> newpath xm ym R 0 360 arc clip
> newpath xy yy R 0 360 arc clip
>
> 1 1 1 0 setcmykcolor
> xc yc R 0 360 arc fill
>
> showpage
>
> ---------------------
>
> %!PS-Adobe-3.0 EPSF-3.0
> %%BoundingBox: 0 0 567 567
> %%Creator: Gernot Hoffmann
> %%Title: RGB-Circles
> %%CreationDate: June 07 / 2006
>
> /mm {2.834646 mul} def
>
> /sc 80 mm def
> /x0 100 mm def
> /y0 100 mm def /BBox
> { 0 0 567 567 rectstroke
> } def
>
> % BBox
>
> /E 0.5 def
> /R 0.7 def
>
> /ar 0 def
> /ag 120 def
> /ab 240 def
>
> /xr ar cos E mul def
> /yr ar sin E mul def
> /xg ag cos E mul def
> /yg ag sin E mul def
>
> /xb ab cos E mul def
> /yb ab sin E mul def
>
> x0 y0 translate
> sc sc scale
>
> gsave
> 1 0 0 setrgbcolor
> xr yr R 0 360 arc fill
>
> 0 1 0 setrgbcolor
> xg yg R 0 360 arc fill
>
> 0 0 1 setrgbcolor
> xb yb R 0 360 arc fill
>
> grestore
> gsave
> newpath xr yr R 0 360 arc clip
> newpath xg yg R 0 360 arc clip
>
> 1 1 0 setrgbcolor
> xr yr R 0 360 arc fill
>
> grestore
> gsave
> newpath xg yg R 0 360 arc clip
> newpath xb yb R 0 360 arc clip
>
> 0 1 1 setrgbcolor
> xg yg R 0 360 arc fill
>
> grestore
> gsave
> newpath xb yb R 0 360 arc clip
> newpath xr yr R 0 360 arc clip
>
> 1 0 1 setrgbcolor
> xb yb R 0 360 arc fill
>
> grestore
> gsave
> newpath xr yr R 0 360 arc clip
> newpath xg yg R 0 360 arc clip
> newpath xb yb R 0 360 arc clip
>
> 1 1 1 setrgbcolor
> xr yr R 0 360 arc fill
>
> showpage
>
< http://www.tinaja.com/glib/pstrans2.pdf > , of course.
Otherwise, you have to work with the HSB color space and make sure you
do not go the wrong way around the circle.
As in < http://www.tinaja.com/glib/postproc.pdf >
--
Many thanks,
Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: don@tinaja.com
Please visit my GURU's LAIR web site at http://www.tinaja.com
[toc] | [prev] | [next] | [standalone]
| From | John Deubert <john@acumentraining.com> |
|---|---|
| Date | 2013-04-01 07:09 -0700 |
| Message-ID | <2013040107092515878-john@acumentrainingcom> |
| In reply to | #1359 |
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
[toc] | [prev] | [next] | [standalone]
| From | John Deubert <john@acumentraining.com> |
|---|---|
| Date | 2013-04-01 09:27 -0700 |
| Message-ID | <2013040109270998040-john@acumentrainingcom> |
| In reply to | #1363 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web