Advertisement
Cronos

Illustrator Wonky Circles Script

Nov 7th, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // script.name = wonkyCircles_CS4nUp.jsx;
  2. // script.description = it makes "crooked" (imperfect) circles in the Active Artboard;
  3. // script.requirement = an open document; //  CS4 and Up
  4. // script.parent = CarlosCanto // 11/6/12;
  5. // script.elegant = false;
  6.  
  7. #target Illustrator
  8.  
  9. if (app.documents.length>0) createWonkyCircles ();
  10. else alert ("no document to draw the wonkies");
  11.  
  12. function createWonkyCircles() {
  13.     var idoc = app.activeDocument;
  14.     var ilayer = idoc.layers.add(); ilayer.name = "Wonky Circles";
  15.     var bounds = idoc.artboards[idoc.artboards.getActiveArtboardIndex()].artboardRect;
  16.     var title = "Create Wonky Circles";
  17.     var copies = Number(prompt ("How many Wonky Circles?", 50, title));
  18.     var small = Number(prompt ("Enter Smallest Circle Radius in Points", 10, title));
  19.     var big = Number(prompt ("Enter Biggest Circle Radius in Points", 50, title));
  20.     var tolpercent = Number(prompt ("Enter Deformation Tolerance Percentage (%)", 6, title));
  21.  
  22.     for (j=0; j<copies; j++) {
  23.         var radius = randomXToY (small, big); // random circle size
  24.         var width = radius*2;
  25.         var height = radius*2;
  26.         var pntx = randomXToY (bounds[0], bounds[2]-width); // randomize position within arboard bounds
  27.         var pnty = randomXToY (bounds[1], bounds[3]+height);
  28.         var top = pnty;
  29.         var left = pntx;    
  30.         var icircle = idoc.pathItems.ellipse(top, left, width, height);
  31.         var tol = width * tolpercent/100; // adjust tolerance according to circles size to avoid weird shapes
  32.        
  33.         for (i=0; i<4; i++) {
  34.             var tolx = randomXToY (-tol, tol); // random x distance to move
  35.             var toly = randomXToY (-tol, tol); //random y distance to move
  36.            
  37.             var pp = icircle.pathPoints[i];
  38.             pp.anchor = [pp.anchor[0]+tolx, pp.anchor[1]+toly]; // move anchor
  39.             pp.leftDirection = [pp.leftDirection[0]+tolx, pp.leftDirection[1]+toly]; // and right left directions
  40.             pp.rightDirection = [pp.rightDirection[0]+tolx, pp.rightDirection[1]+toly];
  41.         }
  42.     }
  43.     //function to get random number between values, by Roshan Bhattarai
  44.     function randomXToY(minVal,maxVal,floatVal)
  45.     {
  46.       var randVal = minVal+(Math.random()*(maxVal-minVal));
  47.       //alert(randVal);
  48.       return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
  49.     }
  50.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement