home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- * *
- * $VER: Random.pvrx 1.0 (26.Jan.94) *
- * Copyright © 1994 by Stylus, Inc. *
- * Author: Jeff Blume *
- * *
- * This macro clones selected objects and randomly distributes them, *
- * with rotation and scaling. There is a slight bias in distribution *
- * (to the upper-left). This bias is less perceptible as the number of *
- * clones increases. Sixty clones shows little bias; 55 is noticeably *
- * more biased. NOTE: the bias can be flipped on either axis; see the *
- * comments in the RANPOS: routine. *
- * *
- ***************************************************************************/
-
- /*
- call open STDOUT,"RAM:RxOut.txt",W
- call open STDERR,"RAM:RxErr.txt",W
- trace R
- */
-
- options results
-
- /* Lock ProVector - wait if necessary */
- 'Lock Wait'
-
- /* Get selected objs; if none exit; otherwise find center of BBOX */
- 'SelectList Sel'; NumSel = Result
- if NumSel = 0 then call Error "No objects selected!"
- 'SelExtent' Ext
- CX = (Ext.X1 + Ext.X2) / 2
- CY = (Ext.Y1 + Ext.Y2) / 2
-
- call Request
-
- 'PushUndo'
- do j=0 for NumSel
- do i=1 for NumClones
- call RanPos
- 'Clone' Sel.j DX DY; Clone = Result
- if ScaleClones = 1 then do
- call RanScale
- 'Size' Clone (CX+DX) (CY+DY) ScaleFactor ScaleFactor
- end
- if RotClones = 1 then do
- call RanRot
- 'Rotate' Clone (CX+DX) (CY+DY) Degrees
- end
- end
- if DelOrig = 1 then 'Delete' Sel.j
- end
- if ScaleClones = 1 | RotClones = 1 then 'Repair'
-
- call CleanUp
-
-
- ERROR:
- arg ErrTxt
- 'GetBool ErrTxt "Cancel" "Cancel"'
- CLEANUP:
- 'UnLock'
- EXIT
-
-
- RANPOS:
- call Limits
- DX = random(0,MaxDX)
- DX = DX/ (10 ** Xidx) /* Restore decimal (approximately :^) */
- if random(0,1) = 0 then DX = -DX /* Random() is BIASED TO 0 */
- DY = random(0,MaxDY)
- DY = DY / (10 ** Yidx) /* Restore decimal (approximately :^) */
- if random(0,1) = 1 then DY = -DY /* Random() is BIASED TO 0 */
- /* Random() is biased to zero; thus, current random sign values bias
- to upper-left. Specifically (likewise the converse):
- DX sign ran()=0 biases to left
- DY sign ran() 1 biases to top */
- return
-
-
- LIMITS:
- 'GetPageDims' PDims
- /* Shift decimal to convert to 3 digit integer for Random() */
- numeric digits 3
- MaxDX = PDims.Width / 2
- Xidx = index(MaxDX,".")
- if Xidx ~= 0 then MaxDX = MaxDX * (10 ** Xidx)
- MaxDY = PDims.Height / 2
- Yidx = index(MaxDY,".")
- if Yidx ~= 0 then MaxDY = MaxDY * (10 ** Yidx)
- numeric digits 9 /* 3 DIGITS NOT SOURCE OF BIAS */
- return /* in fact, little diff either way */
-
-
- RANSCALE:
- /* Limit ScaleFactor from .5 to 2 */
- /*ScaleFactor = random(5,20)*/
- /* Limit ScaleFactor from .1 to 1.5 */
- ScaleFactor = random(1,15)
- ScaleFactor = ScaleFactor/10
- return
-
-
- RANROT:
- Degrees = random(1,360)
- return
-
-
- REQUEST:
- if show("P","REXXREQUEST") then
- do
- call DefGads
- address REXXREQUEST 'GetRequest Gads'; OK=Result
- if OK > 0 then /* The user didn't cancel the requester... */
- do
- NumClones = Gads.3.Value
- ScaleClones = Gads.4.Value
- RotClones = Gads.5.Value
- DelOrig = Gads.6.Value
- end /* end if do */
- else call CleanUp /* User canceled */
- end
- else call error "No REXXRequest"
- return
-
-
- DEFGADS:
- /* Define PubScreen */
- Gads.PubScreen = "PROVECTOR"
-
- /* Window */
- Gads.0.LeftEdge = 166; Gads.0.TopEdge = 70
- Gads.0.Width = 241; Gads.0.Height = 98
- Gads.0.Label = "Random Clones"
-
- /* OK button */
- Gads.1.LeftEdge = 16; Gads.1.TopEdge = 76
- Gads.1.Width = 64; Gads.1.Height = 12
- Gads.1.Type = Button; Gads.1.Label = "OK"; Gads.1.EndGad = 1
-
- /* CANCEL button */
- Gads.2.LeftEdge = 154; Gads.2.TopEdge = 76
- Gads.2.Width = 71; Gads.2.Height = 12
- Gads.2.Type = Button; Gads.2.Label = "Cancel"; Gads.2.EndGad = -1
-
- /* NumClones Integer Gadget */
- Gads.3.LeftEdge = 162; Gads.3.TopEdge = 8
- Gads.3.Width = 50; Gads.3.Height = 12
- Gads.3.Label = "Number of Clones"
- Gads.3.Type = Integer
- Gads.3.Size = 4 /* 4 digits */
- Gads.3.Active = 1
- Gads.3.Value = "60" /* initial/default */
-
- /* Scale Checkbox */
- Gads.4.LeftEdge = 26; Gads.4.TopEdge = 24
- Gads.4.Width = 158; Gads.4.Height = 12
- Gads.4.Label = "Scale Clones"
- Gads.4.Type = Toggle
- Gads.4.Value = "1" /* initial/default */
-
- /* Rotate Checkbox */
- Gads.5.LeftEdge = 26; Gads.5.TopEdge = 39
- Gads.5.Width = 158; Gads.5.Height = 1
- Gads.5.Label = "Rotate Clones"
- Gads.5.Type = Toggle
- Gads.5.Value = "1" /* initial/default */
-
- /* Delete Checkbox */
- Gads.6.LeftEdge = 26; Gads.6.TopEdge = 54
- Gads.6.Width = 158; Gads.6.Height = 12
- Gads.6.Label = "Delete Original Obj"
- Gads.6.Type = Toggle
- Gads.6.Value = "1" /* initial/default */
-
- /* Total Gadgets + Window */
- Gads.NumGads = 7
- return /* return DefGads */
-
-
- /*
- SAY "DX = "||DX
- SAY "DY = "||DY
- SAY "CX = "||CX
- SAY "CY = "||CY
- SAY ""
- */
- /*
-
- /* Temporary Initialization of variables; later use RexxRequest */
- NumClones = 5
- MinX = 0; MaxX = 8.5 /* Later default to */
- MinY = 0; MaxY = 11 /* page size. */
- MinScale = .5; MaxScale = 2
- MinRot = 0; Maxrot = 360
- */
-
- /*
- do i=1 for NumClones
- do j=0 for NumSel
- /*call RanPos*/
- 'Clone' Sel.j DX DY; Clone = Result
- if ScaleClones = 1 then do
- call RanScale
- 'Size' Clone (CX+DX) (CY+DY) ScaleFactor ScaleFactor
- end
- if RotClones = 1 then do
- call RanRot
- 'Rotate' Clone (CX+DX) (CY+DY) Degrees
- end
- /*** OOOHHH, BAD, BAD, BAD!!! ***/
- /* These objs are then cloned AFTER deletion! */
- if DelOrig = 1 then 'Delete' Sel.j
- /* if DelOrig = 1 then 'Delete' Clone */
- /* This deleted ALL the Clones! */
- /*** OOOHHH, BAD, BAD, BAD!!! ***/
- end
- end
- */
-