0

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.

  • Do you want it to work off a selection of items? – Silly-V Jul 3 '18 at 4:32
  • @Silly-V yes... – WELZ Jul 3 '18 at 4:32
  • Well, you might as well be using the Transform dialog box and using the random checkbox as well as the move settings to create the variation range. – Silly-V Jul 3 '18 at 4:35
  • 1
    No its not hard to build takes about 3 minutes (but i have no computer to run illustrator on untill tomorrow). but this is built into the transform each command. – joojaa Jul 3 '18 at 5:36
  • Using transform effect, I can only get it to move in one direction, not both (I can't do between -10 and 10, only 0 and 10) – WELZ Jul 3 '18 at 5:38
4

enter image description here

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<items.length;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<items.length;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<items.length;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

  • These scripts are scatter scripts, but the value is already coded in the script, is there a way to make it give a pop-up for me to enter in a range at which it should scatter? (kinda like the other scripts I mentioned in my question) – WELZ Jul 3 '18 at 15:51
  • @WELZ Sure that's just more work for no particular reward – joojaa Jul 3 '18 at 15:53
  • Is there a way to make it where just moves the paths randomly between (-X and X) and (-Y and Y)? Where X and Y are entered in manually – WELZ Jul 3 '18 at 15:54
  • the reward is that not every doc/group of paths is the same size, so I'd constantly have to go and edit the script to fit for that project. – WELZ Jul 3 '18 at 15:55
  • 1
    @WELZ added gui. I dont know why one would want a screen aligned box, when it could be rotated arbitrarily but your poison i guess. – joojaa Jul 3 '18 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.