Skip to content

Instantly share code, notes, and snippets.

@kumo
Last active August 29, 2015 14:01
Show Gist options
  • Save kumo/79c9ffda330bdf57c675 to your computer and use it in GitHub Desktop.
Save kumo/79c9ffda330bdf57c675 to your computer and use it in GitHub Desktop.
Randomly distribute a number of selected objects across the art board
var currentArtboard = selection[0].parentArtboard;
log(currentArtboard);
var layer = selection[0];
var layerWidth = [[layer frame] width];
var layerHeight = [[layer frame] height];
var frame = [layer frame];
var parent = [layer parentGroup];
log(layer);
log(layer.style);
log(layer.children);
log(layer.layers);
log(frame);
log(parent);
var artboardWidth = [[parent frame] width];
var artboardHeight = [[parent frame] height];
log(artboardWidth);
log(artboardHeight);
var count = [doc askForUserInput:"How many copies do you want?" initialValue:"50"]
for (var j=0; j<[selection count]; j++) {
var source = selection[j];
var frame = [source frame];
[frame setX: Math.random() * (artboardWidth + layerWidth) - layerWidth / 2];
[frame setY: Math.random() * (artboardHeight + layerHeight) - layerHeight / 2];
[source setRotation:Math.random() * 360];
}
for (var i=0; i<count; i++) {
for (var j=0; j<[selection count]; j++) {
var source = selection[j];
var clone = [source duplicate];
var frame2 = [clone frame];
[frame2 setX: Math.random() * (artboardWidth + layerWidth) - layerWidth / 2];
[frame2 setY: Math.random() * (artboardHeight + layerHeight) - layerHeight / 2];
[clone setRotation:Math.random() * 360];
}
}
@kumo
Copy link
Author

kumo commented May 25, 2014

If you duplicate multiple objects and they end up overlapping, the higher objects will seem to appear more often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment