home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / baoMask.js < prev    next >
Encoding:
JavaScript  |  2002-05-13  |  3.4 KB  |  100 lines

  1. /***************************************************************
  2. ADOBE SYSTEMS INCORPORATED 
  3. Copyright 2001 Adobe Systems Incorporated 
  4. All Rights Reserved 
  5.  
  6. NOTICE:  Adobe permits you to use, modify, and distribute this 
  7. file in accordance with the terms of the Adobe license agreement 
  8. accompanying it.  If you have received this file from a source 
  9. other than Adobe, then your use, modification, or distribution
  10. of it requires the prior written permission of Adobe. 
  11. ***************************************************************/
  12. /***************************************************************
  13. Author: Mary Obelnicki
  14. ***************************************************************/
  15.  
  16. /***************************************************************
  17. This file breaks the selected object into 'pieces' of a given size. 
  18. The pieces actually consist of an alias of the original object in a 
  19. group with a mask to create something that looks like a piece of the
  20. original without making the file large. 
  21.  
  22. ***************************************************************/
  23.  
  24. /***************************************************************
  25. To change the behavior of this script, 
  26. make your changes below
  27. ***************************************************************/
  28. var target = application.currentComposition.selection[0];
  29. baoMaskSquare(    target,    // the object to break apart 
  30.                 50);    // the size of the piece
  31.  
  32. /***************************************************************
  33. DO NOT EDIT BELOW THIS LINE
  34. ***************************************************************/
  35. function moveAnchorPointTo(object, x, y)
  36. {
  37.     object.anchorPoint.x += x - object.position.x; 
  38.     object.anchorPoint.y += y - object.position.y; 
  39.     object.position.x = x; 
  40.     object.position.y = y; 
  41. }
  42.  
  43.  
  44. function baoMaskSquare(object, sqSize)
  45. {
  46.     var mask = application.currentComposition.createObject(LMObjectType.geometric, 50, 50); 
  47.     mask.size.x = sqSize; 
  48.     mask.size.y = sqSize;
  49.     
  50.     var xmid = object.position.x + object.scale.x/100 * ((.5 * object.size.x) - object.anchorPoint.x);
  51.     var ymid = object.position.y + object.scale.y/100 * ((.5 * object.size.y) - object.anchorPoint.y);
  52.     
  53.     var halfXSquares = Math.ceil(.5 * object.scale.x/100 * object.size.x / sqSize); 
  54.     var halfYSquares = Math.ceil(.5 * object.scale.y/100 * object.size.y / sqSize); 
  55.     
  56.     var xpos; 
  57.     var ypos; 
  58.     var tempArray = new Array;
  59.     
  60.     for (xpos = (xmid - (halfXSquares - .5) * sqSize); xpos < (xmid + halfXSquares*sqSize); xpos+=sqSize)
  61.     {
  62.         for (ypos = (ymid - (halfYSquares - .5) * sqSize); ypos < (ymid + halfYSquares*sqSize); ypos+=sqSize)
  63.         {
  64.             var newObject = object.makeAlias(); 
  65.         
  66.             var newMask = mask.makeAlias(); 
  67.             newMask.position.x = xpos; 
  68.             newMask.position.y = ypos;
  69.         
  70.             tempArray[0] = newMask; 
  71.             tempArray[1] = newObject; 
  72.             var newGroup = application.currentComposition.group(tempArray); 
  73.             newGroup.topObjectIsMask = true;  
  74.             moveAnchorPointTo(newGroup, xpos, ypos);
  75.             newGroup.name = "PieceAt(" + xpos + "," + ypos + ")" ;   
  76.         }    
  77.     }
  78.     
  79.     mask.name = "OriginalMask" ; 
  80.     object.name = "OriginalObject" ; 
  81.     object.setDepth(0);
  82.     mask.setDepth(1); 
  83.     object.position.x = 50; 
  84.     object.position.y = application.currentComposition.size.y - 50; 
  85.     
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.