/*

  abstract.cwx

  This is the paint-and-dynamite abstract art script.  It creates a
  random number of objects in the current view.

  Copyright 1997 by TrueSpectra Inc.

  This code is provided purely for demonstration purposes and is not
  supported or under warranty.  Feel free to modify and examine this
  example script for your own purposes.
*/


/* Load utility functions. */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs



/* A long string, fragments of which go into headline text objects.*/
wurds = "On the road, ZIPPY is a pinhead without a purpose, but never" ,
"Why do you say without a point?" ,
"Yow!  We're going to a new disco!" ,
"Is it because of your plans that you say we're going to a new disco?" ,
"Yow!  Are you the self-frying president?" ,
"Maybe your life have something to do with this." ,
"SHHHH!!  I hear SIX TATTOOED TRUCK-DRIVERS tossing ENGINE BLOCKS" ,
"into empty OIL DRUMS.." ,
"What makes you believe into empty oil drums?" ,
"I HAVE to buy a new ``DODGE MISER'' and two dozen JORDACHE" ,
"JEANS because my viewscreen is ``USER-FRIENDLY''!!" ,
"Is it because your viewscreen is user friendly'' that you came to me?" ,
"I haven't been married in over six years, but we had sexual counseling" ,
"every day from Oral Roberts!!" ,
"Earlier you said your viewscreen is user friendly''?" ,
"Spreading peanut butter reminds me of opera!!  I wonder why?" ,
"Can you elaborate on that?" ,
"Yow!  I threw up on my window!" ,
"Is it because of the people you hang around with that you are going" ,
"through all this?" ,
"If Robert Di Niro assassinates Walter Slezak, will" ,
"Jodie Foster marry Bonzo??" ,
"Is it because of problems at school that you say jodie foster marry"

lwurds = 199


/* Zippy the Pinhead quotes--these get put into block text objects.*/

line.1 = "My pants just went to high school in the Carlsbad Caverns!!!"
line.2 = "I represent a sardine!!"
line.3 = "Are you mentally here at Pizza Hut??"
line.4 = "Civilization is fun!  Anyway, it keeps me busy!!"
line.5 = "Now I'm concentrating on a specific tank battle toward" ,
	"the end of World War II!"
line.6 = "Edwin Meese made me wear CORDOVANS!!"
line.7 = "I just forgot my whole philosophy of life!!!"
line.8 = "I'm reporting for duty as a modern person.  I want to do the Latin Hustle now!"
line.9 = "Are you mentally here at Pizza Hut??"
line.10 = "But was he mature enough last night at the lesbian masquerade?"
line.11 = "Everybody gets free BORSCHT!"
line.12 = "Where's the Coke machine?  Tell me a joke!!"
line.13 = "..  I wonder if I ought to tell them about my PREVIOUS LIFE" ,
	"as a COMPLETE STRANGER?"
line.14 = "A dwarf is passing out somewhere in Detroit!"
line.15 = "I feel partially hydrogenated!"
line.16 = "A shapely CATHOLIC SCHOOLGIRL is FIDGETING inside my costume.."
line.17 = "Content:  80% POLYESTER, 20% DACRON..  The waitress's" ,
	"UNIFORM sheds TARTAR SAUCE like an 8'' by 10'' GLOSSY.."
line.18 = "Can you MAIL a BEAN CAKE?"
line.19 = "It's the RINSE CYCLE!!  They've ALL IGNORED the RINSE CYCLE!!"
line.20 = "As President I have to go vacuum my coin collection!"
line.21 = "I'd like some JUNK FOOD...  and then I want to be ALONE --"
line.22 = "I want to kill everyone here with a cute colorful Hydrogen Bomb!!"
line.23 = "The FALAFEL SANDWICH lands on my HEAD and I become a VEGETARIAN..."
line.24 = "Can I have an IMPULSE ITEM instead?"
line.25 = "Do you think the ``Monkees'' should get gas on odd or even days?"
line.26 = "I want you to MEMORIZE the collected poems of" ,
	"EDNA ST VINCENT MILLAY.. BACKWARDS!!"
nlines = 26


/* Those bitmap formats I can be bothered with.*/
bmext.1 = 'gif'
bmext.2 = 'jpg'
bmext.3 = 'tiff'
bmext.4 = 'bmp'
nbmext = 4


nbitmaps = 0

ah = CwGetAppHandle('preferences')
searchpath = CwGetProperty(ah, "Bitmap Path")

