From c93157ac30ed60b6875a1e5da8ccb411e8efa4ef Mon Sep 17 00:00:00 2001 From: overflowerror Date: Tue, 25 Mar 2014 08:06:01 +0100 Subject: [PATCH] i hope this works --- code.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++---- index.html | 7 ++++--- lock.js | 16 +++++++++++---- main.js | 15 +++++--------- 4 files changed, 76 insertions(+), 21 deletions(-) diff --git a/code.js b/code.js index 78a6cb6..b4c8460 100644 --- a/code.js +++ b/code.js @@ -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"; +} \ No newline at end of file diff --git a/index.html b/index.html index e4905f5..4682744 100644 --- a/index.html +++ b/index.html @@ -1,13 +1,14 @@ - - + + + +
bitte warten
\ No newline at end of file diff --git a/lock.js b/lock.js index 9347117..a6cd748 100644 --- a/lock.js +++ b/lock.js @@ -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; } diff --git a/main.js b/main.js index 8d092ab..1a0a857 100644 --- a/main.js +++ b/main.js @@ -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 +"
"+ "
"+ "
"+getAngle(acceleration.x, acceleration.y); - drawDial(-getAngle(acceleration.x, acceleration.y)* Math.PI/180) ; + element.innerHTML = "x:"+ acceleration.x + "y:"+ acceleration.y +"
"+ "
"+ "
"+getAngle(acceleration.x, acceleration.y); + handleAngle(getAngle(acceleration.x, acceleration.y) / 180 * Math.PI); }; function getAngle (x, y) { if (x == 0) @@ -32,4 +25,6 @@ var startup = function(){ var options = { frequency: 100 }; -document.addEventListener("deviceready", startup, false); \ No newline at end of file +document.addEventListener("deviceready", startup, false); + +//window.onload = startup; \ No newline at end of file