home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d7xx / d724 / donsgenies.lha / DonsGenies / DonsGenies.lha / Don'sGenies / StepAndRepeatDeLuxe.pprx < prev    next >
Text File  |  1992-08-13  |  13KB  |  361 lines

  1. /*
  2. StepAndRepeatDeLuxe  
  3. This Genie will make multiple copies of a box with user specified offset and rotation between copies. You can also scale the copies and set the centre of rotation. 
  4. Written by Don Cox   July 92.
  5. */
  6.  
  7.  
  8. if ~show("l", "gdarexxsupport.library") then
  9.     if ~addlib("gdarexxsupport.library", 0, -30,0) then
  10.     do
  11.         call ppm_Inform(1,"Please install the gdarexxsupport.library in your libs: directory before running this Genie.")
  12.     end
  13.  
  14.  
  15. cr = '0a'x
  16. address command
  17. call SafeEndEdit.rexx()
  18. units = ppm_GetUnits()
  19. if units = 3 then call ppm_SetUnits(2)
  20.  
  21. signal on halt
  22. signal on break_c
  23. signal on break_e
  24. signal on break_d
  25.  
  26. cu = "in"
  27. if units = 2 then cu = "cm"
  28.  
  29. call ppm_AutoUpdate(0)
  30.  
  31. call ppm_NewGroup()
  32. box = ppm_ClickOnBox("Click on box to duplicate..")
  33. if box = 0 then exit_msg("No box selected")
  34. call ppm_AddToGroup(box)  /* whole set grouped including original box */
  35. dup = 0
  36.  
  37. trace r
  38. source = ppm_Inform(3,"Settings from...","Same again","Defaults","Disk file")
  39.  
  40. oldangle = ppm_GetBoxAngle(box)
  41. call ppm_SetBoxAngle(box,0)   /* rotate to zero to get centre */
  42. boxpos  = ppm_GetBoxPosition(box)
  43. curX   = word(boxpos, 1 )
  44. curY   = word(boxpos, 2 )
  45.  
  46. boxsize = ppm_GetBoxSize(box)
  47. width   = word(boxsize, 1 )
  48. height  = word(boxsize, 2 )
  49.  
  50. centreX = curX+(width/2)
  51. centreY = curY+(height/2)
  52. call ppm_SetBoxAngle(box,oldangle)
  53. boxpos  = ppm_GetBoxPosition(box)
  54.  
  55. ImageScaleX = word(ppm_GetBoxScale(box),1)
  56. ImageScaleY = word(ppm_GetBoxScale(box),2)
  57.  
  58. call ppm_ShowStatus("Position: "curX", "curY" size: w"width", h"height)
  59.  
  60. formstring = ""
  61.  
  62. if source = 0 then do
  63.     if open("temp","ram:SRD.data","R") then do
  64.         formstring = readch("temp",512)
  65.         call close("temp")
  66.         end
  67.     if formstring = "" then source = 1  /* defaults if failed  */
  68.     end   /* source = 0  */
  69.  
  70. if source = 2 then do
  71.     loadfile = ppm_GetFileName("Load settings from disk","PPage:","")
  72.     if loadfile = "" then break
  73.     if open("loader",loadfile,"R") then do
  74.         formstring = readch("loader",512)
  75.         call close("loader")
  76.         end
  77.     if formstring = "" then source = 1  /* go for defaults  */
  78.     end
  79.  
  80. if formstring = "" then formstring ="rows:2"||cr"columns:1"||cr"horiz. spacing ("cu"):"width||cr"vertical spacing ("cu"):"height||cr"horiz. offset ("cu"):"0||cr"offset angle:"0||cr"rotation angle:"0||cr"rotation centre, X:"centreX||cr"rotation centre, Y:"centreY||cr"scale, X:1.00"||cr"scale, Y:1.00"||cr"spiral scale:1.00"||cr"spiral spacing("cu"):0"||cr"save settings (Y/N):N"||cr"Link boxes (Y/N):N"
  81.  
  82.  
  83. form = ppm_GetForm("Step & Repeat DeLuxe", 12, formstring)
  84. if form = '' then exit_msg("Aborted by User")
  85.  
  86. parse var form rows '0a'x columns '0a'x  horizontal '0a'x vertical '0a'x HorizOffset '0a'x OffsetAngle '0a'x RotAngle '0a'x Xcentre '0a'x Ycentre '0a'x Xscale '0a'x Yscale '0a'x SpiralScale '0a'x SpiralIncrement '0a'x Saving '0a'x Linking
  87.  
  88.  
  89. if rows = '' then rows = 1
  90. if columns = '' then columns = 1
  91. if horizontal = '' then horizontal = 0
  92. if vertical = '' then vertical = 0
  93. if HorizOffset = "" then HorizOffset = 0
  94. if OffsetAngle = "" then OffsetAngle = 0
  95. if RotAngle = '' then RotAngle = 0
  96. if Xcentre = "" then Xcentre = centreX
  97. if Ycentre = "" then Ycentre = centreY
  98. if Xscale = "" then Xscale = 1
  99. if Yscale = "" then Yscale = 1
  100. if SpiralScale = "" then SpiralScale = 1
  101. if SpiralIncrement = "" then SpiralIncrement = 0
  102.  
  103. if ~(datatype(rows, n)) then exit_msg("Invalid Entry for Rows: "rows)
  104. if ~(datatype(columns, n)) then exit_msg("Invalid Entry for Columns: "columns)
  105. if ~(datatype(horizontal, n)) then exit_msg("Invalid Entry for Horiz. Spacing: "horizontal)
  106. if ~(datatype(HorizOffset, n)) then exit_msg("Invalid Entry for Horiz. Offset: "HorizOffset)
  107. if ~(datatype(vertical, n)) then exit_msg("Invalid Entry for Vertical Spacing: "vertical)
  108. if ~(datatype(OffsetAngle, n)) then exit_msg("Invalid Entry for Offset Angle: "OffsetAngle)
  109. if ~(datatype(RotAngle, n)) then exit_msg("Invalid Entry for Rotation Angle: "RotAngle)
  110. if ~(datatype(Xcentre, n)) then exit_msg("Invalid Entry for Rotation Centre X: "Xcentre)
  111. if ~(datatype(Ycentre, n)) then exit_msg("Invalid Entry for Rotation Centre Y: "Ycentre)
  112. if ~(datatype(Xscale, n)) then exit_msg("Invalid Entry for X scale: "Xscale)
  113. if ~(datatype(Yscale, n)) then exit_msg("Invalid Entry for Y scale: "Yscale)
  114. if ~(datatype(SpiralScale, n)) then exit_msg("Invalid Entry for Spiral Scale: "SpiralScale)
  115. if ~(datatype(SpiralIncrement, n)) then exit_msg("Invalid Entry for Spiral Increment: "SpiralIncrement)
  116.  
  117. formstring ="rows:"rows||"0a"x"columns:"columns||"0a"x"horiz. spacing ("cu"):"horizontal||"0a"x"vertical spacing ("cu"):"vertical||"0a"x"horiz. offset ("cu"):"HorizOffset||"0a"x"offset angle:"OffsetAngle||"0a"x"rotation angle:"RotAngle||"0a"x"rotation centre, X:"Xcentre||"0a"x"rotation centre, Y:"Ycentre||"0a"x"scale, X:"Xscale||"0a"x"scale, Y:"Yscale||"0a"x"spiral scale:"SpiralScale||"0a"x"spiral spacing("cu"):"SpiralIncrement||"0a"x"save settings (Y/N):"upper(Saving)||"0a"x"Link boxes (Y/N):"upper(Linking)"0a"x
  118.  
  119. if open("temp","ram:SRD.data","W") then do
  120.     call seek("temp",0,"B") 
  121.     call writech("temp",formstring)
  122.     call close("temp")
  123.     end
  124.  
  125. if upper(Saving) = "Y" then do
  126.     savefile = ppm_GetFileName("Save settings to disk","PPage:","")
  127.     if savefile = "" then break
  128.     if open("saver",savefile,"W") then do
  129.         call writech("saver",formstring)
  130.         call close("saver")
  131.         end
  132.     end
  133.  
  134. if RotAngle ~=0 then SpiralIncrement = SpiralIncrement/(360/RotAngle) /* get value for each unit  */
  135.  
  136.  
  137. AroundCentre = 0
  138. if centreX ~= Xcentre | centreY ~= Ycentre then AroundCentre = 1
  139. rotationangle = oldangle
  140. HorizShift = 0   /* sideways shift for offset angle */
  141. if OffsetAngle ~= 0 then do  /* use horiz. spacing and offset angle */
  142.     Oangle=OffsetAngle*3.1415926/180  /* convert to radians  */
  143.     vertical = horizontal*sin(Oangle)
  144.     HorizShift = horizontal*cos(Oangle)
  145.     end
  146. ScaledWidth = width
  147. ScaledHeight = height
  148. ScaledImageX = ImageScaleX
  149. ScaledImageY = ImageScaleY
  150. scaling = 0
  151. if Xscale~=1 | Yscale~=1 then scaling = 1    /* set scaling flag  */
  152.  
  153. boxes.1.1 = box
  154.  
  155.  
  156. /* For single rows or lines of units */
  157. if rows = 1 | columns = 1 then do
  158.     call ppm_ShowStatus("   Working on single column ")
  159.     do i = 2 to max(rows,columns)
  160.         k=i-1
  161.         box = boxes.1.k
  162.         
  163.         /* to avoid a bug in CloneBox we have to clone first and then set the position  */
  164.         boxX=word(ppm_GetBoxPosition(box),1)
  165.         boxY=word(ppm_GetBoxPosition(box),2)
  166.         boxX=boxX+HorizShift+HorizOffset
  167.         boxY=boxY+vertical
  168.         newbox = ppm_CloneBox(box, 0,0)
  169.         call ppm_AddToGroup(newbox)
  170.         call ppm_SetBoxPosition(newbox,boxX,boxY)
  171.         
  172.         boxes.1.i = newbox
  173.         if rotangle ~= 0 then do
  174.             newangle = (rotationangle + rotangle)//360
  175.             call ppm_SetBoxAngle(newbox, newangle)
  176.             rotationangle = newangle
  177.             end
  178.  
  179.         if  AroundCentre = 1 then do
  180.             adjustment = newbox "0a"x Xcentre "0a"x Ycentre "0a"x rotangle "0a"x SpiralScale "0a"x SpiralIncrement
  181.             call rotator(adjustment)
  182.             end
  183.  
  184.         if upper(linking)="Y" then linked = ppm_LinkBox(box,newbox)
  185.  
  186.         if scaling = 1 then do
  187.             ScaledWidth = ScaledWidth*Xscale
  188.             ScaledHeight = ScaledHeight*Yscale
  189.             ScaledImageX = ScaledImageX*Xscale
  190.             ScaledImageY = ScaledImageY*Yscale
  191.             call ppm_SetBoxSize(newbox,ScaledWidth,ScaledHeight)
  192.             call ppm_SetBoxScale(newbox,ScaledImageX,ScaledImageY)
  193.             vertical = vertical * Yscale
  194.             horizontal = horizontal * Xscale
  195.             end
  196.  
  197.         end   /* of column */
  198. end /* rows or columns = 1  */
  199.  
  200.  
  201. else do   /* for multiple columns  */
  202.  
  203. /* make first column */
  204. call ppm_ShowStatus("   Working on column 1")
  205.     do i = 2 to rows
  206.         k=i-1
  207.         box = boxes.1.k
  208.                 
  209.         /* to avoid a bug in CloneBox we have to clone first and then set the position  */
  210.         boxX=word(ppm_GetBoxPosition(box),1)
  211.         boxY=word(ppm_GetBoxPosition(box),2)
  212.         boxX=boxX+HorizShift+HorizOffset
  213.         boxY=boxY+vertical
  214.         newbox = ppm_CloneBox(box, 0,0)
  215.         call ppm_AddToGroup(newbox)
  216.         call ppm_SetBoxPosition(newbox,boxX,boxY)
  217.         
  218.         boxes.1.i = newbox
  219.         if rotangle ~= 0 then do
  220.             newangle = (rotationangle + rotangle)//360
  221.             call ppm_SetBoxAngle(newbox, newangle)
  222.             rotationangle = newangle
  223.             end
  224.  
  225.         if  AroundCentre = 1 then do
  226.             adjustment = newbox "0a"x Xcentre "0a"x Ycentre "0a"x rotangle "0a"x SpiralScale "0a"x SpiralIncrement
  227.             call rotator(adjustment)
  228.             end
  229.  
  230.         if upper(linking)="Y" then linked = ppm_LinkBox(box,newbox)
  231.  
  232.         if scaling = 1 then do
  233.             ScaledImageY = ScaledImageY*Yscale
  234.             ScaledHeight = ScaledHeight*Yscale
  235.             call ppm_SetBoxSize(newbox,width,ScaledHeight)
  236.             call ppm_SetBoxScale(newbox,ImageScaleX,ScaledImageY)
  237.             vertical = vertical * Yscale
  238.             end
  239.  
  240.     end   /* of first column */
  241.  
  242.  
  243.     vertical = height
  244.     box = boxes.1.1
  245.     rotationangle = oldangle
  246.  
  247.     do j = 2 to columns
  248.        call ppm_ShowStatus("  Working on column "j) 
  249.        k = j-1
  250.  
  251.         rotationangle = ppm_GetBoxAngle(boxes.k.1)
  252.         do i = 1 to rows
  253.             box = boxes.k.i
  254.                     
  255.             /* to avoid a bug in CloneBox we have to clone first and then set the position  */
  256.             boxX=word(ppm_GetBoxPosition(box),1)
  257.             boxY=word(ppm_GetBoxPosition(box),2)
  258.             boxX=boxX+Horizontal
  259.             newbox = ppm_CloneBox(box, 0,0)
  260.             call ppm_AddToGroup(newbox)
  261.             call ppm_SetBoxPosition(newbox,boxX,boxY)
  262.             
  263.             boxes.j.i = newbox
  264.             if rotangle ~= 0 then do
  265.                 newangle = (rotationangle + rotangle)//360
  266.                 call ppm_SetBoxAngle(newbox, newangle)
  267.                 rotationangle = newangle
  268.                 end
  269.  
  270.         if  AroundCentre = 1 then do
  271.             adjustment = newbox "0a"x Xcentre "0a"x Ycentre "0a"x rotangle "0a"x SpiralScale "0a"x SpiralIncrement
  272.             call rotator(adjustment)
  273.             end
  274.  
  275.         if upper(linking)="Y" then linked = ppm_LinkBox(box,newbox)
  276.  
  277.         if scaling = 1 then do
  278.             ScaledWidth = word(ppm_GetBoxSize(box),1) *Xscale
  279.             ScaledHeight = word(ppm_GetBoxSize(box),2)
  280.             ScaledImageX = word(ppm_GetBoxScale(box),1) *Xscale
  281.             ScaledImageY = word(ppm_GetBoxScale(box),2)
  282.             call ppm_SetBoxSize(newbox,ScaledWidth,ScaledHeight)
  283.             call ppm_SetBoxScale(newbox,ScaledImageX,ScaledImageY)
  284.             vertical = vertical * Yscale
  285.             ScaledImageY = ScaledImageY * Yscale
  286.             end
  287.  
  288.         end   /* rows */
  289.         
  290.         if scaling = 1 then do 
  291.             horizontal = horizontal*Xscale
  292.             vertical = height
  293.             ScaledImageX = ScaledImageX*Xscale
  294.             ScaledImageY = ImageScaleY
  295.             end
  296.     end   /* columns */
  297.  
  298. end  /* multiple columns  */
  299.  
  300. exit_msg()
  301. end
  302.  
  303.  
  304. /* Rotate box around a centre */
  305.  
  306. rotator: procedure
  307.  
  308. parse arg box '0a'x Xcentre '0a'x Ycentre '0a'x angle '0a'x SpiralScale '0a'x SpiralIncrement
  309. startangle = ppm_GetBoxAngle(box)
  310. call ppm_SetBoxAngle(box,0)
  311. boxpos = ppm_GetBoxPosition(box)
  312. boxleft = word(boxpos,1)
  313. boxtop = word(boxpos,2)
  314. boxsize = ppm_GetBoxSize(box)
  315. boxwidth = word(boxsize,1)
  316. boxheight = word(boxsize,2)
  317. boxcentreX = boxleft+(boxwidth/2)
  318. boxcentreY = boxtop+(boxheight/2)
  319.  
  320. rangle=angle*3.1415926/180  /* convert to radians  */
  321. cosa = cos(rangle)
  322. sina = sin(rangle)
  323. Xoffset = boxcentreX-Xcentre
  324. Yoffset = boxcentreY-Ycentre
  325. newX = (Xoffset*cosa)+(Yoffset*sina)
  326. newY = (Yoffset*cosa)-(Xoffset*sina)
  327.  
  328. if SpiralIncrement ~= 0 then do   /* using Pythagoras to split increment of radius into x & y  */
  329.     incX = (SpiralIncrement * newX) / (sqrt((newX*newX) + (newY*newY)))
  330.     incY = (SpiralIncrement * newY) / (sqrt((newX*newX) + (newY*newY)))
  331.     newX = NewX + incX
  332.     newY = newY + incY
  333.     end
  334.  
  335. x = Xcentre+newX
  336. y = Ycentre+newY
  337. x = x * SpiralScale
  338. y = y * SpiralScale
  339. call ppm_SetBoxPosition(box,x-(boxwidth/2),y-(boxheight/2))
  340. call ppm_SetBoxAngle(box,startangle)
  341.  
  342. return
  343.  
  344.  
  345. break_d:
  346. break_e:
  347. break_c:
  348. halt:
  349.     call exit_msg("User aborted Genie!")
  350.  
  351. exit_msg: procedure  expose units
  352. do
  353.     parse arg message
  354.  
  355.     if message ~= '' then call ppm_Inform(1, message,"Resume")
  356.     call ppm_ClearStatus()
  357.     call ppm_SetUnits(units)
  358.     call ppm_AutoUpdate(1)
  359.     exit
  360. end
  361.