Last active
August 29, 2015 14:01
-
-
Save kumo/79c9ffda330bdf57c675 to your computer and use it in GitHub Desktop.
Randomly distribute a number of selected objects across the art board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you duplicate multiple objects and they end up overlapping, the higher objects will seem to appear more often.