Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // script.name = wonkyCircles_CS4nUp.jsx;
- // script.description = it makes "crooked" (imperfect) circles in the Active Artboard;
- // script.requirement = an open document; // CS4 and Up
- // script.parent = CarlosCanto // 11/6/12;
- // script.elegant = false;
- #target Illustrator
- if (app.documents.length>0) createWonkyCircles ();
- else alert ("no document to draw the wonkies");
- function createWonkyCircles() {
- var idoc = app.activeDocument;
- var ilayer = idoc.layers.add(); ilayer.name = "Wonky Circles";
- var bounds = idoc.artboards[idoc.artboards.getActiveArtboardIndex()].artboardRect;
- var title = "Create Wonky Circles";
- var copies = Number(prompt ("How many Wonky Circles?", 50, title));
- var small = Number(prompt ("Enter Smallest Circle Radius in Points", 10, title));
- var big = Number(prompt ("Enter Biggest Circle Radius in Points", 50, title));
- var tolpercent = Number(prompt ("Enter Deformation Tolerance Percentage (%)", 6, title));
- for (j=0; j<copies; j++) {
- var radius = randomXToY (small, big); // random circle size
- var width = radius*2;
- var height = radius*2;
- var pntx = randomXToY (bounds[0], bounds[2]-width); // randomize position within arboard bounds
- var pnty = randomXToY (bounds[1], bounds[3]+height);
- var top = pnty;
- var left = pntx;
- var icircle = idoc.pathItems.ellipse(top, left, width, height);
- var tol = width * tolpercent/100; // adjust tolerance according to circles size to avoid weird shapes
- for (i=0; i<4; i++) {
- var tolx = randomXToY (-tol, tol); // random x distance to move
- var toly = randomXToY (-tol, tol); //random y distance to move
- var pp = icircle.pathPoints[i];
- pp.anchor = [pp.anchor[0]+tolx, pp.anchor[1]+toly]; // move anchor
- pp.leftDirection = [pp.leftDirection[0]+tolx, pp.leftDirection[1]+toly]; // and right left directions
- pp.rightDirection = [pp.rightDirection[0]+tolx, pp.rightDirection[1]+toly];
- }
- }
- //function to get random number between values, by Roshan Bhattarai
- function randomXToY(minVal,maxVal,floatVal)
- {
- var randVal = minVal+(Math.random()*(maxVal-minVal));
- //alert(randVal);
- return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement