-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid_generator.js
More file actions
174 lines (143 loc) · 5.02 KB
/
Copy pathgrid_generator.js
File metadata and controls
174 lines (143 loc) · 5.02 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*************by Shanfan Huang, the visual designer. http://shanfanhuang.com *******
This work is released under Creative Commons
Attribution-NonCommercial-ShareAlike (CC BY-NC-SA 3.0)
http://creativecommons.org/licenses/by-nc-sa/3.0/
***********************************************************************************/
var def = {
num: 40,
row: 6,
column: 6
};
var components = {
num: {
type: 'number',
label: 'Unit Radius'
},
row: {
type: 'number',
label: 'Rows',
steppers: true,
min: 1,
increment: 1
},
column: {
type: 'number',
label: 'Columns',
steppers: true,
min: 1,
increment: 1
},
/**********Equilateral Grid************/
btn1: {
type: 'button',
value: 'Make Triangular Grid',
onClick: function() {
var r = def.num;
var center = document.bounds.topLeft;
var myTri = new Path.RegularPolygon(center, 3, r/2);
var wStep = myTri.bounds.width/2;
var hStep = myTri.bounds.height/2;
myTri.position = new Point(wStep, hStep);
var y_count = def.row;
var x_count = def.column;
for (i=0; i< y_count; i++)
{
for (j=0; j< x_count; j++)
{
var newTri = myTri.clone();
newTri.position = new Point(wStep + wStep*j, hStep + hStep*2*i);
if ((i+j)%2 != 0){
newTri.rotate(180);
}
}
} //End of Loop
myTri.remove();
} //End of function
},
/********Alternative Triangular Grid ********/
btn2: {
type: 'button',
value: 'Alt. Triangular Grid',
onClick: function() {
var r = def.num;
var start = document.bounds.topLeft;
var myTri = new Path();
myTri.add(
new Point(start),
new Point(start + r),
new Point({x:0, y:r})
);
myTri.closed = true;
//End of drawing unit triangle
var y_count = def.row;
var x_count = def.column;
for (i=0; i<y_count; i++)
{
for (j=0; j<x_count; j++)
{
var newTri = myTri.clone();
if (j%2 != 0){
newTri.rotate(180);
newTri.position = new Point(r*(j/2), r*(i+.5));
}else{
newTri.position = new Point(r*(j/2+.5), r*(i+.5));
}
}
}
myTri.remove();
}
},
/*******Hexagonal Grid**********/
btn3: {
type: 'button',
value: 'Make Hexagonal Grid',
onClick: function() {
var r = def.num;
var center = document.bounds.topLeft;
var myHex = new Path.RegularPolygon(center, 6, r/2);
var wStep = myHex.bounds.width/2;
var hStep = myHex.bounds.height/2;
myHex.position = new Point(wStep, hStep);
var y_count = def.row;
var x_count = def.column;
for (i=0; i< y_count; i++)
{
for (j=0; j< x_count; j++)
{
var newHex = myHex.clone();
if (j%2 != 0){
newHex.position = new Point(wStep + wStep*(1+Math.cos(Math.PI/3))*j, hStep*2*i);
} else {
newHex.position = new Point(wStep + wStep*(1+Math.cos(Math.PI/3))*j, hStep + hStep*2*i);
}
}
} //End of Loop
myHex.remove();
}
},
/*************Alternative Hexagonal Grid***********/
btn4: {
type: 'button',
value: 'Alt. Hexagonal Grid',
onClick: function() {
var r = def.num;
var center = document.bounds.topLeft;
var myHex = new Path.RegularPolygon(center, 6, r/2);
var wStep = myHex.bounds.width/2;
var hStep = myHex.bounds.height/2;
myHex.position = new Point(wStep, hStep);
var y_count = def.row;
var x_count = def.column;
for (i=0; i< y_count; i++)
{
for (j=0; j< x_count; j++)
{
var newHex = myHex.clone();
newHex.position = new Point(wStep*(1+2*j), hStep*(2*i+1))
}
} //End of Loop
myHex.remove();
}
}
};
var palette = new Palette('Grid Generator', components, def);