%
% This file is a product of Sun Microsystems, Inc. and is provided for
% unrestricted use provided that this legend is included on all tape
% media and as a part of the software program in whole or part.  Users
% may copy or modify this file without charge, but are not authorized to
% license or distribute it to anyone else except as part of a product
% or program developed by the user.
%
% THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
% WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
% PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
%
% This file is provided with no support and without any obligation on the
% part of Sun Microsystems, Inc. to assist in its use, correction,
% modification or enhancement.
%
% SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
% INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
% OR ANY PART THEREOF.
%
% In no event will Sun Microsystems, Inc. be liable for any lost revenue
% or profits or other special, indirect and consequential damages, even
% if Sun has been advised of the possibility of such damages.
%
% Sun Microsystems, Inc.
% 2550 Garcia Avenue
% Mountain View, California  94043
%
%
% @(#)poly 23.2 90/06/19
%
% Copyright (c) 1989 by Sun Microsystems, Inc.
%

/PolyCanvas ClassCanvas dictbegin
    /animator null def
    /width 100 def
    /height 100 def
    /lines 50 def
dictend

classbegin

    /newinit {
	/newinit super send
	/nouse /nouse /setcursor self send
    } def

    /path {	% x y w h => -
	/height exch def
	/width exch def
	width height
	rectpath
    } def

    /PaintPoly {
	10 dict begin
	{
	    mark
	    0 fillcanvas
	    /points 3 2 random mul add round cvi def
	    /pointsX2 points 2 mul def
	    points {
		width random mul
		height random mul
	    } repeat			% x2 y2 x1 y1 
	    points -1 1 {
		2 mul /i exch def
		i -1 roll dup
		width random mul exch sub lines div /inc exch def
		i 1 roll
		inc pointsX2 1 add 1 roll
		/i i 1 sub def
		i -1 roll dup
		height random mul exch sub lines div /inc exch def
		i 1 roll
		inc pointsX2 1 add 1 roll
	    } for			% x2inc y2inc x1inc y1inc x2 y2 x1 y1
	    1 setgray
	    /hue random def
	    /hueinc random random sub lines div def
	    /sat 0.3 0.7 random mul add def
	    lines {
		ColorDisplay? {
		    hue sat 1 sethsbcolor
		    /hue hue hueinc add def
		    hue 1.0 gt {
			/hue 0 def
		    } if
		    hue 0 lt {
			/hue 1.0 def
		    } if
		} if
		pointsX2 copy
		newpath
		moveto
		points 1 sub {
		    lineto
		} repeat
		closepath stroke
		0.0015 sleep pause
		% Add the increments to the points
		0 1 pointsX2 1 sub {
		    pointsX2 add index add
		    pointsX2 1 roll
		} for
	    } repeat
	    0.04 sleep pause
	    cleartomark
	} loop
	end
    } def

    /PaintCanvas {
	/killanimator self send
	0 fillcanvas
	animator null eq {
	    /animator { clear PaintPoly } refork
	    animator /ProcessName (Poly Painter) put 
	} if
    } def

    /PointButtonHandler { % event => -
	pop /destroy /canvas self send send
    } def

    /MakeInterests {
	/MakeInterests super send
	PointButton /PointButtonHandler BuildCanvasSend
	/DownTransition /canvas self send soften eventmgrinterest
    } def

    /killanimator {
	animator null ne {
	    animator
		/animator null store
	    killprocess
	} if
    } def

    /destroy {
	/killanimator self send
	/destroy super send
    } def

    /obsolete {
	/killanimator self send
	/obsolete super send
    } def

classend def


/poly framebuffer /new PolyCanvas send def
poly /Transparent false put

gsave 
    framebuffer setcanvas
    clippath pathbbox
grestore

/reshape poly send
/activate poly send
/map poly send pause

newprocessgroup
currentfile closefile

