i hope this works

This commit is contained in:
overflowerror 2014-03-25 08:06:01 +01:00
parent a65361e5f3
commit c93157ac30
4 changed files with 76 additions and 21 deletions

59
code.js
View file

@ -1,7 +1,58 @@
var code = new Array();
const right = 0;
const left = 1;
const non = 2;
var fuzzyRadius = 5;
var code = [3, 14, 25, 9, 26];
var input = new Array();
var checkCode = function(num, value) {
return (Math.abs(code[num] - value) < fuzzyRadius);
var oldNum = 0;
var oldDir = non;
var index = 0;
var numberOfRounds = 0;
var handleAngle = function(angle) {
var dir;
var num = angleToNum(angle);
console.log(num);
if (oldNum - num > countOfNumbers * 2 / 3)
dir = left;
else if (num - oldNum > countOfNumbers * 2 / 3)
dir = right;
else if (oldNum > num)
dir = right;
else if (num > oldNum)
dir = left;
else
dir = oldDir;
if (oldDir != non) {
if (dir != oldDir) {
input[index++] = oldNum;
} else {
if (oldNum > 2 / 3 * countOfNumbers && num < 1 / 3 * countOfNumbers && dir == right)
numberOfRounds++;
if (numberOfRounds > 2) {
index = 0;
input = new Array();
}
}
}
oldDir = dir;
oldNum = num;
drawDial(- angle);
}
var check = function() {
if (code.length != input.length)
return false;
for (var i = 0; i < code.length; i++) {
if (code[i] != input[i])
return false;
}
window.location.href = "http://www.youtube.com/watch?v=aObeQUNELm4";
}

View file

@ -1,13 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script src="lock.js">
</script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="lock.js"></script>
<script src="code.js"></script>
<!--<script type="text/javascript" charset="utf-8" src="cordova.js"></script>-->
<script src="main.js"></script>
</head>
<body>
<canvas id="canvas" width="200px" height="200px" style="background-color: #fff;"></canvas>
<button onclick="check()">I'm feeling lucky.</button>
<div id="textfeld">bitte warten</div>
</body>
</html>

16
lock.js
View file

@ -1,4 +1,7 @@
var context;
const countOfNumbers = 32;
var lockinit = function () {
var canvas = document.getElementById("canvas");
context = canvas.getContext('2d');
@ -39,13 +42,18 @@ var drawDial = function(rot) {
context.closePath();
context.fill();
context.fillStyle = "#fff";
var num = 32;
for (var i = 0; i < num; i++) {
for (var i = 0; i < countOfNumbers; i++) {
context.beginPath();
context.fillText(i, 72 * Math.cos(2 * Math.PI / num * i) - 7, 72 * Math.sin(2 * Math.PI / num * i) + 3);
context.fillText(i + 1, 72 * Math.cos(2 * Math.PI / countOfNumbers * i - Math.PI / 2) - 4, 72 * Math.sin(2 * Math.PI / countOfNumbers * i - Math.PI / 2) + 3);
context.closePath();
context.fill();
}
context.restore();
}
var angleToNum = function(angle) {
var tmp = parseInt(angle / Math.PI / 2 * countOfNumbers) % countOfNumbers;
if (tmp < 0)
tmp += countOfNumbers;
return tmp + 1;
}

13
main.js
View file

@ -1,14 +1,7 @@
function onSuccess(acceleration) {
/*alert('Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n' +
((Math.atan(acceleration.y / acceleration.x))/Math.PI*180)+90
);*/
var element = document.getElementById('textfeld');
element.innerHTML = "x:"+ acceleration.x + "y:"+ acceleration.y +" <br />"+ "<br />"+ "<br />"+getAngle(acceleration.x, acceleration.y);
drawDial(-getAngle(acceleration.x, acceleration.y)* Math.PI/180) ;
element.innerHTML = "x:"+ acceleration.x + "y:"+ acceleration.y +" <br />"+ "<br />"+ "<br />"+getAngle(acceleration.x, acceleration.y);
handleAngle(getAngle(acceleration.x, acceleration.y) / 180 * Math.PI);
};
function getAngle (x, y) {
if (x == 0)
@ -33,3 +26,5 @@ var startup = function(){
var options = { frequency: 100 };
document.addEventListener("deviceready", startup, false);
//window.onload = startup;