/*
 * $VER: SuperStars 1.0 (7.5.98)
 *
 * Arexx program for the ImageFX image processing system.
 * Written by J.A. Whiting, based HEAVILY on
 * Stars (13.2.98) and ReqDemo (24.9.92) both by Thomas Krehbiel
 *
 * Draws a lot of random stars into the current buffer.
 *
 */

OPTIONS RESULTS

GetMain ; IF result = "" THEN EXIT ; PARSE VAR result name width height depth .

SaveUndo ; Undo Off ; Redraw Off
GetPalette '-1'
PARSE VAR result red green blue

maxstars= width * height
seed=TIME(SECONDS)

minbriter = 64 ; maxbriter = 255
minbriteg = 64 ; maxbriteg = 255
minbriteb = 64 ; maxbriteb = 255

Gadget.1 = 'I/100/16/Stars:/1000'
Gadget.2 = 'I/100/30/Random Seed:/'seed
Gadget.3 = 'X/100/45/Use Seed?/1'
Gadget.4 = 'x/100/60/Grey Only?/1'

ComplexRequest '"SuperStars"' 4 Gadget 350 105
IF rc ~= 0 THEN Exit

IF maxstars > RESULT.1 THEN maxstars = RESULT.1
IF RESULT.3 ~= 0 THEN trash = randu(RESULT.2)
grey = RESULT.4

IF grey ~=0 THEN DO
   Gadget.1 = 'I/100/16/Max:/'maxbriteg
   Gadget.2 = 'I/100/30/Min:/'minbriteg
   ComplexRequest '"Star Brightness"' 2 Gadget 250 75
   IF rc~= 0 THEN EXIT
   IF RESULT.2 > RESULT.1 THEN DO
      trash = RESULT.1 ; RESULT.1 = RESULT.2 ; RESULT.2 = trash
   END
   IF RESULT.1 > 255 THEN RESULT.1 = 255
   IF RESULT.2 > 255 THEN RESULT.2 = 255
   maxbriteg = RESULT.1
   minbriteg = RESULT.2
END

ELSE DO
   Gadget.1 = 'I/100/16/Max Red:/'maxbriter
   Gadget.2 = 'I/100/30/Min Red:/'minbriter
   Gadget.3 = 'I/100/44/Max Grn:/'maxbriteg
   Gadget.4 = 'I/100/58/Min Grn:/'minbriteg
   Gadget.5 = 'I/100/72/Max Blu:/'maxbriteb
   Gadget.6 = 'I/100/86/Min Blu:/'minbriteb
   ComplexRequest '"Colorful Star Brightness"' 6 Gadget 250 135
   IF rc~= 0 THEN EXIT
   IF RESULT.2 > RESULT.1 THEN DO
      trash = RESULT.1 ; RESULT.1 = RESULT.2 ; RESULT.2 = trash
   END
   IF RESULT.4 > RESULT.3 THEN DO
      trash = RESULT.3 ; RESULT.3 = RESULT.4 ; RESULT.4 = trash
   END
   IF RESULT.6 > RESULT.5 THEN DO
      trash = RESULT.5 ; RESULT.5 = RESULT.6 ; RESULT.6 = trash
   END
   IF RESULT.1 > 255 THEN RESULT.1 = 255
   IF RESULT.2 > 255 THEN RESULT.2 = 255
   IF RESULT.3 > 255 THEN RESULT.3 = 255
   IF RESULT.4 > 255 THEN RESULT.4 = 255
   IF RESULT.5 > 255 THEN RESULT.5 = 255
   IF RESULT.6 > 255 THEN RESULT.6 = 255
   maxbriter = RESULT.1 ; minbriter = RESULT.2
   maxbriteg = RESULT.3 ; minbriteg = RESULT.4
   maxbriteb = RESULT.5 ; minbriteb = RESULT.6

END


BeginBar 'SuperStars' maxstars

DO i = 1 TO maxstars

   Bar i
   LockGui
   x = randu() * width
   y = randu() * height
   r = random(minbriter,maxbriter)
   g = random(minbriteg,maxbriteg)
   b = random(minbriteb,maxbriteb)
   IF grey ~=0 THEN SetPalette '-1' g g g
      ELSE SetPalette '-1' r g b
   Point x y
   UnlockGui Quiet

   END

EndBar

Undo On ; Redraw On ; Redraw
SetPalette '-1' red green blue

EXIT
