From 7ae71e95066d108b8acc829423ac3da9945d25da Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 09:58:01 +0200 Subject: [PATCH 01/10] iconbits: introduce color support --- apps/iconbits/iconbits.app.js | 52 +++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index 625070dd5..d046bf1df 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -10,6 +10,7 @@ let kule = [0, 0, 0]; // R, G, B var font_height = 22, font_width = 8; var zoom_x = 64, zoom_y = 24, zoom_f = 6; + var color = true; let oldLock = false; let sg = null; @@ -17,7 +18,7 @@ sg.setColor(1,1,1).fillRect(0,0, font_width, font_height); } - function setup(m) { + function __setup(m) { mode = m; switch (m) { case 'font': @@ -37,10 +38,23 @@ zoom_f = 2; break; } + } + function setup(m) { + __setup(m); sg = Graphics.createArrayBuffer(font_width, font_height, 8, {}); clear(); } + function icon_big() { + zoom_x = 16; + zoom_y = 25; + zoom_f = 3; + } + + function icon_small() { + __setup("icon"); + } + function updateLock() { if (oldLock) { return; @@ -66,7 +80,11 @@ Bangle.on("lock", function() { kule[2] = Math.random(); } function selectColor (x) { - let c; + if (color) { + i = Math.floor((x - 25) / 4); + kule = toColor(i); + return; + } if (x < g.getWidth()/2) { c = 0; } else { @@ -117,6 +135,7 @@ Bangle.on("lock", function() { g.clear(); if (mode == "draw") return; + const w = g.getWidth; g.setColor(0, 0, 0.5); g.fillRect(0, 0, g.getWidth(), g.getHeight()); g.setColor(1, 1, 1); @@ -129,6 +148,16 @@ Bangle.on("lock", function() { update(); } + function toColor(i) { + let r = [0, 0, 0]; + r[0] = (i % 3) / 2; + i = Math.floor(i / 3); + r[1] = (i % 3) / 2; + i = Math.floor(i / 3); + r[2] = (i % 3) / 2; + return r; + } + function drawUtil () { if (Bangle.isLocked()) { updateLock(); @@ -136,6 +165,11 @@ Bangle.on("lock", function() { // titlebar g.setColor(kule[0], kule[1], kule[2]); g.fillRect(0, 0, g.getWidth(), 20); + for (let i = 0; i < 3*3*3; i++) { + r = toColor(i); + g.setColor(r[0], r[1], r[2]); + g.fillRect(25+4*i, 20, 25+4*i+3, 24); + } // clear button g.setColor('#000'); // black g.fillCircle(10, 10, 8, 8); @@ -173,7 +207,7 @@ Bangle.on("lock", function() { var XS = (to.x - from.x) / 32; var YS = (to.y - from.y) / 32; for (let i = 0; i < 32; i++) { - g.fillCircle(from.x + (i * XS), from.y + (i * YS), 4, 4); + g.fillCircle(from.x + (i * XS), from.y + (i * YS), 2, 2); } break; case 'square': @@ -182,7 +216,7 @@ Bangle.on("lock", function() { for (let i = 0; i < 32; i++) { const posX = from.x + (i * XS); const posY = from.y + (i * YS); - g.fillRect(posX - 10, posY - 10, posX + 10, posY + 10); + g.fillRect(posX - 4, posY - 4, posX + 4, posY + 4); } break; } @@ -190,7 +224,7 @@ Bangle.on("lock", function() { } function update() { - g.drawImage(sg, 0, 64, {}); + g.drawImage(sg, 4, 64, {}); g.drawImage(sg, zoom_x, zoom_y, { scale: zoom_f }); } @@ -226,8 +260,9 @@ Bangle.on("lock", function() { oldY = -1; }, 100); + let top_bar = 20; // tap and hold the clear button - if (tap.x < 32 && tap.y < 32) { + if (tap.x < 32 && tap.y < top_bar) { if (tap.b === 1) { if (tapTimer === null) { tapTimer = setTimeout(function () { @@ -244,7 +279,7 @@ Bangle.on("lock", function() { } return; } - if (tap.x > g.getWidth() - 32 && tap.y < 32) { + if (tap.x > g.getWidth() - 32 && tap.y < top_bar) { if (tap.b === 1) { if (tapTimer === null) { tapTimer = setTimeout(function () { @@ -264,7 +299,7 @@ Bangle.on("lock", function() { } drawUtil(); return; - } else if (tap.y < 32) { + } else if (tap.y < top_bar) { if (mode == "draw") nextColor(); else @@ -308,6 +343,7 @@ Bangle.on("lock", function() { //print("wh", im, typeof im, im[0], typeof im[0]); //print("Image:", im.length, s); print('fi("'+btoa(im)+'");'); + print(btoa(require('heatshrink').compress(im))); } From aedb898177876ff8bca37c5674c741c7b63f1dbd Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 10:04:32 +0200 Subject: [PATCH 02/10] iconbits: cleanups. --- apps/iconbits/iconbits.app.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index d046bf1df..d40cc0285 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -194,6 +194,9 @@ Bangle.on("lock", function() { } function __draw (g, from, to) { + let XS = (to.x - from.x) / 32; + let YS = (to.y - from.y) / 32; + switch (pen) { case 'pixel': g.drawLine(from.x, from.y, to.x, to.y); @@ -204,15 +207,11 @@ Bangle.on("lock", function() { g.drawLine(from.x + 2, from.y + 2, to.x, to.y + 2); break; case 'circle': - var XS = (to.x - from.x) / 32; - var YS = (to.y - from.y) / 32; for (let i = 0; i < 32; i++) { g.fillCircle(from.x + (i * XS), from.y + (i * YS), 2, 2); } break; case 'square': - var XS = (to.x - from.x) / 32; - var YS = (to.y - from.y) / 32; for (let i = 0; i < 32; i++) { const posX = from.x + (i * XS); const posY = from.y + (i * YS); @@ -220,7 +219,6 @@ Bangle.on("lock", function() { } break; } - } function update() { From 9697902e40bee4f32dc25a75fb387a4c1e99fb0e Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 10:12:57 +0200 Subject: [PATCH 03/10] iconbits: cleanups, finish color selector --- apps/iconbits/iconbits.app.js | 37 ++++++++++++++++------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index d40cc0285..b5f26d4df 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -13,6 +13,7 @@ var color = true; let oldLock = false; let sg = null; + const top_bar = 20; function clear(m) { sg.setColor(1,1,1).fillRect(0,0, font_width, font_height); @@ -61,9 +62,9 @@ } g.setColor('#fff'); g.fillRect(0, 0, g.getWidth(), 20); - g.setFont('6x8', 2); + g.setFont('Vector', 22); g.setColor('#000'); - g.drawString('PLEASE UNLOCK', 10, 2); + g.drawString('PLEASE\nUNLOCK', 10, 2); oldLock = true; } Bangle.on("lock", function() { @@ -74,14 +75,14 @@ Bangle.on("lock", function() { drawUtil(); } }); - function nextColor () { + function nextColor() { kule[0] = Math.random(); kule[1] = Math.random(); kule[2] = Math.random(); } - function selectColor (x) { + function selectColor(x) { if (color) { - i = Math.floor((x - 25) / 4); + i = Math.floor((x - 32) / 4); kule = toColor(i); return; } @@ -131,7 +132,7 @@ Bangle.on("lock", function() { } } - function drawArea () { + function drawArea() { g.clear(); if (mode == "draw") return; @@ -158,17 +159,17 @@ Bangle.on("lock", function() { return r; } - function drawUtil () { + function drawUtil() { if (Bangle.isLocked()) { updateLock(); } // titlebar g.setColor(kule[0], kule[1], kule[2]); - g.fillRect(0, 0, g.getWidth(), 20); + g.fillRect(0, 0, g.getWidth(), top_bar); for (let i = 0; i < 3*3*3; i++) { r = toColor(i); g.setColor(r[0], r[1], r[2]); - g.fillRect(25+4*i, 20, 25+4*i+3, 24); + g.fillRect(32+4*i, 12, 32+4*i+3, top_bar); } // clear button g.setColor('#000'); // black @@ -183,7 +184,7 @@ Bangle.on("lock", function() { drawBrushIcon(); } - function transform (p) { + function transform(p) { if (p.x < zoom_x || p.y < zoom_y) return p; p.x = ((p.x - zoom_x) / zoom_f); @@ -193,7 +194,7 @@ Bangle.on("lock", function() { return p; } - function __draw (g, from, to) { + function __draw(g, from, to) { let XS = (to.x - from.x) / 32; let YS = (to.y - from.y) / 32; @@ -258,7 +259,6 @@ Bangle.on("lock", function() { oldY = -1; }, 100); - let top_bar = 20; // tap and hold the clear button if (tap.x < 32 && tap.y < top_bar) { if (tap.b === 1) { @@ -343,19 +343,16 @@ Bangle.on("lock", function() { print('fi("'+btoa(im)+'");'); print(btoa(require('heatshrink').compress(im))); } - - } - setup("icon"); - drawArea(); - Bangle.setUI({ +setup("icon"); +drawArea(); +Bangle.setUI({ "mode": "custom", "drag": on_drag, "btn": on_btn, - }); - drawUtil(); - +}); +drawUtil(); function ft(icon) { g.reset().clear(); From 5cc09c832d21147f4b203868a7189db88fa60675 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 10:31:08 +0200 Subject: [PATCH 04/10] iconbits: cleanup preview functions --- apps/iconbits/iconbits.app.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index b5f26d4df..bb99e7c34 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -330,18 +330,15 @@ Bangle.on("lock", function() { s += f(v); } print("Manual bitmap\n"); - print('ft("' + s + '");'); + print('show_font("' + s + '");'); if (1) { s = ""; var im = sg.asImage("string"); for (var v of im) { - //print("val", v, typeof v); s += f(v); } - //print("wh", im, typeof im, im[0], typeof im[0]); - //print("Image:", im.length, s); - print('fi("'+btoa(im)+'");'); - print(btoa(require('heatshrink').compress(im))); + //print('show_unc_icon("'+btoa(im)+'");'); + print('show_icon("'+btoa(require('heatshrink').compress(im))+'");'); } } @@ -354,14 +351,22 @@ Bangle.setUI({ }); drawUtil(); -function ft(icon) { +function show_font(icon) { g.reset().clear(); g.setFont("Vector", 26).drawString("Hellord" + icon, 0, 0); } -function fi(icon) { +function show_bin_icon(icon) { g.reset().clear(); - g.drawImage(atob(icon), 40, 40); + g.drawImage(icon, 40, 40); +} + +function show_unc_icon(icon) { + show_bin_icon(atob(icon)); +} + +function show_icon(icon) { + unc = require("heatshrink").decompress(atob(icon)); + show_bin_icon(unc); } -//ft(icon_10 + "23.1" + icon_hpa); From 24ebb8a583e70e0125e1e35a05fac3b9e612d006 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 11:13:32 +0200 Subject: [PATCH 05/10] iconbits: update png icon --- apps/iconbits/app.png | Bin 2459 -> 2010 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/apps/iconbits/app.png b/apps/iconbits/app.png index 7a3ee2e90600531bd4df39ad517637ecdc854745..d4e822ac7d47958ae769d3f09024801c10b8dc62 100644 GIT binary patch literal 2010 zcmdT_`#aQ$7d{_jX5=!`nsLb`Y1hUicC#^~Sa(a3MaFe1L#nm&l*zdE849ahD?*eh z$r8gid{$8KrIiRPv##-V=n5c5d|Vx%_MzU`%A$D0!QEGBr4p6GGXRLk-JO2)<%Uj` z?%Mm}2UREG2fOPfo$kiX9;?=YvSZ5 z8Yf8IhXVTB5SZRY^!21M5z&wq<CWG_D;Vw z<$qj!Hbs+%I3rR|>eMZGI^7qw0ZeqpJaL#;o6A3;sPXfNEW_BOK<9@KmGZ`38fk%+ zPC{M*>HKT@|8&MGY>LI-Zv$L3BeRa_xt^$*jkogcz{&qPW~N)Ts`^gGA1x5fNm7Ut zqGJW=q{-A*dHUQZJx9l}OTzGw0K*851QO*Gbi%&6OBI9Qj{bac4#J(26urwUK06w~ zk)@Ule|6bmbd3+O1lU83t06JT3bfI>jZu2_R#-ufhsUXkWO5vJF|adD67VYIphQR` zpd}n>W<7%L4l`>@F32t<@5`MXR>!;0))9m(8S4S9uH!V> z5?(NmgEa05qK%G@MG4lRc;tPynr*w4C~ENQ@Sel^Z@I2YFk&=qM+DKH*u!r5x<(Dm z>Up=U{lXZj+rTyJy43n!Z=e+Mkoo0pzy$ND+`b2h$P#0O6l(AnbaiH3NB)pd7&gXn zrpX;u3*yfFv*{Av7&e^i7Y&#i)Kb}fi?e5oAH7##!t~u&XGlPhZe%x6<83jPX&^T>pBPp1#k?hPevNjY^-;U+HKC=QRcJZ?aiHc(`pwKX4TU4w ziE}~8xb;5QGH%|#U2r3YdD6q#k}-mlNAhT4Tg)6{nAJaLiykt=t&nv6it-#q(Ot=S zZD{$eS!ZFH7JALg=JtKJpBQBXw0qO1r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bp`XaRaZGFGlwcO+s+S2Gx75 zuE-qX^R#sIW=Q`FcMtVdO2+JG);)cY_D>rW(O+yq^xzyvmgo`t#OJo5H0CaVG4@4u zW?Ut>8uOh-TOyrTPU?p#Vks6Cuf4^_ai;@WvCp!s2)*173$Mk#WUFO?rXdHuYgHMd zO2zt(fkh*gKJCROx}lr9ufO_beR?fEe50u!s2jocuLr*+-8~}LrCoH-%m}8qYHd)u z6v-7C)9=;ZV!0k{hWem1(~tgj*MT{HB|?h_?uK`dpa;kcKc~B}SKX}mm!A`N>xy8u znUTq#`qrlCzVsh*t^K0nA4f-BGTV1b|KDa9_k+|nuYU+S-2VY#O@9YOAGJ()7lP0U MB_Pzll? Date: Fri, 19 Jul 2024 11:14:18 +0200 Subject: [PATCH 06/10] iconbits: add loading/preview functions --- apps/iconbits/iconbits.app.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index bb99e7c34..2be08e3d4 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -223,7 +223,8 @@ Bangle.on("lock", function() { } function update() { - g.drawImage(sg, 4, 64, {}); + if (zoom_f < 3) + g.drawImage(sg, 4, 64, {}); g.drawImage(sg, zoom_x, zoom_y, { scale: zoom_f }); } @@ -370,3 +371,20 @@ function show_icon(icon) { show_bin_icon(unc); } +function load_bin_icon(i) { + sg.reset().clear(); + sg.drawImage(i, 0, 0); + drawArea(); +} + +function load_icon(icon) { + unc = require("heatshrink").decompress(atob(icon)); + load_bin_icon(unc); +} + +function for_screen() { + g.reset().clear(); + icon_big(); + update(); +} + From b51a85657628dfb19aaa6b59d7cd701760b78dc9 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 11:48:02 +0200 Subject: [PATCH 07/10] iconbits: cleanups, implement line drawing. --- apps/iconbits/iconbits.app.js | 53 ++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index 2be08e3d4..1777a8af3 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -98,8 +98,8 @@ Bangle.on("lock", function() { function nextPen () { switch (pen) { case 'circle': pen = 'pixel'; break; - case 'pixel': pen = 'crayon'; break; - case 'crayon': pen = 'square'; break; + case 'pixel': pen = 'line'; break; + case 'line': pen = 'square'; break; case 'square': pen = 'circle'; break; default: pen = 'pixel'; break; } @@ -108,8 +108,8 @@ Bangle.on("lock", function() { discard = setTimeout(function () { oldX = -1; oldY = -1; console.log('timeout'); discard = null; }, 500); } - var oldX = -1; - var oldY = -1; + var oldX = -1, oldY = -1; + var line_from = null; function drawBrushIcon () { const w = g.getWidth(); @@ -129,6 +129,9 @@ Bangle.on("lock", function() { g.drawLine(w - 14, 6, w - 10, 12); g.drawLine(w - 6, 6, w - 10, 12); break; + case 'line': + g.drawLine(w - 5, 5, w - 15, 15); + break; } } @@ -199,6 +202,7 @@ Bangle.on("lock", function() { let YS = (to.y - from.y) / 32; switch (pen) { + case 'line': case 'pixel': g.drawLine(from.x, from.y, to.x, to.y); break; @@ -219,6 +223,8 @@ Bangle.on("lock", function() { g.fillRect(posX - 4, posY - 4, posX + 4, posY + 4); } break; + default: + print("Unkown pen ", pen); } } @@ -229,9 +235,11 @@ Bangle.on("lock", function() { } function do_draw(from, to) { + print("do-draw", from, to); from = transform(from); to = transform(to); if (from && to) { + print("__draw", from, to); __draw(sg, from, to); } update(); @@ -306,20 +314,31 @@ Bangle.on("lock", function() { drawUtil(); return; } - oldX = to.x; - oldY = to.y; sg.setColor(kule[0], kule[1], kule[2]); g.setColor(kule[0], kule[1], kule[2]); + oldX = to.x; + oldY = to.y; - do_draw(from, to); + if (pen != "line") { + do_draw(from, to); + } else { + if (tap.b == 1) { + print(line_from); + if (!line_from) { + line_from = to; + } else { + print("draw -- ", line_from, to); + do_draw(line_from, to); + line_from = null; + } + } + } drawUtil(); } function on_btn(n) { function f(i) { return "\\x" + i.toString(16).padStart(2, '0'); } - print("on_btn", n); - print(g.getPixel(0, 0)); let s = f(0) + f(font_width) + f(font_height) + f(1); // 0..black, 65535..white for (let y = 0; y < font_height; y++) { @@ -330,17 +349,11 @@ Bangle.on("lock", function() { } s += f(v); } - print("Manual bitmap\n"); - print('show_font("' + s + '");'); - if (1) { - s = ""; - var im = sg.asImage("string"); - for (var v of im) { - s += f(v); - } - //print('show_unc_icon("'+btoa(im)+'");'); - print('show_icon("'+btoa(require('heatshrink').compress(im))+'");'); - } + if (mode == "font") + print('show_font("' + s + '");'); + var im = sg.asImage("string"); + //print('show_unc_icon("'+btoa(im)+'");'); + print('show_icon("'+btoa(require('heatshrink').compress(im))+'");'); } setup("icon"); From 62cb337105f4ec196d6c1b6b7f8678de3bdc0a19 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 13:29:25 +0200 Subject: [PATCH 08/10] iconbits: cleanups, add documentation. --- apps/iconbits/README.md | 17 +++++++++++++++-- apps/iconbits/iconbits.app.js | 8 +++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/iconbits/README.md b/apps/iconbits/README.md index c5c524ab0..90bc0f5a3 100644 --- a/apps/iconbits/README.md +++ b/apps/iconbits/README.md @@ -3,5 +3,18 @@ Bitmap editor suitable for creating icons and fonts for BangleJS2. You'll want to run a copy of this in simulator, and another one on -watch to view the results. Draw using the provided tools, then press -the button, and you'll get result on the console. +watch to view the results. + +Draw using the provided tools, then press the button, and you'll get +result on the console; you can also use "dump();" on command +line. show_icon() takes same parameter as is used in app-icon.js +files, you can just copy&paste it to get an icon. By using +"for_screen();" command, then taking a screenshot, you can easily +generate app.png file. + +It is also possible to load existing icon into editor, using +"load_icon("");" command. At the end of iconbits.app.js file there are +more utility functions. + + + diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index 1777a8af3..83eb8ee89 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -235,11 +235,9 @@ Bangle.on("lock", function() { } function do_draw(from, to) { - print("do-draw", from, to); from = transform(from); to = transform(to); if (from && to) { - print("__draw", from, to); __draw(sg, from, to); } update(); @@ -327,7 +325,6 @@ Bangle.on("lock", function() { if (!line_from) { line_from = to; } else { - print("draw -- ", line_from, to); do_draw(line_from, to); line_from = null; } @@ -335,7 +332,8 @@ Bangle.on("lock", function() { } drawUtil(); } - function on_btn(n) { + +function dump(n) { function f(i) { return "\\x" + i.toString(16).padStart(2, '0'); } @@ -361,7 +359,7 @@ drawArea(); Bangle.setUI({ "mode": "custom", "drag": on_drag, - "btn": on_btn, + "btn": dump, }); drawUtil(); From 4561572aad3de1aee941e6da990e4acacd9e9b48 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 21:50:37 +0200 Subject: [PATCH 09/10] iconbits: mark this as version 0.02. --- apps/iconbits/ChangeLog | 1 + apps/iconbits/metadata.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/iconbits/ChangeLog b/apps/iconbits/ChangeLog index 263d4078d..10f5d311c 100644 --- a/apps/iconbits/ChangeLog +++ b/apps/iconbits/ChangeLog @@ -1 +1,2 @@ 0.01: attempt to import +0.02: implement colors and lines diff --git a/apps/iconbits/metadata.json b/apps/iconbits/metadata.json index b98a43953..edb4b4d6a 100644 --- a/apps/iconbits/metadata.json +++ b/apps/iconbits/metadata.json @@ -1,6 +1,6 @@ { "id": "iconbits", "name": "Icon bits", - "version": "0.01", + "version": "0.02", "description": "Bitmap editor suitable for creating icons", "icon": "app.png", "readme": "README.md", From d85ec84ae32d35405eaaf27e9dc781e9660c14b1 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 19 Jul 2024 22:01:24 +0200 Subject: [PATCH 10/10] iconbits: fix warnings. --- apps/iconbits/iconbits.app.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/iconbits/iconbits.app.js b/apps/iconbits/iconbits.app.js index 83eb8ee89..5fc10423c 100644 --- a/apps/iconbits/iconbits.app.js +++ b/apps/iconbits/iconbits.app.js @@ -82,14 +82,13 @@ Bangle.on("lock", function() { } function selectColor(x) { if (color) { - i = Math.floor((x - 32) / 4); + let i = Math.floor((x - 32) / 4); kule = toColor(i); return; } + let c = 255; if (x < g.getWidth()/2) { c = 0; - } else { - c = 255; } kule[0] = c; kule[1] = c; @@ -170,7 +169,7 @@ Bangle.on("lock", function() { g.setColor(kule[0], kule[1], kule[2]); g.fillRect(0, 0, g.getWidth(), top_bar); for (let i = 0; i < 3*3*3; i++) { - r = toColor(i); + let r = toColor(i); g.setColor(r[0], r[1], r[2]); g.fillRect(32+4*i, 12, 32+4*i+3, top_bar); } @@ -378,7 +377,7 @@ function show_unc_icon(icon) { } function show_icon(icon) { - unc = require("heatshrink").decompress(atob(icon)); + let unc = require("heatshrink").decompress(atob(icon)); show_bin_icon(unc); } @@ -389,7 +388,7 @@ function load_bin_icon(i) { } function load_icon(icon) { - unc = require("heatshrink").decompress(atob(icon)); + let unc = require("heatshrink").decompress(atob(icon)); load_bin_icon(unc); }