do while length(searchpath) > 0
	n = pos(';', searchpath, 1)
        if n = 0 then
		n = length(searchpath)+1
	path = substr(searchpath, 1, n-1)
	searchpath = substr(searchpath, n+1)
	do c = 1 to nbmext
		call getfiles path, bmext.c
		end
	end


/* Create the objects and exit.*/
do random(1,100)
	call randobj
	end
exit




/* Get bitmap files. */
getfiles:procedure expose bitmaps. nbitmaps
parse arg path, ext

if substr(path, length(path)) \= "\" then
	path = path || "\"

rc = SysFileTree(path||'*.'||ext, 'files', 'FSO')

if rc = 2 then do
	say "REXX error."
	exit
	end

do i = 1 to files.0
	nbitmaps = nbitmaps + 1
	bitmaps.nbitmaps = files.i
	end
return



/* Create a random object. */
randobj:procedure expose wurds lwurds line. nlines bitmaps. nbitmaps

ah=CwGetAppHandle('output settings')
maxwidth=CwGetProperty(ah, 'output size:width')
maxheight=CwGetProperty(ah, 'output size:height')

mw=maxwidth/2
mh=maxheight/2
mx = maxwidth
my = maxheight

/* Need these to generate types. */
region.1.name = "Custom Region";
region.2.name = "User Draw";
region.3.name = "Ramp";
region.4.name = "Ellipse Fade";
region.5.name = "Headline Text";
region.6.name = "Block Text";
region.7.name = "Rectangle";
region.8.name = "Ellipse";
region.9.name = "Shape";
nregions = 9;

tool.1.name = "Custom Tool";
tool.2.name = "Bitmap";
tool.3.name = "Solid Color";
tool.4.name = "Wave";
tool.5.name = "Lens";
tool.6.name = "Emboss";
tool.7.name = "Contrast & Brightness";
tool.8.name = "Greyscale";
tool.9.name = "Color Fade";
tool.10.name = "Button";
tool.11.name = "Noise";
tool.12.name = "Pixelate";
tool.13.name = "Blur";
tool.14.name = "Sharpen";
ntools = 14;

/* Pick tools.  For the moment, don't get custom tools or regions. */
t=random(2,ntools)
r=random(3,nregions)

x = rand(0, mx)
y = rand(0, my)
w = rand(.01, mw)
h = rand(.01, mh)
rot = rand(0, 360)
shear = rand(0, 80)

o = CwCreateEffect(region.r.name, tool.t.name)
call CwSetPosition o, x, y, w, h, rot, shear

if r = 5 then
	call word o
else if r = 6 then
	call sentence o

if t = 2 then
	call bitmap o

call Colors o

return o




/* My random number generator. */

rand:procedure		
arg from, to;

r = random(0, 999) / 1000
return (to - from) * r + from



/* Set the text of a block-text object. */

sentence:procedure expose line. nlines
parse arg handle

n = random(1, 26)
text = line.n
call CwSetProperty CwGetRegion(handle), "Caption", text
return




/* Set the text of a headline-text object. */

word:procedure expose wurds lwurds
parse arg handle

p = random(1,lwurds)
n = random(1, 5)
text = subword(wurds, p, n)
call CwSetProperty CwGetRegion(handle), "Caption", text
return




/* Randomly set the Colors of the given parameter. */

Colors:procedure
parse arg object

tool = CwGetTool(object)

/* See if it has Color. */
if CwHasProperty(tool, "Color") then do
	call CwSetProperty tool, "Color", randColor()
	end

/* See if it's a Color-fade.*/
else if CwHasProperty(tool, "Top-left:HSV Color") then do
	call CwSetProperty tool, "Top-Left:HSV Color", randColor()
	call CwSetProperty tool, "Top-Right:HSV Color", randColor()
	call CwSetProperty tool, "Bottom-Left:HSV Color", randColor()
	call CwSetProperty tool, "Bottom-Right:HSV Color", randColor()
	end
return



/* Return a random Color. */

randColor:procedure

r=random(1,255)
g=random(1,255)
b=random(1,255)

return "("||r||","||g||","||b||")"




/* Randomly assign a bitmap value to the object. */
bitmap:procedure expose bitmaps. nbitmaps
parse arg object

if nbitmaps > 0 then do
	tool = CwGetTool(object)
	bm = random(1, nbitmaps)
	bmn = bitmaps.bm
	
	call CwSetProperty tool, 'Image', bmn
	end
return
