Skip to content

Instantly share code, notes, and snippets.

@kumo
Last active August 29, 2015 14:01
Show Gist options
  • Save kumo/667796a13b6f0aa7629f to your computer and use it in GitHub Desktop.
Save kumo/667796a13b6f0aa7629f to your computer and use it in GitHub Desktop.
Duplicate an object into a marching crowd
var layer = selection[0];
var layerWidth = [[layer frame] width];
var layerHeight = [[layer frame] height];
var frame = [layer frame];
var parent = [layer parentGroup];
var widthOffset = layerWidth / 100 * 50;
var heightOffset = layerHeight / 100 * 60;
for (var row=0; row<5; row++) {
for (var col=0; col<3; col++) {
var clone = [layer duplicate];
var frame2 = [clone frame];
if (row % 2 == 1) {
[frame2 setX: col * (layerWidth) + widthOffset];
} else {
[frame2 setX: col * (layerWidth) + widthOffset - widthOffset];
}
[frame2 setY: -row * (layerHeight - heightOffset)];
}
if (row % 2 == 0) {
var clone = [layer duplicate];
var frame2 = [clone frame];
[frame2 setX: 3 * (layerWidth) + widthOffset - widthOffset];
[frame2 setY: -row * (layerHeight - heightOffset)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment