home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / Gradient and Twirl.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  6.5 KB  |  177 lines

  1. //////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED 
  4. // Copyright 2002 Adobe Systems Incorporated 
  5. // All Rights Reserved 
  6. //
  7. // NOTICE:  Adobe permits you to use, modify, and 
  8. // distribute this file in accordance with the terms
  9. // of the Adobe license agreement accompanying it.  
  10. // If you have received this file from a source 
  11. // other than Adobe, then your use, modification,
  12. // or distribution of it requires the prior 
  13. // written permission of Adobe. 
  14. //
  15. //////////////////////////////////////////////////
  16.  
  17. //////////////////////////////////////////////////
  18. // Gradient and Twirl.js
  19. //
  20. // DESCRIPTION
  21. //
  22. // This script gives the gradient and twirl effect 
  23. // to objects selected and animates them over frames.
  24. //
  25. // HOW TO USE
  26. //
  27. // Create any object(s) and select them in the Composition.
  28. // Select Automation > Run Automation Script 
  29. // > Gradient and Twirl.js
  30. // 
  31. // Click on Preview Mode to view the objects 
  32. // gradient and twirl effect.
  33. //
  34. //////////////////////////////////////////////////
  35.  
  36.  
  37. // Main Code [Execution of script begins from here]
  38.  
  39. // Check if any composition is open
  40. if(application.compositions.length > 0){
  41.     comp = application.currentComposition;
  42.     if(comp.selection.length >= 1){ // Checks if at least one object is selected
  43.         var targets = comp.selection; // Store all selected objects in the array targets
  44.         
  45.         application.currentComposition.saveSelection(); // saves the current selection
  46.         // Call function Gradient
  47.         // Make changes in the parameters to try with different results.
  48.         Gradient(targets, 48, 250, 250, 100, 50, 200); 
  49.         
  50.         // Call function distort
  51.         // Make changes in the parameters to try with different results.
  52.         Distort(targets, 48, 200, 3);     
  53.         
  54.         application.currentComposition.restoreSelection(); // restores the saved selection
  55.     }
  56.     else{ // If no objects are selected brings the Console window up 
  57.         Console.show();
  58.         // Writes to the Console
  59.         Console.write("Please select the objects to give gradient and twirl effect run script again.\n");
  60.     }
  61. }
  62. else{// if no composition open
  63.     // opens a new composition
  64.     comp = application.newComposition();
  65.     Console.show();
  66.     Console.write("New Composition opened\nPlease create and select the objects give gradient and twirl effect and run script again.\n");
  67. }
  68.  
  69.  
  70. // Add your own functions here
  71.  
  72. //////////////////////////////////////////////////
  73. // 
  74. // Gradient:
  75. // 
  76. // Set the targets objects with a given Gradient.
  77. // The starting color RGB values have to be specified for start of gradient.
  78. // The ending color RGB values have to be specified for end of gradient.
  79. // Both have to be significantly different to see the best result of the effect.
  80. //
  81. // targets: The objects to give the gradient and twirl effect
  82. // startRed: start red color for the gradient
  83. // starGreen: start green color for the gradient
  84. // starBlue: star blue color for the gradient
  85. // endRed: end red color for the gradient
  86. // endGreen: end green color for the gradient
  87. // endBlue: end blue color for the gradient
  88. //
  89. //////////////////////////////////////////////////
  90.  
  91.  
  92. function Gradient(targets, startRed, startGreen, startBlue, endRed, endGreen, endBlue)
  93. {
  94.     // loop through all of the selected objects
  95.     // Set their gradient type and the start and end color for the gradient
  96.     for(var i=0 ; i < targets.length ; i++){        
  97.         targets[i].layers[0].colorGradient.type = LMGradientType.burst;
  98.         targets[i].layers[0].colorGradient.startColor.red = startRed;
  99.         targets[i].layers[0].colorGradient.startColor.green = startGreen;
  100.         targets[i].layers[0].colorGradient.startColor.blue = startBlue;
  101.         targets[i].layers[0].colorGradient.endColor.red = endRed;
  102.         targets[i].layers[0].colorGradient.endColor.green = endGreen;
  103.         targets[i].layers[0].colorGradient.endColor.blue = endBlue;
  104.         }
  105. }
  106.  
  107.  
  108. //////////////////////////////////////////////////
  109. // 
  110. // Distort:
  111. // Give the distort effect - twirl to the targets object(s)
  112. //
  113. // targets: The objects to give twirl distortion effect
  114. // frames: The total number of frames across which the turns are set.
  115. // finalTurns: The number of turns in the twirl effect
  116. // keyFrameRate: The attribute will be recorded every this frame 
  117. // i.e. if keyFrameRate is 3 attribute is set at every 3rd frame and so on.
  118. // 
  119. // Note: The twirl turns cannot be seen without a gradient because 
  120. // then both will be of the same color. Hence here we have a gradient
  121. // before twirl turn.
  122. // 
  123. //////////////////////////////////////////////////
  124.  
  125.  
  126. function Distort(targets, frames, finalTurns, keyFrameRate)
  127. {
  128.     // Loop through all of the selected objects
  129.     for(var i=0 ; i < targets.length ; i++){ 
  130.         
  131.         // variable to store the original distortion type of the object.
  132.         var oriDistort = targets[i].layers[0].stopwatch.distortion.type;
  133.         
  134.         // variable to store the original number of turns the object has. 
  135.         var oriTwirlTurns = targets[i].layers[0].stopwatch.distortion.twirlTurns;    
  136.         
  137.         // Set the current original frame as the current frame
  138.         var frame0 = targets[0].startFrame; 
  139.         
  140.         // Finding the amount of turns to be set per key frame
  141.         var singleTurn = Math.round(finalTurns * keyFrameRate/frames);
  142.         
  143.         // Turn stopwatches for distortion and then twirlturns on
  144.         // You can specify positive or negative number of turns 
  145.         // for clockwise or anti-clockwise turns respectively
  146.         targets[i].layers[0].stopwatch.distortion.type = true;
  147.         targets[i].layers[0].stopwatch.distortion.twirlTurns = true;
  148.         
  149.         // Recording the attributes after the stopwatches are turned on, hence 
  150.         // assigning the oriainal values stored back to the object
  151.         targets[i].layers[0].distortion.type = oriDistort;
  152.         targets[i].layers[0].distortion.twirlTurns = oriTwirlTurns;
  153.         
  154.         // Setting the first frame of each object as the original frame
  155.         targets[i].currentFrame = frame0;
  156.         
  157.         // Set the distortion type
  158.         targets[i].layers[0].distortion.type = LMDistortType.twirl;
  159.         
  160.         // Loop to go through all the frames across which to set the final number
  161.         // turns
  162.         
  163.         for(var j=0 ; j < frames ; j += keyFrameRate){
  164.             // Set the key frame
  165.             targets[i].currentFrame = frame0 + j;
  166.             
  167.             // Increase the number of turns at each key frame 
  168.             targets[i].layers[0].distortion.twirlTurns += singleTurn;
  169.         }
  170.     }
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
  177.