Thread View: comp.lang.postscript
2 messages
2 total messages
Started by Nigel O'Brian
Tue, 08 Sep 1992 05:10
graduated triangle fills?
Author: Nigel O'Brian
Date: Tue, 08 Sep 1992 05:10
Date: Tue, 08 Sep 1992 05:10
22 lines
1375 bytes
1375 bytes
This might be a bit optimistic, but does anyone have a routine to do a graduated grayscale fill inside a triangular path? Something like x1 y1 x2 y2 x3 y3 gray1 gray2 gray3 gradfill producing a triangle with specified vertices, and a more or less linearly varying gray taking the specified values at the vertices. I want it for 3D shading. Something recursive should work -- maybe generating 4 invocations corresponding to the subdivision of the triangle given by joining mid-points of sides. Depth can be controlled by maximum variation of grays at the vertices. Perhaps such a routine would be of general interest? -- ================================================================= Nigel O'Brian obrian_n@maths.su.oz.au School of Mathematics nigel@frog.maths.su.oz University of Sydney Ph: (02)-692-4083 Sydney NSW 2006, Australia FAX: (02)-692-4534
Re: graduated triangle fills?
Author: Ross Cunniff
Date: Mon, 14 Sep 1992 17:20
Date: Mon, 14 Sep 1992 17:20
78 lines
3100 bytes
3100 bytes
nigel@maths.su.oz.au (Nigel O'Brian) writes:
>This might be a bit optimistic, but does anyone have a routine
>to do a graduated grayscale fill inside a triangular path?
>Something like
>
>x1 y1 x2 y2 x3 y3 gray1 gray2 gray3 gradfill
>
>producing a triangle with specified vertices, and a more or less
>linearly varying gray taking the specified values at the vertices.
>I want it for 3D shading. Something recursive should
>work -- maybe generating 4 invocations corresponding to
>the subdivision of the triangle given by joining mid-points of
>sides. Depth can be controlled by maximum variation of grays
>at the vertices. Perhaps such a routine would be of general
>interest?
Ask and you shall receive :-)
---cut here------------cut here---------------cut here----
% Trigrad.ps - fill a triangle with a gradient
% Arguments: x1 y1 gray1 x2 y2 gray2 x3 y3 gray3 trigrad
% Calls itself recursively.
% Ross Cunniff, Hewlett-Packard Graphics Software Lab, cunniff@fc.hp.com
% September 14, 1992
% This parameter defines the maximum gray delta allowed to draw a single
% triangle
/_maxgraydel 1 15 div def
% This is the dictionary used by the procedure
/_tridict 10 dict def
/trigrad { _tridict begin
/gray3 exch def /y3 exch def /x3 exch def
/gray2 exch def /y2 exch def /x2 exch def
/gray1 exch def /y1 exch def /x1 exch def
% Test the size of the triangle
/maxg gray1 gray3 sub dup 0 le { neg } if def
gray1 gray2 sub dup 0 le {neg} if dup maxg gt {/maxg exch def} {pop} ifelse
gray2 gray3 sub dup 0 le {neg} if dup maxg gt {/maxg exch def} {pop} ifelse
maxg _maxgraydel le {
% Triangle is 'small' - just fill it and return
x1 y1 moveto x2 y2 lineto x3 y3 lineto closepath
gray1 gray2 add gray3 add 3 div setgray
fill
end
} { %else
newpath
% Subdivide into four triangles and recurse
x1 y1 gray1
x1 x2 add 2 div y1 y2 add 2 div gray1 gray2 add 2 div
x1 x3 add 2 div y1 y3 add 2 div gray1 gray3 add 2 div
x1 x2 add 2 div y1 y2 add 2 div gray1 gray2 add 2 div
x2 y2 gray2
x2 x3 add 2 div y2 y3 add 2 div gray2 gray3 add 2 div
x1 x3 add 2 div y1 y3 add 2 div gray1 gray3 add 2 div
x3 x2 add 2 div y3 y2 add 2 div gray3 gray2 add 2 div
x3 y3 gray3
x1 x2 add 2 div y1 y2 add 2 div gray1 gray2 add 2 div
x2 x3 add 2 div y2 y3 add 2 div gray2 gray3 add 2 div
x1 x3 add 2 div y1 y3 add 2 div gray1 gray3 add 2 div
end
% Trade off stack space for VM space...
trigrad
trigrad
trigrad
trigrad
} ifelse
} bind def
---cut here------------cut here---------------cut here----
>Nigel O'Brian
Ross Cunniff
Hewlett-Packard Graphics Software Lab
cunniff@fc.hp.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads