toms@NCIFCRF.GOV (05/26/88)
%!
% bez version 2.02 1988 May 26 TDS
%
% AUTHOR:
% Tom Schneider
% Frederick, Maryland
% toms@ncifcrf.gov
%
% LANGUAGE: PostScript
%
% DESCRIPTION:
% Bez creates a set of colorful Bezier curves using the
% curveto function in PostScript. Each of the 4 coordinates
% that define each Bezier curve has its own velocity that is
% initialized with random numbers. The 4 coordinates bounce
% around within the field of view, and their velocities
% are altered slightly at random. The color of each
% curve is also altered slightly from the previous curve.
%
% USE:
% Under NeWS 1.1 run with the command
% psview bez
% Everytime you iconize and re-open the window, you will get
% a different pattern, since the random numbers change...
% Note: you can change the size of the window to be sure to get
% the black box which outlines the bounds of the coordinates.
% (The curve goes slightly outside the box sometimes.)
%
% BUGS:
% A proper window rather than psview would be nice, in which one
% could toggle the various constants and redraw with a single touch.
%
% Bez runs beautifully on my Sun 3/260C, but it doesn't
% work on a Sun 3/50. The first curve appears in black and then it
% is overwritten with white, so almost nothing shows up. The problem
% is not corrected by using 2 setlinequality, by keeping the hue fixed
% or by setting the width to 2. So much for portability.
% If you figure it out, let me know please.
%
% It would make a nice lockscreen, if lockscreen existed under NeWS...
%
% The placement of the image doesn't work quite right in psview.
%
% CONSTANTS for you to play with:
/acc 0.5 def % acceleration of velocity changes (0.5 is nice)
% try 0 with numbercurves at 1000!
/huestep 0.01 def % rate of hue change (0.01 is nice)
/maxbound 750 def % maximum x and y axis (750 is nice)
/numbercurves 500 def % number of curves to put down (500 is nice)
/speed 2 def % velocity increments (2 is nice)
/width 1 def % line width, wider is slower, but prettier (1 is nice)
% other constants
/hue random def % initialize hue
% set up line sizes
1 setlinequality
width setlinewidth
/scran { % chose a random number scaled between 0 and maxbound
random maxbound mul
} def
% define positions
/xp0 scran def
/yp0 scran def
/xp1 scran def
/yp1 scran def
/xp2 scran def
/yp2 scran def
/xp3 scran def
/yp3 scran def
/veran { % chose a random velocity between -speed and speed
random 2 mul 1 sub speed mul
} def
% define velocities
/xv0 veran def
/yv0 veran def
/xv1 veran def
/yv1 veran def
/xv2 veran def
/yv2 veran def
/xv3 veran def
/yv3 veran def
/go { % construct a single Bezier curve
% draw the current curve defined by the 4 points
newpath
xp0 yp0 moveto
xp1 yp1
xp2 yp2
xp3 yp3
curveto
stroke
% update positions
/xp0 xp0 xv0 add def
/xp1 xp1 xv1 add def
/xp2 xp2 xv2 add def
/yp3 yp3 yv3 add def
/yp0 yp0 yv0 add def
/yp1 yp1 yv1 add def
/yp2 yp2 yv2 add def
/xp3 xp3 xv3 add def
% make velocities drift randomly!
/xv0 xv0 veran acc mul add def
/xv1 xv1 veran acc mul add def
/xv2 xv2 veran acc mul add def
/xv3 xv3 veran acc mul add def
/yv0 yv0 veran acc mul add def
/yv1 yv1 veran acc mul add def
/yv2 yv2 veran acc mul add def
/yv3 yv3 veran acc mul add def
% reverse velocities at boundries
xp0 maxbound gt {/xv0 0 xv0 sub def} if
xp1 maxbound gt {/xv1 0 xv1 sub def} if
xp2 maxbound gt {/xv2 0 xv2 sub def} if
xp3 maxbound gt {/xv3 0 xv3 sub def} if
yp0 maxbound gt {/yv0 0 yv0 sub def} if
yp1 maxbound gt {/yv1 0 yv1 sub def} if
yp2 maxbound gt {/yv2 0 yv2 sub def} if
yp3 maxbound gt {/yv3 0 yv3 sub def} if
xp0 0 lt {/xv0 0 xv0 sub def} if
xp1 0 lt {/xv1 0 xv1 sub def} if
xp2 0 lt {/xv2 0 xv2 sub def} if
xp3 0 lt {/xv3 0 xv3 sub def} if
yp0 0 lt {/yv0 0 yv0 sub def} if
yp1 0 lt {/yv1 0 yv1 sub def} if
yp2 0 lt {/yv2 0 yv2 sub def} if
yp3 0 lt {/yv3 0 yv3 sub def} if
% change the color
/hue hue huestep add def % modify the hue
hue % this is the hue
1.0 % this is the saturation
1.0 % this is the brightness
sethsbcolor % reset the color
} def
% main calls
erasepage
% draw a curve around the field so that psview
% can figure out where to place the graph
newpath
0 0 moveto
maxbound 0 lineto
maxbound maxbound lineto
0 maxbound lineto
closepath
stroke
% produce the curves
numbercurves{
go
pause
} repeat