Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: components/proximity_auth/webui/resources/proximity_auth.js

Issue 1080163002: Add new chrome://proximity-auth WebUI for debugging Smart Lock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add OWNERS Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/proximity_auth/webui/resources/proximity_auth.js
diff --git a/components/proximity_auth/webui/resources/proximity_auth.js b/components/proximity_auth/webui/resources/proximity_auth.js
new file mode 100644
index 0000000000000000000000000000000000000000..8b9e1c3a3f270445ddeb3151f375d5d7bcae9f4c
--- /dev/null
+++ b/components/proximity_auth/webui/resources/proximity_auth.js
@@ -0,0 +1,91 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// TODO(tengs): This page is just a placeholder. The real page still needs to be
+// built.
+
+function LSystem(rules, startState, iterations) {
+ symbols = startState.split('').map(function(character) {
+ return { c: character, i: 0 };
+ });
+
+ while (true) {
+ var index = -1;
+ for (var i = 0; i < symbols.length; ++i) {
+ var symbol = symbols[i];
+ if (symbol.i < iterations && rules[symbol.c] != null) {
+ index = i;
+ break;
+ }
+ }
+ if (index == -1)
+ break;
+
+ var symbol = symbols[index];
+ var newSymbols = rules[symbol.c].apply(symbol).split('').map(function(c) {
+ return { c: c, i: symbol.i + 1 };
+ });
+
+ Array.prototype.splice.apply(symbols, [index, 1].concat(newSymbols));
+ }
+
+ return symbols.map(function(symbol) {
+ return symbol.c;
+ });
+};
+
+var rules = {
+ 'X': function(x) { return 'X+YF'; },
+ 'Y': function(y) { return 'FX-Y'; },
+}
+var startState = 'FX+FX+';
+var iterations = 10;
+
+function draw() {
+ var canvas = document.getElementById('canvas');
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+
+ var canvasWidth = canvas.offsetWidth;
+ var canvasHeight = canvas.offsetHeight;
+ var context = canvas.getContext('2d');
+
+ context.lineWidth = 2;
+ var segmentWidth = 0.015 * canvasHeight;
+ var pos = {
+ x: 0.5 * canvasWidth,
+ y: 0.25 * canvasHeight,
+ };
+ var dir = { x: 1, y: 0, };
+
+ var commands = LSystem(rules, startState, iterations);
+ var drawCommand = function() {
+ var command = commands.shift();
+ if (command === 'F') {
+ context.beginPath();
+ context.moveTo(pos.x, pos.y);
+
+ pos = {
+ x: pos.x + dir.x * segmentWidth,
+ y: pos.y + dir.y * segmentWidth,
+ };
+
+ context.lineTo(pos.x, pos.y);
+ var r = Math.round(pos.x / canvasWidth * 256);
+ var b = Math.round(pos.y / canvasHeight * 256);
+ var g = 180;
+ context.strokeStyle = 'rgb(' + r + ',' + g + ',' + b + ')';
+ context.stroke();
+ } else if (command === '+') {
+ dir = { x: -dir.y, y: dir.x }
+ } else if (command === '-') {
+ dir = { x: dir.y, y: -dir.x }
+ }
+ }
+
+ window.setInterval(drawCommand, 10);
+ //while (commands.length) drawCommand();
xiyuan 2015/04/15 17:10:47 nit: remove?
Tim Song 2015/04/15 19:42:07 Done.
+}
+
+document.addEventListener("DOMContentLoaded", draw);

Powered by Google App Engine
This is Rietveld 408576698