So now I've got colours working correctly (thanks again Hal and Gordon), I need to work on speed. See code below, but in the emulator, doing a full screen wipe takes ~6ms/frame. Exactly the same on the actual B2 takes ~228ms/frame, i.e. very very slow.
Is there anything I can do to speed this up, or is that just how long it takes to draw the whole screen? Doing only part of the screen definitely speeds things up, but not enough to look smooth.
let colormap={
0: 0,
31: 1,
2016: 2,
2047: 3,
63488: 4,
63519: 5,
65504: 6,
65535: 7
};
let palette = new Uint16Array([
g.toColor("#000"),
g.toColor("#00f"),
g.toColor("#0f0"),
g.toColor("#0ff"),
g.toColor("#f00"),
g.toColor("#f0f"),
g.toColor("#ff0"),
g.toColor("#fff"),
0,0,0,0,0,0,0,0
]);
let animInterval;
let time_array = []
let animate = function(step) {
if (animInterval) clearInterval(animInterval);
slideX = -R.w;
animInterval = setInterval(function() {
let time_start = getTime()
slideX += step;
let stop = false;
if (slideX>=0) {
slideX=0;
stop = true;
}
g.drawImage(g2img, slideX, R.y);
if (stop) {
clearInterval(animInterval);
animInterval=undefined;
print(time_array)
print(time_array.reduce((a, b) => a + b, 0) / time_array.length)
}
time_array.push(Math.round((getTime() - time_start)*1000))
}, 20);
};
Bangle.loadWidgets();
Bangle.drawWidgets();
let R = Bangle.appRect;
// R.h = 50
let g2 = Graphics.createArrayBuffer(R.w * 2, R.h, 4, {msb:true});
let g2img = { width:g2.getWidth(), height:g2.getHeight(), bpp:4, buffer:g2.buffer, palette: palette };
g2.setBgColor(colormap[g.theme.bg]);
g2.setColor(colormap[g.theme.fg]);
g.setBgColor("#F00").clearRect(R);
g.setColor("#0F0").setFont('Vector:15').setFontAlign(0, 0).drawString("OLD SCREEN", R.w/2, R.h/2);
let screengrab = g.asImage();
g2.drawImage(screengrab, R.w - R.x, -R.y);
g2.clearRect(R);
g2.setFont('Vector:15').setFontAlign(0, 0).drawString("NEW SCREEN", R.w/2, R.h/2);
animate(4);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
So now I've got colours working correctly (thanks again Hal and Gordon), I need to work on speed. See code below, but in the emulator, doing a full screen wipe takes ~6ms/frame. Exactly the same on the actual B2 takes ~228ms/frame, i.e. very very slow.
Is there anything I can do to speed this up, or is that just how long it takes to draw the whole screen? Doing only part of the screen definitely speeds things up, but not enough to look smooth.