I have found (and use) scripts for random opacity, random resize, random rotation etc. but I can't seem to find one which will do a "random displacement/move"
With the other above mentioned scripts, you simply select the paths, run the script and enter in a minimum value and a maximum value and the computer randomizes it for you. (Say min 20% opacity, max 80% opacity - they will all be between 20-80% opacity)
Is this script difficult to create?
Couldn't it just be enter in min -X
and min -Y
to max X
and max Y
movement? Then the computer would just choose a random value as it does in the other scripts.
Answer
Here is a implementation of uniform box scatter
scatter_box(activeDocument.selection, 100, 100);
function scatter_box(items, xoffset, yoffset){
for(var i=0;i var oldpos = items[i].position;
items[i].position= [oldpos[0]+Math.random()*xoffset-xoffset/2,
oldpos[1]+Math.random()*yoffset-yoffset/2];
}
}
Here for uniform disc scatter.
scatter_disk(activeDocument.selection, 50);
function scatter_disk(items, rad){
for(var i=0;i
var oldpos = items[i].position;
var r = Math.sqrt(Math.random()*rad*rad);
var theta = Math.random()*2*Math.PI;
items[i].position= [oldpos[0]+r*Math.sin(theta),
oldpos[1]+r*Math.cos(theta)];
}
}
Obviously you could use other random distributions too.
GUI version
#target illustrator
buildGUI();
function buildGUI(){
var resource =
"dialog { text:'jooScatter',\
properties:{ closeButton:true, maximizeButton:false,\
minimizeButton:false, resizeable:false },\
orientation:'row', spacing:2, margins:5,\
alignChildren:['left','fill'],\
g: Group {\
alignChildren:['left','fill'],\
orientation:'column', spacing:20,margins:5,\
p1: Panel {\
text: 'Scatter Offsets:',\
g1: Group {\
orientation:'column',\
x: Group {\
st: StaticText { text:'x width:'},\
f: EditText {text:'100', characters:20}\
},\
y: Group {st2 : StaticText{ text:'y width:'},\
f: EditText { text:'100' , characters:20 },\
},\
},\
},\
g2: Group { alignment: 'right', orientation:'row',\
apply: Button { text: 'Apply'},\
cancel: Button { text:'Cancel'},\
}\
}\
}"
var win = new Window (resource);
var cancel = function() {
win.close(0);
}
var apply = function() {
scatter_box(activeDocument.selection,
eval(win.g.p1.g1.x.f.text),
eval(win.g.p1.g1.y.f.text)
);
redraw();
}
win.g.g2.apply.onClick = apply;
win.g.g2.cancel.onClick = cancel;
win.show();
}
function scatter_box(items, xoffset, yoffset){
for(var i=0;i var oldpos = items[i].position;
items[i].position= [oldpos[0]+Math.random()*xoffset-xoffset/2,
oldpos[1]+Math.random()*yoffset-yoffset/2];
}
}
GIF of it in action here
No comments:
Post a Comment