mirror of https://github.com/espruino/BangleApps
clockbg 0.06: 25% speed improvement if Math.randInt exists (2v25 fw)
parent
4ff01d1db0
commit
242eda245b
|
@ -4,4 +4,5 @@
|
||||||
0.04: More options for different background colors
|
0.04: More options for different background colors
|
||||||
'Plasma' generative background
|
'Plasma' generative background
|
||||||
Add a 'view' option in settings menu to view the current background
|
Add a 'view' option in settings menu to view the current background
|
||||||
0.05: Random square+plasma speed improvements (~2x faster)
|
0.05: Random square+plasma speed improvements (~2x faster)
|
||||||
|
0.06: 25% speed improvement if Math.randInt exists (2v25 fw)
|
|
@ -1,6 +1,7 @@
|
||||||
let settings;
|
let settings;
|
||||||
|
|
||||||
exports.reload = function() {
|
exports.reload = function() {
|
||||||
|
//let t = Date.now();
|
||||||
settings = Object.assign({
|
settings = Object.assign({
|
||||||
style : "randomcolor",
|
style : "randomcolor",
|
||||||
colors : ["#F00","#0F0","#00F"]
|
colors : ["#F00","#0F0","#00F"]
|
||||||
|
@ -17,7 +18,8 @@ exports.reload = function() {
|
||||||
let bpp = (settings.colors.length>4)?4:2;
|
let bpp = (settings.colors.length>4)?4:2;
|
||||||
let bg = Graphics.createArrayBuffer(11,11,bpp,{msb:true});
|
let bg = Graphics.createArrayBuffer(11,11,bpp,{msb:true});
|
||||||
let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256);
|
let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256);
|
||||||
E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels
|
if (Math.randInt) E.mapInPlace(u32, u32, Math.randInt); // random pixels
|
||||||
|
else E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels
|
||||||
bg.buffer[bg.buffer.length-1]=Math.random()*256; // 11x11 isn't a multiple of 4 bytes - we need to set the last one!
|
bg.buffer[bg.buffer.length-1]=Math.random()*256; // 11x11 isn't a multiple of 4 bytes - we need to set the last one!
|
||||||
bg.palette = new Uint16Array(1<<bpp);
|
bg.palette = new Uint16Array(1<<bpp);
|
||||||
bg.palette.set(settings.colors.map(c=>g.toColor(c)));
|
bg.palette.set(settings.colors.map(c=>g.toColor(c)));
|
||||||
|
@ -28,7 +30,8 @@ exports.reload = function() {
|
||||||
settings.style = "image";
|
settings.style = "image";
|
||||||
let bg = Graphics.createArrayBuffer(16,16,4,{msb:true});
|
let bg = Graphics.createArrayBuffer(16,16,4,{msb:true});
|
||||||
let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256);
|
let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256);
|
||||||
E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels
|
if (Math.randInt) E.mapInPlace(u32, u32, Math.randInt); // random pixels
|
||||||
|
else E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels
|
||||||
bg.filter([ // a gaussian filter to smooth out
|
bg.filter([ // a gaussian filter to smooth out
|
||||||
1, 4, 7, 4, 1,
|
1, 4, 7, 4, 1,
|
||||||
4,16,26,16, 4,
|
4,16,26,16, 4,
|
||||||
|
@ -42,6 +45,7 @@ exports.reload = function() {
|
||||||
settings.imgOpt = {scale:11};
|
settings.imgOpt = {scale:11};
|
||||||
delete settings.colors;
|
delete settings.colors;
|
||||||
}
|
}
|
||||||
|
//console.log("bg",Date.now()-t);
|
||||||
};
|
};
|
||||||
exports.reload();
|
exports.reload();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ "id": "clockbg",
|
{ "id": "clockbg",
|
||||||
"name": "Clock Backgrounds",
|
"name": "Clock Backgrounds",
|
||||||
"shortName":"Backgrounds",
|
"shortName":"Backgrounds",
|
||||||
"version": "0.05",
|
"version": "0.06",
|
||||||
"description": "Library that allows clocks to include a custom background (generated on demand or uploaded).",
|
"description": "Library that allows clocks to include a custom background (generated on demand or uploaded).",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"screenshots": [{"url":"screenshot.png"},{"url":"screenshot2.png"},{"url":"screenshot3.png"}],
|
"screenshots": [{"url":"screenshot.png"},{"url":"screenshot2.png"},{"url":"screenshot3.png"}],
|
||||||
|
|
Loading…
Reference in New Issue