-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathAnimCube7.js
More file actions
3193 lines (3074 loc) · 104 KB
/
Copy pathAnimCube7.js
File metadata and controls
3193 lines (3074 loc) · 104 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
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @author Josef Jelinek
* @version 3.5b
* 7x7x7 Cube by Marcelo Falcão de Oliveira
*/
"use strict";
function AnimCube7(params) {
var cubeDim = 7;
// external configuration
var config = [];
// background colors
var bgColor;
var hlColor;
var textColor;
var buttonBgColor;
var sliderColor; // progress bar
var sliderBgColor;
var buttonBorderColor;
var cubeColor;
// cube colors
var colors = [];
// cube facelets
var cube = [];
var scube = [];
var initialCube = [];
var initialSCube = [];
// normal vectors
var faceNormals = [
[ 0.0, -1.0, 0.0], // U
[ 0.0, 1.0, 0.0], // D
[ 0.0, 0.0, -1.0], // F
[ 0.0, 0.0, 1.0], // B
[-1.0, 0.0, 0.0], // L
[ 1.0, 0.0, 0.0] // R
];
// vertex co-ordinates
var cornerCoords = [
[-1.0, -1.0, -1.0], // UFL
[ 1.0, -1.0, -1.0], // UFR
[ 1.0, -1.0, 1.0], // UBR
[-1.0, -1.0, 1.0], // UBL
[-1.0, 1.0, -1.0], // DFL
[ 1.0, 1.0, -1.0], // DFR
[ 1.0, 1.0, 1.0], // DBR
[-1.0, 1.0, 1.0] // DBL
];
// vertices of each face
var faceCorners = [
[0, 1, 2, 3], // U: UFL UFR UBR UBL
[4, 7, 6, 5], // D: DFL DBL DBR DFR
[0, 4, 5, 1], // F: UFL DFL DFR UFR
[2, 6, 7, 3], // B: UBR DBR DBL UBL
[0, 3, 7, 4], // L: UFL UBL DBL DFL
[1, 5, 6, 2] // R: UFR DFR DBR UBR
];
// corresponding corners on the opposite face
var oppositeCorners = [
[0, 3, 2, 1], // U->D
[0, 3, 2, 1], // D->U
[3, 2, 1, 0], // F->B
[3, 2, 1, 0], // B->F
[0, 3, 2, 1], // L->R
[0, 3, 2, 1], // R->L
];
// faces adjacent to each face
var adjacentFaces = [
[2, 5, 3, 4], // U: F R B L
[4, 3, 5, 2], // D: L B R F
[4, 1, 5, 0], // F: L D R U
[5, 1, 4, 0], // B: R D L U
[0, 3, 1, 2], // L: U B D F
[2, 1, 3, 0] // R: F D B U
];
// current twisted layer
var twistedLayer;
var twistedMode;
// directions of facelet cycling for all faces
var faceTwistDirs = [1, 1, -1, -1, -1, -1];
// initial observer co-ordinate axes (view)
var eye = [0.0, 0.0, -1.0];
var eyeX = [1.0, 0.0, 0.0]; // (sideways)
var eyeY = []; // (vertical)
var initialEye = [];
var initialEyeX = [];
var initialEyeY = [];
// angle of rotation of the twistedLayer
var currentAngle; // edited angle of twisted layer
var originalAngle; // angle of twisted layer
// animation speed
var speed;
var doubleSpeed;
// current state of the program
var natural = true; // cube is compact, no layer is twisted
var toTwist; // layer can be twisted
var interrupted; // thread was interrupted
var restarted; // animation was stopped
var mirrored; // mirroring of the cube view
var editable; // editation of the cube with a mouse
var repeatable; // allow repetition of sequence
var clickProgress; // allow advance by clicking progress bar
var twisting; // a user twists a cube layer
var spinning; // an animation twists a cube layer
var animating; // animation run
var dragging; // progress bar is controlled
var demo; // demo mode
var persp; // perspective deformation
var scale; // cube scale
var align; // cube alignment (top, center, bottom)
var hint;
var faceShift;
var hintHoriz;
var hintVert;
var hintBorder;
var moveCounter;
// move sequence data
var move = [];
var demoMove = [];
var initialMove = [];
var initialReversedMove = [];
var curMove;
var movePos;
var moveDir;
var moveOne;
var moveAnimated;
var metric;
var infoText = [];
var curInfoText;
// state of buttons
var buttonBar; // button bar mode
var buttonHeight;
var drawButtons = true;
// including buttonSymbolScale
var buttonSymbolScale = 1.0;
var pushed;
var buttonPressed = -1;
var progressHeight = 6;
var textHeight = 12;
var moveText;
var moveTextSpace;
var outlined = true;
var snap = false;
var signNotation;
var wcaNotation;
var yzAlt;
var superCube = false;
var scrambleToggle = false;
var scramble = 0;
var randMoveCount = 0;
var scw = 0;
var borderWidth = 0;
var rotateAllowed = 1;
// transformation tables for compatibility with Lars's applet
var posFaceTransform = [3, 2, 0, 5, 1, 4];
var posFaceletTransform = [
[42,35,28,21,14,7,0,43,36,29,22,15,8,1,44,37,30,23,16,9,2,45,38,31,24,17,10,3,46,39,32,25,18,11,4,47,40,33,26,19,12,5,48,41,34,27,20,13,6], // B
[6,13,20,27,34,41,48,5,12,19,26,33,40,47,4,11,18,25,32,39,46,3,10,17,24,31,38,45,2,9,16,23,30,37,44,1,8,15,22,29,36,43,0,7,14,21,28,35,42], // F
[0,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], // U
[0,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], // R
[42,35,28,21,14,7,0,43,36,29,22,15,8,1,44,37,30,23,16,9,2,45,38,31,24,17,10,3,46,39,32,25,18,11,4,47,40,33,26,19,12,5,48,41,34,27,20,13,6], // D
[0,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] // L
];
function onModuleLoad() {
var fname = getParameter("config");
if (fname != null)
loadConfigFile(fname);
else {
init();
}
}
// setup default configuration
function loadConfigFile(file) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = handler;
xhr.open('GET', file, true);
xhr.send();
function handler() {
if (xhr.readyState == 4) {
if (xhr.status == 200)
parseConfigFile(xhr.responseText);
else
console.log('Error loading config file: ' + file);
init();
}
}
}
function parseConfigFile(text) {
var lines = text.split('\n');
for (var i = 0; i < lines.length; i++) {
var line = lines[i].split('=');
if (typeof line[1] != 'undefined')
config[line[0].trim()] = line[1].trim();
}
}
function init() {
// setup colors
colors[0] = rgbToHex(255, 128, 64); // 0 - light orange
colors[1] = rgbToHex(255, 0, 0); // 1 - pure red
colors[2] = rgbToHex( 0, 255, 0); // 2 - pure green
colors[3] = rgbToHex( 0, 0, 255); // 3 - pure blue
colors[4] = rgbToHex(153, 153, 153); // 4 - white grey
colors[5] = rgbToHex(170, 170, 68); // 5 - yellow grey
colors[6] = rgbToHex(187, 119, 68); // 6 - orange grey
colors[7] = rgbToHex(153, 68, 68); // 7 - red grey
colors[8] = rgbToHex(68, 119, 68); // 8 - green grey
colors[9] = rgbToHex(0, 68, 119); // 9 - blue grey
colors[10] = rgbToHex(255, 255, 255); // W - white
colors[11] = rgbToHex(255, 255, 0); // Y - yellow
colors[12] = rgbToHex(255, 96, 32); // O - orange
colors[13] = rgbToHex(208, 0, 0); // R - red
colors[14] = rgbToHex(0, 144, 0); // G - green
colors[15] = rgbToHex(32, 64, 208); // B - blue
colors[16] = rgbToHex(176, 176, 176); // L - light gray
colors[17] = rgbToHex( 80, 80, 80); // D - dark gray
colors[18] = rgbToHex(255, 0, 255); // M - magenta
colors[19] = rgbToHex( 0, 255, 255); // C - cyan
colors[20] = rgbToHex(255, 160, 192); // P - pink
colors[21] = rgbToHex(32, 255, 16); // N - light green
colors[22] = rgbToHex( 0, 0, 0); // K - black
colors[23] = rgbToHex(128, 128, 128); // . - gray
// setup window background color
var param = getParameter("bgcolor");
if (param != null && param.length == 6) {
if (validateColor(param))
bgColor = "#" + param;
else
bgColor = "gray";
}
else
bgColor = "gray";
// setup button bar background color
param = getParameter("butbgcolor");
if (param != null && param.length == 6) {
if (validateColor(param))
buttonBgColor = "#" + param;
else
buttonBgColor = bgColor;
}
else
buttonBgColor = bgColor;
// custom colors
param = getParameter("colors");
if (param != null) {
for (var i = 0, j = 0; i < 10 && j < param.length; i++, j+=6) {
var s = param.substr(j, 6);
if (s.length == 6 && validateColor(s))
colors[i] = "#" + s;
}
}
// clean the cube
for (var i = 0; i < 6; i++)
for (var j = 0; j < 49; j++)
cube[i][j] = i + 10;
param = getParameter("supercube");
if (param != null)
if ("1" == (param)) {
superCube = true;
setBorderWidth(.06);
// change white to black for default colorscheme
for (var i = 0; i < 49; i++)
cube[0][i] = 22;
param = getParameter("scw");
if (param != null) {
if ("1" == (param))
scw = 1;
else if ("2" == (param))
scw = 2;
}
if (scw == 1)
colors[10] = "#000000";
}
param = getParameter("gabbacolors");
if (param != null)
if ("1" == (param)) {
if (superCube == true) {
colors[11] = "#fdcf00"; // Y - yellow
colors[12] = "#fd4e0a"; // O - orange
colors[13] = "#93000d"; // R - red
colors[14] = "#00702d"; // G - green
colors[15] = "#00347a"; // B - blue
}
else {
setBorderWidth(.06);
colors[11] = "#ffd90a"; // Y
colors[12] = "#ff4f0b"; // O
colors[13] = "#9e0b19"; // R
colors[14] = "#0b7d39"; // G
colors[15] = "#0b4186"; // B
}
}
param = getParameter("borderwidth");
if (param != null) {
for (var i = 0; i < param.length; i++)
if (param.charAt(i) >= '0' && param.charAt(i) <= '9')
borderWidth = borderWidth * 10 + parseInt(param[i]);
if (borderWidth >= 0 && borderWidth <= 20)
setBorderWidth(borderWidth / 100);
}
// clean the supercube
if (superCube) {
for (var i = 0; i < 6; i++)
for (var j = 0; j < 49; j++)
scube[i][j] = 0;
}
var initialPosition = "lluu";
// setup color configuration of the solved cube
param = getParameter("colorscheme");
if (param != null && param.length == 6) {
for (var i = 0; i < 6; i++) { // udfblr
var color = 23;
for (var j = 0; j < 23; j++) {
if (param[i].toLowerCase() == "0123456789wyorgbldmcpnk".charAt(j)) {
color = j;
break;
}
}
for (var j = 0; j < 49; j++)
cube[i][j] = color;
}
}
param = getParameter("scramble");
if ("1" == (param))
scramble = 1;
else if ("2" == (param))
scramble = 2;
if (scramble == 0) {
// setup facelets - compatible with Lars's applet
param = getParameter("pos");
if (param != null && param.length == 294) {
initialPosition = "uuuuff";
if (bgColor == "gray")
bgColor = "white";
for (var i = 0; i < 6; i++) {
var ti = posFaceTransform[i];
for (var j = 0; j < 49; j++) {
var tj = posFaceletTransform[i][j];
cube[ti][tj] = 23;
for (var k = 0; k < 14; k++) {
// "abcdefgh" ~ "gbrwoyld"
if (param.charAt(i * 49 + j) == "DFECABdfecabgh".charAt(k)) {
cube[ti][tj] = k + 4;
break;
}
}
}
}
}
// setup color facelets
param = getParameter("facelets");
if (param != null && param.length == 294) {
for (var i = 0; i < 6; i++) {
for (var j = 0; j < 49; j++) {
cube[i][j] = 23;
for (var k = 0; k < 23; k++) {
if (param[i * 49 + j].toLowerCase() == "0123456789wyorgbldmcpnk".charAt(k)) {
cube[i][j] = k;
break;
}
}
}
}
}
// setup supercube facelet twist
param = getParameter("superfacelets");
if (param != null && param.length == 294) {
for (var i = 0; i < 6; i++) {
for (var j = 0; j < 49; j++) {
for (var k = 0; k < 4; k++) {
if (param[i * 49 + j].toLowerCase() == "0123".charAt(k)) {
scube[i][j] = k;
break;
}
}
}
}
}
}
moveText = 0;
yzAlt = false;
signNotation = false;
param = getParameter("sign");
if (param != null)
if ("1" == param) {
signNotation = true;
moveText = 5;
yzAlt = true;
}
wcaNotation = false;
param = getParameter("wca");
if (param != null)
if ("1" == param) {
wcaNotation = true;
moveText = 6;
yzAlt = true;
}
param = getParameter("yz");
if (param != null)
if ("0" == param)
yzAlt = false;
else if ("1" == param)
yzAlt = true;
param = getParameter("randmoves");
if (param != null) {
var rm = 0;
for (var i = 0; i < param.length; i++)
if (param.charAt(i) >= '0' && param.charAt(i) <= '9')
rm = rm * 10 + parseInt(param[i]);
if (rm > 0)
randMoveCount = rm;
}
// setup move sequence (and info texts)
param = getParameter("move");
if ("random" == (param) || scramble > 0)
param = randMoves(7, randMoveCount);
move = (param == null ? [] : getMove(param, true));
movePos = 0;
curInfoText = -1;
// setup initial move sequence
if (scramble == 0) {
param = getParameter("initmove");
if (param != null) {
if ("random" == (param))
param = randMoves(7, randMoveCount);
initialMove = param == ("#") ? move : getMove(param, false);
}
// setup initial reversed move sequence
param = getParameter("initrevmove");
if (param != null) {
if ("random" == (param))
param = randMoves(7, randMoveCount);
initialReversedMove = param == ("#") ? move : getMove(param, false);
}
// setup demo move sequence
param = getParameter("demo");
if (param != null) {
if ("random" == (param))
param = randMoves(7, randMoveCount);
demoMove = param == ("#") ? move : getMove(param, true);
if (demoMove.length > 0 && demoMove[0].length > 0)
demo = true;
}
}
// setup initial cube position
param = getParameter("position");
vNorm(vMul(eyeY, eye, eyeX));
if (param == null)
param = initialPosition;
var pi12 = Math.PI / 12;
for (var i = 0; i < param.length; i++) {
var angle = pi12;
switch (param[i].toLowerCase()) {
case 'd':
angle = -angle;
case 'u':
vRotY(eye, angle);
vRotY(eyeX, angle);
break;
case 'f':
angle = -angle;
case 'b':
vRotZ(eye, angle);
vRotZ(eyeX, angle);
break;
case 'l':
angle = -angle;
case 'r':
vRotX(eye, angle);
vRotX(eyeX, angle);
break;
}
}
vNorm(vMul(eyeY, eye, eyeX)); // fix eyeY
// setup quarter-turn speed and double-turn speed
speed = 0;
doubleSpeed = 0;
param = getParameter("speed");
if (param != null)
for (var i = 0; i < param.length; i++)
if (param.charAt(i) >= '0' && param.charAt(i) <= '9')
speed = speed * 10 + parseInt(param[i]);
param = getParameter("doublespeed");
if (param != null)
for (var i = 0; i < param.length; i++)
if (param.charAt(i) >= '0' && param.charAt(i) <= '9')
doubleSpeed = doubleSpeed * 10 + parseInt(param[i]);
if (speed == 0)
speed = 10;
if (doubleSpeed == 0)
doubleSpeed = speed * 3 / 2;
// perspective deformation
persp = 0;
param = getParameter("perspective");
if (param == null)
persp = 2;
else
for (var i = 0; i < param.length; i++)
if (param.charAt(i) >= '0' && param.charAt(i) <= '9')
persp = persp * 10 + parseInt(param[i]);
// cube scale
var varscale = 0;
param = getParameter("scale");
if (param != null)
for (var i = 0; i < param.length; i++)
if (param.charAt(i) >= '0' && param.charAt(i) <= '9')
varscale = varscale * 10 + parseInt(param[i]);
scale = 1.0 / (1.0 + varscale / 10.0);
// hint displaying
hint = false;
param = getParameter("hint");
if (param != null) {
hint = true;
faceShift = 0.0;
for (var i = 0; i < param.length; i++)
if (param.charAt(i) >= '0' && param.charAt(i) <= '9')
faceShift = faceShift * 10 + parseInt(param[i]);
if (faceShift < 1.0)
hint = false;
else
faceShift /= 10.0;
}
hintHoriz = 3.7;
param = getParameter("hinthoriz");
if (param != null) {
var n = parseFloat(param);
if (n > 0)
hintHoriz = n;
}
hintVert = 3.7;
param = getParameter("hintvert");
if (param != null) {
var n = parseFloat(param);
if (n > 0)
hintVert = n;
}
hintBorder = 0;
param = getParameter("hintborder");
if (param != null)
if (param == "1")
hintBorder = 1;
// appearance and configuration of the button bar
buttonHeight = 13;
param = getParameter("buttonheight");
if (param != null) {
var n = parseInt(param);
if (n >= 9 & n <= 25)
buttonHeight = n;
}// get button symbols' scale, default = 1, 0.5 min., 2.5 max. according to buttonHeight
param = getParameter("butsymbolscale");
if (param != null) {
var n = parseFloat(param);
if (n > 0) {
if (n < 0.5 || n > 2.5) {n = 1.0}
if (n > 1+(buttonHeight-9)*0.09375) {n = 1+(buttonHeight-9)*0.09375}
buttonSymbolScale = n;
}
}
progressHeight = move.length == 0 ? 0 : 6;
buttonBar = 1;
param = getParameter("buttonbar");
if ("0" == (param)) {
buttonBar = 0;
buttonHeight = 0;
progressHeight = 0;
}
else if ("1" == (param))
buttonBar = 1;
else if ("2" == (param) || move.length == 0) {
buttonBar = 2;
progressHeight = 0;
}
// whether the cube can be edited with mouse
param = getParameter("edit");
if ("0" == (param))
editable = false;
else
editable = true;
// whether the sequence can be repeated
param = getParameter("repeat");
if ("0" == (param))
repeatable = false;
else
repeatable = true;
// whether clicking on the progress bar advances through the sequence
param = getParameter("clickprogress");
if ("0" == (param))
clickProgress = false;
else
clickProgress = true;
// displaying the textual representation of the move
param = getParameter("movetext");
if ("0" == (param))
moveText = 0;
else if ("1" == (param))
moveText = 1;
else if ("5" == (param))
moveText = 5;
else if ("6" == (param))
moveText = 6;
moveTextSpace = 1;
param = getParameter("movetextspace");
if ("0" == (param))
moveTextSpace = 0;
// how texts are displayed
param = getParameter("textsize");
if (param != null) {
var n = parseInt(param);
if (n >= 5 & n <= 40)
textHeight = n;
}
param = getParameter("fonttype");
if (param == null || "1" == (param))
outlined = true;
else
outlined = false;
// metric
metric = 0;
param = getParameter("metric");
if (param != null) {
if ("1" == (param)) // quarter-turn
metric = 1;
else if ("2" == (param)) // face-turn
metric = 2;
else if ("3" == (param)) // slice-turn
metric = 3;
}
align = 1;
param = getParameter("align");
if (param != null) {
// 0 = top, 1 = center, 2 = bottom
var n = parseInt(param);
if (n >= 0 & n <= 3)
align = n;
if (n >= 3 & n <= 99)
align = n / 100;
}
param = getParameter("snap");
if (param != null)
if ("1" == (param))
snap = true;
// setup initial values
for (var i = 0; i < 6; i++)
for (var j = 0; j < 49; j++) {
initialCube[i][j] = cube[i][j];
initialSCube[i][j] = scube[i][j];
}
if (initialMove.length > 0)
doMove(cube, initialMove[0], 0, initialMove[0].length, false);
if (initialReversedMove.length > 0)
doMove(cube, initialReversedMove[0], 0, initialReversedMove[0].length, true);
if (scramble == 2)
doMove(cube, move[0], 0, move[0].length, true);
for (var i = 0; i < 3; i++) {
initialEye[i] = eye[i];
initialEyeX[i] = eyeX[i];
initialEyeY[i] = eyeY[i];
}
// setup colors (contrast)
if (colorAverage(bgColor) < 128) {
textColor = "white";
hlColor = brighter(bgColor);
}
else {
textColor = "black";
hlColor = darker(bgColor);
}
if (colorAverage(buttonBgColor) < 128)
buttonBorderColor = "white";
else
buttonBorderColor = "black";
sliderColor = textColor;
param = getParameter("slidercolor");
if (param != null && param.length == 6) {
if (validateColor(param))
sliderColor = "#" + param;
}
sliderBgColor = darker(bgColor);
param = getParameter("sliderbgcolor");
if (param != null && param.length == 6) {
if (validateColor(param))
sliderBgColor = "#" + param;
}
param = getParameter("troughcolor");
if (param != null && param.length == 6) {
if (validateColor(param))
sliderBgColor = "#" + param;
}
cubeColor = "black";
param = getParameter("cubecolor");
if (param != null && param.length == 6) {
if (validateColor(param))
cubeColor = "#" + param;
}
moveCounter = 1;
param = getParameter("counter");
if ("0" == param)
moveCounter = 0;
curInfoText = (move.length > 0 && move[0][0] >= 1000) ? 0 : -1;
init2();
if (demo)
startAnimation(-1);
} // init()
function getParameter(s) {
var uparam = searchParams[s];
if (typeof uparam == 'undefined')
return config[s];
return uparam;
}
function setBorderWidth(w) {
border[0][0] = border[0][1] = border[1][1] = border[3][0] = w;
border[1][0] = border[2][0] = border[2][1] = border[3][1] = 1.0 - w;
}
var moveModes = [
0, 0, 0, 0, 0, 0, // UDFBLR
7, 7, 7, // ESM
3, 3, 3, 3, 3, 3, // XYZxyz
2, 2, 2, 2, 2, 2 // udfblr
];
var moveCodes = [
0, 1, 2, 3, 4, 5, // UDFBLR
1, 2, 4, // ESM
5, 2, 0, 5, 2, 0, // XYZxyz
0, 1, 2, 3, 4, 5 // udfblr
];
function getMove(sequence, info) {
if (info) {
var inum = 0;
var pos = sequence.indexOf('{');
while (pos != -1) {
inum++;
pos = sequence.indexOf('{', pos + 1);
}
if (infoText == null) {
curInfoText = 0;
infoText = [];
}
else {
var infoText2 = [];
for (var i = 0; i < infoText.length; i++)
infoText2[i] = infoText[i];
curInfoText = infoText.length;
infoText = infoText2;
}
}
var num = 1;
var pos = sequence.indexOf(';');
while (pos != -1) {
num++;
pos = sequence.indexOf(';', pos + 1);
}
var mv = [];
var lastPos = 0;
pos = sequence.indexOf(';');
num = 0;
while (pos != -1) {
mv[num] = getMovePart(sequence.substring(lastPos, pos), info, num++);
lastPos = pos + 1;
pos = sequence.indexOf(';', lastPos);
}
mv[num] = getMovePart(sequence.substring(lastPos), info, num);
return mv;
}
var modeChar = ['n', 't', 'c', 's', 'a', 'o', 'm', 'u'];
function getMovePart(sequence, info, num) {
if (wcaNotation) {
sequence = wca_to_sign(sequence);
sequence = convertNotation7(sequence);
}
else if (signNotation)
sequence = convertNotation7(sequence);
if (sequence.trim() == '#')
if (typeof move[num] != 'undefined')
return(move[num]);
var length = 0;
var mv = [];
var moveCodeString = "UDFBLRESMXYZxyzudfblr";
if (yzAlt == true)
moveCodeString = "UDFBLRESMXZYxzyudfblr";
for (var i = 0; i < sequence.length; i++) {
if (sequence.charAt(i) == '.') {
mv[length] = -1;
length++;
}
else if (sequence.charAt(i) == '{') {
i++;
var s = "";
while (i < sequence.length) {
if (sequence.charAt(i) == '}')
break;
if (info)
s += sequence.charAt(i);
i++;
}
if (info) {
infoText[curInfoText] = s;
mv[length] = 1000 + curInfoText;
curInfoText++;
length++;
}
}
else {
for (var j = 0; j < 21; j++) {
// if (sequence.charAt(i) == "UDFBLRESMXYZxyzudfblr".charAt(j)) {
if (sequence.charAt(i) == moveCodeString.charAt(j)) {
i++;
var mode = moveModes[j];
mv[length] = moveCodes[j] * 4 * (modeChar.length + 1);
if (i < sequence.length) {
if (moveModes[j] == 0) { // modifiers for basic characters UDFBLR
for (var k = 0; k < modeChar.length; k++) {
if (sequence.charAt(i) == modeChar[k]) {
mode = k + 1;
i++;
break;
}
}
}
}
mv[length] += mode * 4;
if (i < sequence.length) {
if (sequence.charAt(i) == '1')
i++;
else if (sequence.charAt(i) == '\'' || sequence.charAt(i) == '3') {
mv[length] += 2;
i++;
}
else if (sequence.charAt(i) == '2') {
i++;
if (i < sequence.length && sequence.charAt(i) == '\'') {
mv[length] += 3;
i++;
}
else
mv[length] += 1;
}
}
length++;
i--;
break;
}
}
}
}
return mv;
}
function convertNotation7(s) {
s = replaceMoves(s, 2, 'n', 0);
s = replaceMoves(s, 3, 'o', 0);
s = replaceMoves(s, 4, 'm', 0);
s = replaceMoves(s, 2, 't', 1);
s = replaceMoves(s, 3, 'u', 1);
return s;
}
var faces = ['U', 'D', 'F', 'B', 'L', 'R'];
function replaceMoves(s, a, b, t) {
for (var i=0; i < 6; i++) {
var f = (t==0) ? faces[i] : faces[i].toLowerCase();
var r = new RegExp(a + f, "g");
s = s.replace(/\{[^}]*\}|[^{}]+/g, (trecho) => {
// If it starts with {, it is an info box then leave as it is
if (trecho.startsWith("{")) return trecho;
// otherwise, apply the replacements
return trecho
.replace(r, faces[i] + b);
});
}
return s;
}
function wca_to_sign(s) {
for (var i=0; i < 6; i++) {
var r = new RegExp(faces[i] + 'w', "g");
s = s.replace(/\{[^}]*\}|[^{}]+/g, (trecho) => {
// If it starts with {, it is an info box then leave as it is
if (trecho.startsWith("{")) return trecho;
// otherwise, apply the replacements
return trecho
.replace(r, faces[i].toLowerCase());
});
}
return s;
}
function moveTextFunc(move, start, end) {
if (start >= move.length)
return "";
var s = "";
for (var i = start; i < end; i++) {
var t = turnTextFunc(move, i);
if (t != '')
s += t + (moveTextSpace ? ' ' : '');
}
return s;
}
var turnSymbol = [
[ // "standard" notation
["U", "D", "F", "B", "L", "R"],
["Un", "Dn", "Fn", "Bn", "Ln", "Rn"],
["Ut", "Dt", "Ft", "Bt", "Lt", "Rt"],
["Uc", "Dc", "Fc", "Bc", "Lc", "Rc"],
["Us", "Ds", "Fs", "Bs", "Ls", "Rs"],
["Ua", "Da", "Fa", "Ba", "La", "Ra"],
["Uo", "Do", "Fo", "Bo", "Lo", "Ro"],
["Um", "Dm", "Fm", "Bm", "Lm", "Rm"],
["Uu", "Du", "Fu", "Bu", "Lu", "Ru"]
],
[ // "reduced" notation
["U", "D", "F", "B", "L", "R"],
["Un", "Dn", "Fn", "Bn", "Ln", "Rn"],
["u", "d", "f", "b", "l", "r"],
["Z", "~Z", "Y", "~Y", "~X", "X"],
["Us", "Ds", "Fs", "Bs", "Ls", "Rs"],
["Ua", "Da", "Fa", "Ba", "La", "Ra"],
["Uo", "Do", "Fo", "Bo", "Lo", "Ro"],
["~E", "E", "S", "~S", "M", "~M"]
],
[ // "reduced" notation - swapped Y and Z
["U", "D", "F", "B", "L", "R"],
["Un", "Dn", "Fn", "Bn", "Ln", "Rn"],
["u", "d", "f", "b", "l", "r"],
["Y", "~Y", "Z", "~Z", "~X", "X"],
["Us", "Ds", "Fs", "Bs", "Ls", "Rs"],
["Ua", "Da", "Fa", "Ba", "La", "Ra"],
["Uo", "Do", "Fo", "Bo", "lo", "Ro"],
["~E", "E", "S", "~S", "M", "~M"]
],
[ // another reduced notation
["U", "D", "F", "B", "L", "R"],
["Un", "Dn", "Fn", "Bn", "Ln", "Rn"],
["Uu", "Dd", "Ff", "Bb", "Ll", "Rr"],
["QU", "QD", "QF", "QB", "QL", "QR"],
["UD'", "DU'", "FB'", "BF'", "LR'", "RL'"],
["UD", "DU", "FB", "BF", "LR", "RL"],
["Uo", "Do", "Fo", "Bo", "Lo", "Ro"],
["u", "d", "f", "b", "l", "r"]
],
[ // SiGN
["U", "D", "F", "B", "L", "R"],
["2U", "2D", "2F", "2B", "2L", "2R"],
["u", "d", "f", "b", "l", "r"],
["y", "~y", "z", "~z", "~x", "x"],
["Us", "Ds", "Fs", "Bs", "Ls", "Rs"],
["Ua", "Da", "Fa", "Ba", "La", "Ra"],
["3U", "3D", "3F", "3B", "3L", "3R"],
["~E", "E", "S", "~S", "M", "~M"],
["3u", "3d", "3f", "3b", "3l", "3r"]
],
[ // WCA
["U", "D", "F", "B", "L", "R"],
["2U", "2D", "2F", "2B", "2L", "2R"],
["Uw", "Dw", "Fw", "Bw", "Lw", "Rw"],
["y", "~y", "z", "~z", "~x", "x"],
["Us", "Ds", "Fs", "Bs", "Ls", "Rs"],
["Ua", "Da", "Fa", "Ba", "La", "Ra"],
["3U", "3D", "3F", "3B", "3L", "3R"],
["~E", "E", "S", "~S", "M", "~M"],
["3Uw", "3Dw", "3Fw", "3Bw", "3Lw", "3Rw"]
]
];
var modifierStrings = ["", "2", "'", "2'"];
function turnTextFunc(move, pos) {
if (pos >= move.length)
return "";
if (move[pos] >= 1000)
return "";
if (move[pos] == -1)
return ".";
var s = turnSymbol[moveText - 1][Math.floor(move[pos] / 4) % (modeChar.length + 1)][Math.floor(move[pos] / 4 / (modeChar.length + 1))];
if (s.charAt(0) == '~')
return s.substring(1) + modifierStrings[(move[pos] + 2) % 4];
return s + modifierStrings[move[pos] % 4];
}
var metricChar = ["", "q", "h", "s"];
function realMoveLength(move) {
var length = 0;
for (var i = 0; i < move.length; i++)
if (move[i] < 1000)
length++;
return length;
}
function realMovePos(move, pos) {
var rpos = 0;
for (var i = 0; i < pos; i++)
if (move[i] < 1000)
rpos++;