67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
storage = require("Storage");
|
|
Bangle.setLCDPower(1);
|
|
g.clear();
|
|
|
|
// constants
|
|
const settingsfile = "memorytrainer.settings.json";
|
|
|
|
|
|
// utilities
|
|
function wait(s) {
|
|
c_time = getTime();
|
|
while(getTime() - c_time <= s) {}
|
|
}
|
|
function getSettings() {
|
|
return Object.assign({"firstrun": true}, storage.readJSON(settingsfile, true) || {});
|
|
}
|
|
|
|
|
|
// UI functions
|
|
function animate100x100img_big2small(img, minscale, maxscale) {
|
|
for(img_scale = minscale; img_scale <= maxscale; img_scale+=0.3) {
|
|
try {
|
|
g.drawImage(img, (g.getWidth()-100*img_scale)/2, (g.getHeight()-100*img_scale)/2, {scale: img_scale});
|
|
} catch(e) {} // place the image in the middle of screen (100 is the image width and height)
|
|
g.clear();
|
|
wait(1/60);
|
|
}
|
|
for(img_scale = maxscale; img_scale >= minscale; img_scale-=0.4) {
|
|
try {
|
|
g.drawImage(img, (g.getWidth()-100*img_scale)/2, (g.getHeight()-100*img_scale)/2, {scale: img_scale});
|
|
} catch(e) {}
|
|
g.clear();
|
|
wait(1/60);
|
|
}
|
|
}
|
|
|
|
function welcome(new_user) {
|
|
var brain_trainer_text = storage.readJSON("memorytrainer.icons.json", true).brain_trainer_text;
|
|
var img_brain_trainer_text = brain_trainer_text.data;
|
|
if(new_user) {
|
|
E.showMessage("Hello!");
|
|
wait(1);
|
|
g.clear();
|
|
wait(0.2);
|
|
E.showMessage("This is a\nBRAIN-TRAINER.");
|
|
wait(1);
|
|
g.clear();
|
|
wait(0.2);
|
|
}
|
|
g.drawImage(img_brain_trainer_text, g.getWidth()/2, g.getHeight()/2, {rotate: 0.04, scale: 1.2});
|
|
wait(1);
|
|
g.clear();
|
|
}
|
|
|
|
|
|
// now the real code begins
|
|
var settings = getSettings();
|
|
|
|
animate100x100img_big2small(storage.read("memorytrainer.png"), 0.1, 1.5);
|
|
if(settings.firstrun) {
|
|
welcome(true);
|
|
settings.firstrun = false;
|
|
storage.writeJSON(settingsfile, settings);
|
|
} else {
|
|
welcome(false);
|
|
}
|