home *** CD-ROM | disk | FTP | other *** search
- /*
-
- starfld.cwx
-
- This script draws a starfield on a black background the size of the output area.
- If the background is already there, it just draws the stars.
-
- 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.
-
- */
-
-
-
- /* Get the current output rectangle. */
- output_settings = CwGetAppHandle('output settings')
- field.w = CwGetProperty(output_settings, "output size:width")
- field.h = CwGetProperty(output_settings, "output size:height")
- dim = .1
-
-
- /* See if there's a big back background. If not, create it.*/
- bbb = CwGetHandleFromObjectName(CwGetCurrentView(), 'black background')
- if \CwIsHandleValid(bbb) then do
- f = CwCreateEffect( 'Rectangle', 'Solid Color' )
- s = CwGetTool(f);
- call CwSetProperty s, 'Color', 'black'
- call CwSetProperty f, 'Name', 'black background'
- call CwSetPosition f, field.w/2, field.h/2, field.w, field.h, 0, 0
- end
-
-
- /* Draw 50 stars. */
- do i = 1 to 50
- dim = rand(.05, .2)
- x = rand(dim/2, field.w - dim/2)
- y = rand(dim/2, field.h - dim/2)
- call star x, y, dim
- end
-
- exit
-
-
-
-
- /* Return an random number between FROM and TO. (REXX's random function is gross.) */
- rand:procedure
- arg from, to;
-
- r = random(0, 999) / 1000
- return (to - from) * r + from
-
-
-
-
- /* A Star is Born. */
- star:procedure
- parse arg x, y, dim
-
- star = CwCreateEffect( 'Ellipse Fade', 'Solid Color' )
-
- solid = CwGetTool(star)
- call CwSetProperty solid, 'Color', 'white'
-
- ell = CwGetRegion(star)
- call CwSetProperty ell, 'Density', 35
-
- call CwSetPosition star, x, y, dim, dim, 0, 0
- return;
-
-
-