-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceltic_design.1.0.html
360 lines (293 loc) · 12.4 KB
/
celtic_design.1.0.html
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>HTML 5 :: Celtic Grid</title>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'
type='text/javascript'></script>
<link href='http://fonts.googleapis.com/css?family=Rosarivo'
rel='stylesheet' type='text/css'>
<link href='jquery-ui-1.8.20.custom/css/ui-lightness/jquery-ui-1.8.20.custom.css'
rel='stylesheet' type='text/css'>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<style type='text/css'>
body {
background:#999;
font-family:'Rosarivo', arial;
}
#blossom {
border:solid 4px #666;
background:white;
float:left;
}
#wrapper {
width:900px;
height:600px;
margin:50px auto;
}
#right {
width:210px;
height:567px;
float:right;
background:#ccc;
padding:20px;
}
input, label {
float:left;
width:200px;
height:20px;
}
input {
border:solid 1px #999;
padding:3px 5px;
width:190px;
}
label {
padding:10px 0 3px 0;
font-size:15px;
height:auto;
}
#submit {
position:relative;
top:15px;
background:#666;
color:white;
border:0;
font-size:15px;
padding:5px 0;
height:auto;
width:200px;
}
#submit:hover, #variation:hover {
background:#c50;
}
#data {
clear:both;
}
.slider {
clear:both;
width:200px;
}
#variation {
display:block;
margin-top:20px;
margin-left:-10px;
color:white;
background:#666;
padding:5px;
text-align:center;
text-decoration:none;
}
</style>
</head>
<body>
<div id='wrapper'>
<canvas id="blossom" width="600" height="600"></canvas>
<div id='right'>
<form id='params'>
<label for='sides'>Horizontal Steps</label>
<div>
<div class='slider'></div>
<input type='hidden' id='grid_size_x' value='4' />
</div>
<label for='sides'>Vertical Steps</label>
<div>
<div class='slider'></div>
<input type='hidden' id='grid_size_y' value='4' />
</div>
<label for='sides'>Zoom</label>
<div>
<div class='slider'></div>
<input type='hidden' id='cell_size' value='10' />
</div>
<a href='' id='variation'>Variation</a>
</form>
</div>
<div id='data'></div>
</div>
<div id="slider"></div>
<!-- End demo -->
<script type="application/javascript">
$(function () {
function clearCanvas() {
var canvas = document.getElementById("blossom"),
context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
}
//builds incriminator pattern
function build_pattern() {
var grid_size_x = parseInt($('#grid_size_x').val());
var grid_size_y = parseInt($('#grid_size_y').val());
var curve_priority = parseInt($('#curve_priority').val());
var y_random_range, x_random_range;
//stores pattern incrementor
var points = new Array(new Array(0, 0));
//tracks span of x's and y's
var x_total = 0;
var y_total = 0;
//increases range for smaller value to increase probability of a 0.
//This will make it less likely to make a long straight line.
if (grid_size_x > grid_size_y) {
x_random_range = 2;
y_random_range = (grid_size_x / grid_size_y) + 1;
} else if (grid_size_y > grid_size_x) {
y_random_range = 2;
x_random_range = (grid_size_y / grid_size_x) + 2;
} else {
y_random_range = 2;
x_random_range = 2;
}
//return false;
//console.log(' ');
//cycle through increment point to build patten.
while (1 == 1) {
if (x_total >= grid_size_x && y_total >= grid_size_y) {
break;
}
if (x_total < grid_size_x) {
x = Math.floor(Math.random() * x_random_range);
if (x > 0) {
x = 0;
} else {
x = 1;
}
} else {
x = 0;
}
if (y_total < grid_size_y) {
y = Math.floor(Math.random() * y_random_range);
if (y > 0) {
y = 0;
} else {
y = 1;
}
} else {
y = 0;
}
//calculate distance moved on the grid
x_total = x_total + x;
y_total = y_total + y;
var t = new Array(x, y)
points.push(t);
}
return points;
}
function draw() {
clearCanvas();
pattern = build_pattern();
var canvas = document.getElementById("blossom"),
ctx;
var cell_size = parseInt(($('#cell_size').val() / 1000) * $('#blossom').width());
var grid_size_x = $('#grid_size_x').val() * cell_size;
var grid_size_y = $('#grid_size_y').val() * cell_size;
var x_offset = grid_size_x * 2 * -1;
//repeat rows
while (x_offset < $('#blossom').width()) {
draw_segment(canvas, pattern, x_offset, y_offset, cell_size);
x_offset = x_offset + (grid_size_x * 2);
//make columns
var y_offset = grid_size_y;
while (y_offset < $('#blossom').height()) {
draw_segment(canvas, pattern, x_offset, y_offset, cell_size);
y_offset = y_offset + (grid_size_y * 2);
}
} //end drawing while loop
}
function draw_segment(canvas, pattern, x_offset, y_offset, cell_size) {
if (canvas.getContext) {
ctx = canvas.getContext("2d");
ctx.globalAlpha = 1;
ctx.beginPath();
if (isNaN(y_offset)) {
y_offset = 0;
}
var x = Math.round(x_offset);
var y = Math.round(y_offset);
for (i = 0; i < pattern.length; i++) {
var x_increment = pattern[i][0] * cell_size;
var y_increment = pattern[i][1] * cell_size;
var curve = pattern[i][2];
coord = draw_new_line(x_increment, y_increment, x, y);
x = coord[0];
y = coord[1];
}
pattern2 = array_flip(pattern);
for (i = 0; i < pattern2.length; i++) {
x_increment = pattern2[i][0] * cell_size;
y_increment = pattern2[i][1] * cell_size * -1;
coord = draw_new_line(x_increment, y_increment, x, y);
x = coord[0];
y = coord[1];
}
for (i = 0; i < pattern.length; i++) {
x_increment = pattern[i][0] * cell_size * -1;
y_increment = pattern[i][1] * cell_size * -1;
coord = draw_new_line(x_increment, y_increment, x, y);
x = coord[0];
y = coord[1];
}
for (i = 0; i < pattern2.length; i++) {
x_increment = pattern2[i][0] * cell_size * -1;
y_increment = pattern2[i][1] * cell_size;
coord = draw_new_line(x_increment, y_increment, x, y);
x = coord[0];
y = coord[1];
}
ctx.fill();
ctx.stroke();
}
} // end draw segment
function draw_new_line(x_increment, y_increment, x, y) {
x = x + x_increment;
y = y + y_increment;
ctx.lineTo(x, y);
return new Array(x, y);
}
function array_flip(trans) {
tmp_ar = new Array();
for (i = 0; i < trans.length; i++) {
tmp_ar.unshift(trans[i]);
}
return tmp_ar;
}
///page movement
var move = 0;
var mouse_start_x;
var mouse_start_y;
var x_offset;
var y_offset;
$("#blossom").mousedown(function (e) {
move = 1;
start_x = e.pageX;
start_y = e.pageY;
}).mouseup(function () {
move = 0;
});
$("#blossom").mousemove(function (e) {
if (move == 1) {
x_offset = e.pageX - start_x;
y_offset = e.pageY - start_y;
//console.log(x_offset,y_offset);
}
});
draw();
$('#variation').click(function () {
draw();
return false;
});
$(".slider").slider({
animate: true,
range: "min",
value: 1,
min: 3,
max: 25,
step: 1,
//this gets a live reading of the value and prints it on the page
slide: function (event, ui) {
$(this).parent().find('input').attr('value', ui.value);
draw();
}
});
});
</script>
</body>
</html>