-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern Generator UI.js
72 lines (57 loc) · 1.65 KB
/
Pattern Generator UI.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
*
* Create the interface to generate patterns.
*
* @author Michele Mauri
* @version 0.1.1
*
*/
include('Classes/Utils/Pattern.js');
/**
* get all the paths and updates their fill with the new pattern.
*
*/
function updatePatterns(_pattern)
{
var selectedPaths = document.getItems({
type: Path,
selected: true
});
for(p in selectedPaths)
{
selectedPaths[p].fillColor = _pattern;
}
}
//creates the interface: components, values, an then palette.
var components = {
type: { type: 'list', label:'Pattern type', options:['Lines Pattern', 'Circles Pattern', 'Squares Pattern']},
ruler1: { type: 'ruler'},
size: { type: 'number', label: 'Width', units: 'point', steppers: true },
rotation: { type: 'number', label: 'Rotation', units: 'degree' },
density: { type: 'number', label: 'Density', units: 'percent' },
color: { type: 'color', label: 'Color' }
}
var values = {
type: 'Lines Pattern',
size: 5,
rotation: 45,
density: 50,
color: '#ff0000'
}
var palette = new Palette('New Pattern',components, values);
//updatePatterns(PatternLine(values.size,values.density/100,values.rotation,values.color));
palette.onChange = function(comp){
switch (values.type){
case 'Lines Pattern':
updatePatterns(PatternLine(values.size,values.density/100,values.rotation,values.color));
break;
case 'Circles Pattern':
updatePatterns(PatternCircle(values.size,values.density/100,values.rotation,values.color));
break;
case 'Squares Pattern':
updatePatterns(PatternSquare(values.size,values.density/100,values.rotation,values.color));
break;
default:
preview.fillColor = '#A7A9AC';
}
}