Create app.js

pull/1942/head
pidajo 2022-06-10 16:34:27 +02:00 committed by GitHub
parent 146244aecf
commit 713a2849cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 52 additions and 0 deletions

52
apps/wristlight/app.js Normal file
View File

@ -0,0 +1,52 @@
function draw(color) {
if (color == undefined) {
color = -1;
}
g.clear();
g.setColor(color);
g.fillRect(0, 0, g.getWidth(), g.getHeight());
}
function draw2Pattern() {
colors = ["ff0000", "8080ff", "00ff00",
"ffffff"];
drawPattern(2, colors);
}
function draw3Pattern() {
colors = ["ff0000", "00ff00", "0000ff",
"ff00ff", "ffffff", "00ffff",
"ffff00", "ff8000", "ff0080"];
drawPattern(3, colors);
}
function drawPattern(size, colors) {
g.clear();
var w = g.getWidth() / size;
var h = g.getHeight() / size;
for (var i = 0; i < size; i++) {
for (var j = 0; j < size; j++) {
var color = colors[i*size + j];
g.setColor("#" + color);
g.fillRect(j * w, i * h, j * w + w, i * h + h);
}
}
Bangle.on("touch", function(btn, xy) {
var x = parseInt((xy.x) / w);
var y = parseInt((xy.y) / h);
draw("#" + colors[y * size + x]);
});
}
// Clear the screen once, at startup
// draw immediately at first
draw3Pattern();
/*
require("Storage").write("wristlight.info",{
"id":"wristlight",
"name":"Wrist Light",
"src":"wristlight.app.js",
"icon":"wristlight.img"
});
*/