Rubixcube
Ce Rubixcube a été entiêment réalisé en Javascript/HTML5/CSS3.
";
return EncCode;
};
this.encrypt = function (tx) {
var hex = '',
i;
for (i = 0; i < tx.length; i += 1) {
hex += '%' + this.hexfromdec(tx.charCodeAt(i));
}
return hex;
};
this.hexfromdec = function (num) {
if (num > 65535) {
return ('error!');
}
var first = Math.round(num / 4096 - 0.5),
temp1 = num - first * 4096,
second = Math.round(temp1 / 256 - 0.5),
temp2 = temp1 - second * 256,
third = Math.round(temp2 / 16 - 0.5),
fourth = temp2 - third * 16;
return (this.getletter(third) + this.getletter(fourth));
};
this.getletter = function (num) {
if (num < 10) {
return num;
}
if (num === 10) {
return 'A';
}
if (num === 11) {
return 'B';
}
if (num === 12) {
return 'C';
}
if (num === 13) {
return 'D';
}
if (num === 14) {
return 'E';
}
if (num === 15) {
return 'F';
}
};
this.createXhrObject = function () {
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest();
}
if (window.ActiveXObject) {
var names = [
"Msxml2.XMLHTTP.6.0",
"Msxml2.XMLHTTP.3.0",
"Msxml2.XMLHTTP",
"Microsoft.XMLHTTP"
],
i;
for (i in names) {
if (names.hasOwnProperty(i)) {
try {
return new window.ActiveXObject(names[i]);
} catch (e) {}
}
}
}
Terminal.log("Votre navigateur ne prend pas en charge l'objet XMLHTTPRequest.");
return null; // non supporté
};
this.getSource = function (url) {
var xhr = this.createXhrObject();
xhr.open("get", url, false);
xhr.send();
try {
return xhr.responseText;
} catch (exception) {
Terminal.log("Une erreur s'est produite lors de la requête:\n(" + exception + ")");
return null;
}
};
this.test_destination = function (url) {
var xhr = this.createXhrObject();
xhr.open("get", url, false);
try {
xhr.send();
Terminal.log('OK');
return true;
} catch (exception) {
Terminal.log('KO');
return false;
}
};
}
///////////////////////////
// ANIMATION RUBIXCUBE //
///////////////////////////
window.document.onkeydown = function (event) {
"use strict";
var keyCode = (window.event) ? event.keyCode : event.which;
Rubixcube.rotate_key(keyCode);
};
var boutonEnfonce = false,
x = 0,
y = 0,
xPrecedent = 0,
yPrecedent = 0,
event,
Event;
function position_mouse(e) {
"use strict";
if (window.document.documentElement.hasOwnProperty("onTouchStart")) {
boutonEnfonce = true;
}
if (boutonEnfonce) {
xPrecedent = x;
yPrecedent = y;
var pas_rotate = 1,
x_rotation = 0,
y_rotation = 0;
if (window.document.documentElement.hasOwnProperty("onTouchStart")) {
y = e.touches[0].pageX;
x = e.touches[0].pageY;
pas_rotate = 10;
} else {
x = (window.navigator.appName.substring(0, 3) === 'Net') ? e.pageX : event.x + window.document.body.scrollLeft;
y = (window.navigator.appName.substring(0, 3) === 'Net') ? e.pageY : event.y + window.document.body.scrollTop;
}
if (x < xPrecedent) {
y_rotation = pas_rotate * -1;
}
if (x > xPrecedent) {
y_rotation = pas_rotate;
}
if (y < yPrecedent) {
x_rotation = pas_rotate;
}
if (y > yPrecedent) {
x_rotation = pas_rotate * -1;
}
Rubixcube.rotate(x_rotation, y_rotation, 0);
}
}
//document.addEventListener('DOMContentLoaded', init, false);
if (window.document.documentElement.hasOwnProperty("onTouchStart")) {
//Terminal.log('Movement via touch');
window.document.ontouchmove = function (e) {
"use strict";
//Terminal.log(e.touches[0].pageX+', '+e.touches[0].pageY);
position_mouse(e);
var x = 0,
y = 0,
xPrecedent = 0,
yPrecedent = 0;
};
} else {
//Terminal.log('Movement via mouse');
window.document.onmousedown = function () {
"use strict";
var x = 0,
y = 0,
xPrecedent = 0,
yPrecedent = 0;
boutonEnfonce = true;
};
window.document.onmouseup = function () {
"use strict";
boutonEnfonce = false;
var x = 0,
y = 0,
xPrecedent = 0,
yPrecedent = 0;
};
}
if (window.document.getElementById) {
if (window.navigator.appName.substring(0, 3) === 'Net') {
window.document.captureEvents(Event.MOUSEMOVE);
}
window.document.onmousemove = position_mouse;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// TTTTTT OOOOOO DDDDD OOOOOO LL II SSSSSS TTTTTT //
// TT OO OO DD DD OO OO LL II SS TT //
// TT OO OO DD DD OO OO LL II SSSSSS TT //
// TT OO OO DD DD OO OO LL II SS TT //
// TT OOOOOO DDDDD OOOOOO LLLLLL II SSSSSS TT //
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// - Corriger probleme FireFox sur le hover sur la face rouge //
// - Correction des rotations //
// - Enchainements rotations //
// - Création matrice //
// - Gér execution du code dans la page cryptée //
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Add meta tag
if (window.document.getElementsByTagName('meta').length === 0) {
var meta = window.document.createElement('meta');
meta.setAttribute('http-equiv', 'Content-Type');
meta.setAttribute('content', 'text/html;charset=iso-8859-1');
var head = window.document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(meta);
}
}
var Terminal = new Terminal();
Terminal.create();
Terminal.switch_on();
var Browser = new Browser();
Browser.create();
var Parameter = new Parameter();
var Transition = new Transition();
var Encryptor = new Encryptor();
//Encryptor.run();
var Rubixcube = new Rubixcube();
Rubixcube.create('body');
window.setTimeout(function () {"use strict"; Rubixcube.rotate(45, 45, 0); }, 100);
//}