-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg_puzzle.js
770 lines (621 loc) · 22 KB
/
svg_puzzle.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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
var allEdges = [];
var allPolygonAgents = [];
var allPolygons = [];
function getRandomColor(){
var colours = ["red", "green", "blue", "pink", "purple", "orange", "gray"];
var indx = Math.round(Math.random() * (colours.length -1));
return colours[indx];
}
function createEdgesFromGridPerimeter(){
for(var i = 0; i < window.puzzleGrid.squaresCount['x']; i++){
var e1 = new Edge(
new Point(i,0),
new Point(i+1,0)
);
e1.add();
var e2 = new Edge(
new Point(i, window.puzzleGrid.squaresCount['y']),
new Point(i+1,window.puzzleGrid.squaresCount['y'])
);
e2.add();
}
for(var j = 0; j < window.puzzleGrid.squaresCount['y']; j++){
var e3 = new Edge(
new Point(0,j),
new Point(0, j+1)
);
e3.add();
var e4 = new Edge(
new Point(window.puzzleGrid.squaresCount['x'], j),
new Point(window.puzzleGrid.squaresCount['x'], j+1)
);
e4.add();
}
}
function createEdgesFromGridSlices(countX, countY){
for(var i = 0; i < countX; i++){
new GridSliceAgent('x');
}
for(var j = 0; j < countY; j++){
new GridSliceAgent('y');
}
return;
}
function Direction(xVal, yVal){
// The intention is for xVal and yVal to be 0, -1 or 1. Perhaps later add code here
// that throws an error if the arguments do not sit within these values.
this.xVal = xVal;
this.yVal = yVal;
this.rightSideOfLine = function(){
// Let's face it: The functionality of this function comes from the fact that I gave up
// on defining a relationship between the direction of travel on the x and y axis
// and a sharp right turn on a web browser's upside-down coordinate system. Now that I've
// got it laid out neatly as an object literal, I can come bakc later and
// refactor it into a nice mathematical function.
// In 'turns', a value of -1 means lowest and 1 means highest. I'll later use these
// values to fill in a sort function for a given point's forking Edges. We want the agent
// to make the sharpest right turn she can at any given junction.
var turnToTest = [this.xVal, this.yVal].toString();
var turns = {
"1,0": {
x: undefined,
y: 1
},
"-1,0": {
x: undefined,
y: -1
},
"0,1": {
x: -1,
y: undefined
},
"0,-1": {
x: 1,
y: undefined
},
"1,1": {
x: -1,
y: 1
},
"1,-1": {
x: 1,
y: 1
},
"-1,1": {
x: -1,
y: -1
},
"-1,-1": {
x: 1,
y: -1
}
}
return turns[turnToTest];
}
}
function Edge(point1, point2){
var _this = this;
this.point1 = point1;
this.point2 = point2;
this.polygons = [];
this.isAtPerimeter = (function(){
var maxY = window.puzzleGrid.squaresCount['y'];
var maxX = window.puzzleGrid.squaresCount['x'];
return(
(_this.point1.y == 0 && _this.point2.y == 0) ||
(_this.point1.x == 0 && _this.point2.x == 0) ||
(_this.point1.y == maxY && _this.point2.y == maxY) ||
(_this.point1.x == maxX && _this.point2.x == maxX)
);
})();
this.maxPolygons = _this.isAtPerimeter ? 1 : 2;
this.add = function(){
allEdges.push(this);
};
this.angleFrom = function(otherEdge){
// There should not be an angle that >= 0. This is because every angle is taken
// as being from between 1 - 180 on a given side (left or right). That is, since I
// so far only consider angles when segregating edges on the basis of being 'left' or 'right'
// of a given edge, I'm only considering angles between 1 - 180 using the reference
// edge as an axis. Any negative angles are taken as obtuse. 0 angles are taken as
// 180.
var convertToAngle = {
"0": 180,
"1": 135,
"Infinity": 90,
"-1": 45
}
var otherSlope = convertToAngle['' + otherEdge.slope];
var thisSlope = convertToAngle['' + this.slope];
var resultAngle = otherSlope - thisSlope;
if(resultAngle <= 0){
return 180 + resultAngle;
}
else{
return resultAngle;
}
}
this.doesItIntersectWithinSquare = function(){
var conflicts = allEdges.filter(function(element){
var currentXs = [_this.point1.x, _this.point2.x];
var currentYs = [_this.point1.y, _this.point2.y];
var otherXs = [element.point1.x, element.point2.x];
var otherYs = [element.point1.y, element.point2.y];
return(
(currentXs.toString() == otherXs.toString() ||
currentXs.toString() == otherXs.reverse().toString()) &&
(currentYs.toString() == otherYs.toString() ||
currentYs.toString() == otherYs.reverse().toString())
);
});
return conflicts.length > 0;
}
this.edgesThatMeetAtPoint = function(point){
// This should really be a method of Point, as it only refers to this Edge once.
// Make sure I'm defining and referring to Points consistently enough that I can do this
// reliably.
var allEdgesButThisOne = allEdges.filter(function(element){
return allEdges.indexOf(element) != allEdges.indexOf(_this);
});
return allEdgesButThisOne.filter(function(element){
return (
((element.point1.x == point.x ) && (element.point1.y == point.y)) ||
((element.point2.x == point.x) && (element.point2.y == point.y))
);
});
}
this.otherPointThan = function(criterionPoint){
return ([this.point1, this.point2].filter(function(edgePoint){
return (edgePoint.x != criterionPoint.x) || (edgePoint.y != criterionPoint.y);
}))[0];
}
this.render = function(colour){
var line = window.puzzleSpace.line(
this.point1.x * window.puzzleGrid.squareSize,
this.point1.y * window.puzzleGrid.squareSize,
this.point2.x * window.puzzleGrid.squareSize,
this.point2.y * window.puzzleGrid.squareSize
);
line.stroke({ width: '1px', color: colour });
}
this.remove = function(){
allEdges.splice(allEdges.indexOf(this), 1);
return;
}
this.slope = (function(){
return (
(_this.point2.y - _this.point1.y)/
(_this.point2.x - _this.point1.x)
);
})();
this.extendedLine = new ExtendedLine(this);
this.whichPerimeter = function(){
var otherAxis = { x: "y", y: "x" };
var onBottomRight = function(axis){
var testAxis = otherAxis[axis];
return window.puzzleGrid.squaresCount[testAxis] == _this.point1[testAxis];
};
var perimeterEdges = {
"y,false":"left",
"y,true": "right",
"x,true": "bottom",
"x,false": "top"
};
if(!this.isAtPerimeter){
return "none";
}
else{
var onWhichAxis = this.point1.x - this.point2.x == 0 ? "y" : "x";
var results = [onWhichAxis, onBottomRight(onWhichAxis)].join(',');
return perimeterEdges[results];
}
}
}
function ExtendedLine(edge){
var _this = this;
this.visibleEdge = edge;
this.yIntercept = (
this.visibleEdge.point1.y - (this.visibleEdge.slope * this.visibleEdge.point1.x)
);
this.getYWithX = function(x){
var ve = this.visibleEdge;
var yIntercept = this.yIntercept;
return (ve.slope * x) + yIntercept;
}
this.getXWithY = function(y){
var ve = this.visibleEdge;
//y = mx+b
//x = (y - b)/m
return (y - this.yIntercept)/this.visibleEdge.slope;
}
this.points = (function(){
var ve = _this.visibleEdge;
// y = mx + b
// b = y - mx
var pnts = [];
if(ve.slope == Infinity){
for(var i = 0; i <= window.puzzleGrid.squaresCount['y']; i ++){
pnts[i] = new Point(ve.point1.x, i);
}
return pnts;
}
for(var i = 0; i < window.puzzleGrid.squaresCount['x'] + 1; i ++){
pnts[i] = new Point(i, _this.getYWithX(i));
}
var pntsOnGrid = pnts.filter(function(element){
return (
(element.x >=0 && element.x <= window.puzzleGrid.squaresCount['x']) &&
(element.y >=0 && element.y <= window.puzzleGrid.squaresCount['y'])
);
});
return pntsOnGrid;
})();
this.getComparisonPoints = function(otherPoint){
// In case you are tempted to replace this code with something that
// iterates through 'x' and 'y', I've tried it, and it makes things confusing without saving
// space!
var slp = Math.abs(_this.visibleEdge.slope);
var resultForX = function(){
if(slp > 0 && slp != Infinity){
var resultingX = _this.getXWithY(otherPoint.y);
return new Point(resultingX, otherPoint.y);
}
else{
return (_this.getPointsByAxis('y', otherPoint.y))[0];
}
}
var resultForY = function(){
if(slp > 0 && slp != Infinity){
var resultingY = _this.getYWithX(otherPoint.x);
return new Point(otherPoint.x, resultingY);
}
else{
return (_this.getPointsByAxis('x', otherPoint.x))[0];
}
}
return {
x: resultForX(),
y: resultForY()
}
}
this.getPointsByAxis = function(axis, value){
return this.points.filter(function(pnt){
return pnt[axis] == value;
});
}
}
function Grid(squaresX, squaresY, squareSizePx){
this.squaresCount = {
x: squaresX,
y: squaresY
}
this.squareSize = squareSizePx;
var gridLineQualities = {
width: '1px',
color: 'rgb(200,200,200)'
}
this.renderForDebug = function(){
var gridLines = window.puzzleSpace.group();
for(var i = 0; i < this.squaresCount['y'] + 1; i++){
var line = window.puzzleSpace.line(
0,
i * this.squareSize,
this.squaresCount['x'] * this.squareSize,
i * this.squareSize
);
gridLines.add(line);
line.stroke(gridLineQualities);
}
for(var j = 0; j < this.squaresCount['x'] + 1; j++){
var line = window.puzzleSpace.line(
j * this.squareSize,
0,
j * this.squareSize,
this.squaresCount['y'] * this.squareSize
);
gridLines.add(line);
line.stroke(gridLineQualities);
}
}
this.renderGuide = function(){
var sc = this.squaresCount;
var ss = this.squareSize;
var guideOffset = {
x: document.body.clientWidth/2 - (sc.x*ss)/2,
y: document.body.clientHeight/2 - (sc.y*ss)/2
};
var gridPerimeter = window.puzzleSpace.group();
gridPerimeter.add(window.puzzleSpace.line(
0 + guideOffset.x,
0 + guideOffset.y,
sc.x*ss + guideOffset.x,
0 + guideOffset.y
).stroke(gridLineQualities));
gridPerimeter.add(window.puzzleSpace.line(
0 + guideOffset.x,
sc.y*ss + guideOffset.y,
sc.x*ss + guideOffset.x,
sc.y*ss + guideOffset.y
).stroke(gridLineQualities));
gridPerimeter.add(window.puzzleSpace.line(
0 + guideOffset.x,
0 + guideOffset.y,
0 + guideOffset.x,
sc.y*ss + guideOffset.y
).stroke(gridLineQualities));
gridPerimeter.add(window.puzzleSpace.line(
sc.x*ss + guideOffset.x,
0 + guideOffset.y,
sc.x*ss + guideOffset.x,
sc.y*ss + guideOffset.y
).stroke(gridLineQualities));
}
}
function GridSliceAgent(axis){
var axis = axis;
var firstCoord = Math.round(Math.random() * window.puzzleGrid.squaresCount[axis]);
var firstPoint = new Point(
axis == 'x' ? 0 : firstCoord,
axis == 'y' ? 0 : firstCoord
)
function chooseRandomEdge(edgeArray){
var indx = Math.round(Math.random() * (edgeArray.length - 1));
var newEdge = edgeArray[indx];
newEdge.add();
return newEdge;
}
function thereIsNoMoreRoomGivenTo(edge){
return edge.point2[axis] == window.puzzleGrid.squaresCount[axis];
}
(function advanceTheAgent(refPoint){
var possibleEdges = possibleNextEdgesFor(refPoint);
if(possibleEdges.length > 0){
var newEdge = chooseRandomEdge(possibleEdges);
}
if(newEdge && !thereIsNoMoreRoomGivenTo(newEdge)){
return advanceTheAgent(newEdge.point2);
}
else{
return;
}
})(firstPoint);
function possibleNextEdgesFor(point1){
var possibleDirections = [-1, 1, 0];
var possibleNextEdges = possibleDirections.map(function(element){
var point2 = new Point (
axis == 'x' ? point1.x + 1 : Math.min(point1.x + element, window.puzzleGrid.squaresCount['y']),
axis == 'y' ? point1.y + 1 : Math.min(point1.y + element, window.puzzleGrid.squaresCount['x'])
);
var point2InGrid = new Point(
Math.min(Math.max(point2.x, 0), window.puzzleGrid.squaresCount.x),
Math.min(Math.max(point2.y, 0), window.puzzleGrid.squaresCount.y)
);
return new Edge(point1, point2InGrid);
});
return possibleNextEdges.filter(function(element){
return !(element.doesItIntersectWithinSquare());
});
}
}
function Point(x,y){
this.x = x;
this.y = y;
}
function Puzzle(){
// I need to make allEdges, allPolygons and allPolygonAgents properties of Puzzle
this.errors = 0;
this.color = getRandomColor();
this.carve = function(){
createEdgesFromGridPerimeter();
// The arguments for this call to 'creatEdgesFromGridSlices' are pretty arbitrary.
// Make them seem less so!
createEdgesFromGridSlices(3, 3);
for(var j = 0; j < allEdges.length; j++){
if(allEdges[j].polygons.length < allEdges[j].maxPolygons){
var agent = new PolygonAgent(allEdges[j]);
agent.activate();
!agent.giveUp || this.recarve();
}
}
}
this.finalize = function(){
for(var i = 0; i < allPolygons.length; i++){
allPolygons[i].render();
}
}
this.recarve = function(){
allEdges = [];
allPolygonAgents = [];
allPolygons = [];
this.errors++;
// The number of errors I let the system tolerate is pretty arbitrary. Make it less so!
// For instance, the probability that a puzzle will encounter an error, and the
// number of errors it'll probably take before the system finds a working puzzle,
// increases with the number of gridSlices and grid squares.
if(this.errors < 100){
this.carve();
}
else{
throw "There've been too many attempts to set up the puzzle. I'm giving up!";
// So far I haven't handled this exception. One way to handle it would be to
// present the user with an option to try producing the puzzle again.
// another would be to display an error message and be all sad and stuff.
}
}
}
function Polygon(edgeArray, pointsObject){
var _this = this;
this.edges = edgeArray;
this.points = pointsObject;
this.color = window.puzzle.color;
allPolygons.push(this);
for(var i = 0; i < this.edges.length; i++){
this.edges[i].polygons.push(this);
}
this.render = function(){
var pointsString = (function(){
// I need a less 'magic' way to specify the initial offsets of each piece.
var initialXOffset = Math.round(Math.random() * (document.body.clientWidth/2));
var initialYOffset = Math.round(Math.random() * (document.body.clientHeight/3));
var strng = '';
for(var i = 0, pnts = _this.points, keys = Object.keys(_this.points); i < keys.length; i++){
var renderedX = (pnts[keys[i]].x * window.puzzleGrid.squareSize) + initialXOffset;
var renderedY = (pnts[keys[i]].y * window.puzzleGrid.squareSize) + initialYOffset;
strng = strng + (renderedX + "," + renderedY + " ");
}
return strng;
})();
this.shape = window.puzzleSpace.polygon(pointsString).fill(this.color).stroke(
{ width: 1, color: "black" }
);
this.shape.node.addEventListener('mousedown', startDrag);
}
function startDrag(mousedownEvent){
mousedownEvent.preventDefault();
// I'm calling 'preventDefault' to avert the browser's own drag event.
window.puzzleSpace.node.addEventListener('mousemove', dragGo);
window.puzzleSpace.node.addEventListener('mouseup', dragStop);
function dragStop(){
window.puzzleSpace.node.removeEventListener('mousemove', dragGo);
}
var mouseInShape = {
x: mousedownEvent.clientX - _this.shape.bbox().x,
y: mousedownEvent.clientY - _this.shape.bbox().y
}
function dragGo(mouseMoveEvent){
var moveTo = {
x: mouseMoveEvent.clientX - mouseInShape.x,
y: mouseMoveEvent.clientY - mouseInShape.y
}
_this.shape.move(moveTo.x, moveTo.y);
}
}
}
function PolygonAgent(startEdge){
var _this = this;
this.edges = [startEdge];
this.startEdge = startEdge;
this.currentEdge = startEdge;
this.points = {};
this.giveUp = false;
allPolygonAgents.push(this);
this.currentDirection = (function getFirstDirection(){
var perimeterEdge = _this.startEdge.whichPerimeter();
var startDirs = {
top: { x: 1, y: 0 },
bottom: { x: -1, y:0 },
left: { x: 0, y: -1 },
right: { x: 0, y: 1 },
none: {
x: _this.startEdge.point2.x - _this.startEdge.point1.x,
y: startEdge.point2.y - startEdge.point1.y
}
}
return new Direction(startDirs[perimeterEdge]['x'], startDirs[perimeterEdge]['y']);
})();
this.forwardPoint = (function(){
// This is the point ahead of the imaginary agent, who sits on currentEdge.
var points = [_this.currentEdge.point1, _this.currentEdge.point2];
var cd = _this.currentDirection;
return points.sort(function(a,b){
if(((a.x * cd.xVal) >= (b.x * cd.xVal)) && ((a.y * cd.yVal) >= (b.y * cd.yVal))){
return -1;
}
else{
return 1;
}
})[0];
})();
this.startPoint = this.startEdge.otherPointThan(_this.forwardPoint);
this.points[0] = this.startPoint;
this.points[1] = this.forwardPoint;
this.trailingEdges = function(){
var allTrailingEdges = this.currentEdge.edgesThatMeetAtPoint(this.forwardPoint);
var trailingEdgesMissingPolygons = allTrailingEdges.filter(function(edg){
return edg.polygons.length < edg.maxPolygons;
});
return trailingEdgesMissingPolygons;
}
this.nextEdge = function(){
var trailingEdges = this.trailingEdges();
var rightTurnDirection = this.currentDirection.rightSideOfLine();
// Map trailingEdges into an array of points other than the forwardPoint where the
// trailingEdges meet.
var edgesOnTheRight = trailingEdges.filter(function(edg){
// First, choose two points from the line that extends through currentEdge.
// One point corresponds with distalPoint's x value, one with distalPoint's y value.
var distalPoint = edg.otherPointThan(_this.forwardPoint);
var comparisonPointsFor = _this.currentEdge.extendedLine.getComparisonPoints(distalPoint);
// Second, see which axes we're comparing to distalPoint. Horizontal or vertical lines
// only require comparison along one axis. I.e. only one axis might have a rightTurn.
var criteriaAxes = ['x','y'].filter(function(axis){
return rightTurnDirection[axis];
});
// Third, see if distalPoint lies above/below the testLine at its x and y values,
// depending on which axes are available to test. Sort the points that sit on the 'right'
// side of the testLine into one array (this includes points on the testLine).
var testAxes = criteriaAxes.filter(function(axis){
var criterionValue = comparisonPointsFor[axis][axis];
return (
(distalPoint[axis] * rightTurnDirection[axis]) >=
(criterionValue * rightTurnDirection[axis])
);
});
return testAxes.length == criteriaAxes.length;
});
// Fourth, sort the points on the 'left' of the line into another array.
var edgesOnTheLeft = trailingEdges.filter(function(edg){
return edgesOnTheRight.indexOf(edg) == -1;
});
var rightEdgesByAcuteAngle = edgesOnTheRight.sort(function(a,b){
return _this.currentEdge.angleFrom(a) - _this.currentEdge.angleFrom(b);
});
var leftEdgesByObtuseAngle = edgesOnTheLeft.sort(function(a,b){
return _this.currentEdge.angleFrom(b) - _this.currentEdge.angleFrom(a);
});
var chosenEdge = (
rightEdgesByAcuteAngle.length > 0 ? rightEdgesByAcuteAngle[0] : leftEdgesByObtuseAngle[0]
);
return chosenEdge;
}
this.activate = function(){
var nextEdge = this.nextEdge();
// I'm including the below 'if' block, as well as the whole 'Puzzle' object and its
// associated 'carve', 'finalize', and 'recarve' methods, because every now and then,
// 'nextEdge' comes up as undefined or the PolygonAgent goes astray. I'm not sure why
// this happens. For some reason, there are times when the initial Edge within a
// PolygonAgent has fewer than its maxPolygons, but some of the following Edges
// have reached their polygon limit. In these moments, if I filter out
// Edges that have reached .maxPolygons in 'this.trailingEdges', the PolygonAgent
// will see the rightmost Edge as one that's patently not to the 'right' at all. In these
// moments, there's a recursion issue and the whole enterprise has to be abandoned.
if(nextEdge == undefined || this.edges.length > 25){
this.giveUp = true;
return;
}
if(_this.forwardPoint.x == _this.startPoint.x &&
_this.forwardPoint.y == _this.startPoint.y){
var newPolygon = new Polygon(this.edges, this.points);
}
else{
var oldForwardPoint = this.forwardPoint;
this.edges.push(nextEdge);
this.currentEdge = nextEdge;
this.forwardPoint = nextEdge.otherPointThan(oldForwardPoint);
_this.points[Object.keys(_this.points).length] = _this.forwardPoint;
this.currentDirection = new Direction(
this.forwardPoint.x - oldForwardPoint.x,
this.forwardPoint.y - oldForwardPoint.y
);
_this.activate();
}
}
}
window.onload = function(){
window.puzzleGrid = new Grid(10, 10, 20);
window.puzzleSpace = SVG('puzzleSpace').size('100%', '100%');
window.puzzleGrid.renderGuide();
window.puzzle = new Puzzle();
window.puzzle.carve();
window.puzzle.finalize();
}