Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. // creating a document
  2. var doc = app.documents.add();
  3. // adding a new layer
  4. var layer = doc.layers.add();
  5.  
  6. // variable declarations
  7. var i, ray, displacement, dx, dy;
  8.  
  9. // creating 20 path items in a loop and setting their parameters
  10. for (i = 0; i < 20; i++) {
  11. // adding a path item and saving it to the "ray" variable
  12. ray = layer.pathItems.add();
  13. // defining path points
  14. ray.setEntirePath([ [0, 0], [0, 10]]);
  15.  
  16. // generating a random angle for rotation
  17. // note: rotation in Illustrator is counter-clockwise
  18. ray.rotation = Math.round(Math.random() * 360);
  19. // applying rotation to the path, using its bottom as the origin point
  20. ray.rotate(ray.rotation, true, true, true, true, Transformation.BOTTOM);
  21.  
  22. // moving the path away from the center of the document by "displacement" amount
  23. displacement = 10 + Math.random() * 10;
  24. // calculating x and y coordinates from "displacement"
  25. // (which is basically a hypotenuse)
  26. dx = displacement * Math.sin( (180 + ray.rotation) * Math.PI / 180 );
  27. dy = - displacement * Math.cos( (180 + ray.rotation) * Math.PI / 180 );
  28. // translating the path
  29. ray.translate(dx, dy);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement