-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrandomly-distribute.sketchplugin
More file actions
50 lines (37 loc) · 1.32 KB
/
randomly-distribute.sketchplugin
File metadata and controls
50 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var doc = context.document;
var currentArtboard = context.selection[0].parentArtboard;
var selection = context.selection;
/* 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];
}
}