-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathRandom Splitter.js
More file actions
57 lines (48 loc) · 1.3 KB
/
Copy pathRandom Splitter.js
File metadata and controls
57 lines (48 loc) · 1.3 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
51
52
53
54
55
56
57
// Script author peko [peko@gasubasu.com]
// http://gasubasu.com
// SPLITS PATHES OVER AN SELECTED IMAGE
// Rasterize image to RGB before use
var raster;
function segment(item, position) {
i = item.clone();
i.scale(0.5, position);
c = raster.getAverageColor(i);
i.fillColor = c;
//print(c, i.fillColor);
}
function splitItem(item) {
if (item instanceof Path) {
segment(item, item.bounds.topLeft);
segment(item, item.bounds.topRight);
segment(item, item.bounds.bottomLeft);
segment(item, item.bounds.bottomRight);
item.remove();
}
}
if (raster == null) {
var rasters = document.getItems({
type: Raster,
selected: true
});
if(rasters.length > 0) {
raster = rasters[0];
} else {
raster = null;
Dialog.alert('Please select an image first!')
}
}
var splitsNum = 0;
if (raster)
while (splitsNum < 100){
var p = Point(
raster.bounds.left+Math.random()*raster.bounds.width,
raster.bounds.top + Math.random()*raster.bounds.height
);
var hitResult = document.hitTest(p);
if (hitResult && hitResult.item instanceof Path){
splitItem(hitResult.item);
splitsNum ++;
//new Path.Circle(p, 5);
//document.redraw();
}
}