Skip to content

Instantly share code, notes, and snippets.

View rozek's full-sized avatar

Andreas Rozek rozek

View GitHub Profile
@rozek
rozek / asString.js
Created September 5, 2018 11:10
asString: convert Object.create(null) to string
/**** asString - can also convert Object.create(null) to string ****/
asString = function asString (Value) {
switch (Value) {
case undefined: return '[object Undefined]';
case null: return '[object Null]';
default:
if (Array.isArray(Value)) { return '[object Array]' };
return (
@rozek
rozek / TestObject.js
Created September 5, 2018 11:16
basic JavaScript object with properties useful for unit testing
/**** basic JavaScript object whose properties could be used for unit testing ****/
function newTestObject () {
return {
undefined:undefined,
null:null,
true:true, false:false,
negativeInteger:-123, zero:0, positiveInteger:123,
negativeInfinity:-Infinity, Number:Math.PI, positiveInfinity:Infinity, NaN:NaN,
emptyString:'', String:'Test',
@rozek
rozek / Bangle_CharsPerLine.js
Last active December 4, 2019 09:49
Bangle.js: how many characters can be shown per line using the default font?
// how many characters can be shown per line on Bangle.js using the default font?
Bangle.setLCDMode(); // use normal display mode
g.clear();
g.setFont('4x6');
let Digits = '1234567890';
let StringToDraw = '';
for (let i = 0; i < 8; i++) { StringToDraw += Digits }
StringToDraw += '\n';
@rozek
rozek / Bangle_ASCII-Table.js
Last active December 4, 2019 09:49
Bangle.js: which character glyphs are available in the code range 0...255?
// which 8-bit character glyphs are available?
const LineHeight = 10;
let yPosition;
/**** clear ****/
function clear () {
Bangle.setLCDMode(); // use normal display mode
g.clear();
@rozek
rozek / Bangle_ColorStripe.js
Last active December 6, 2019 08:49
Bangle.js: fills the display with a color stripe
// fills the display of a Bangle.js with a color stripe
Bangle.setLCDMode(); // use normal display mode
g.clear();
/**** HSVtoRGB ****/
// see https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
function HSVtoRGB (h, s, v) {
let c = v*s;
@rozek
rozek / Bangle_ColorDisc.js
Last active December 6, 2019 08:48
Bangle.js: fills the display with a color disc
// fills the display of a Bangle.js with a color disc
Bangle.setLCDMode(); // use normal display mode
g.clear();
/**** HSVtoRGB (especially for Bangle.js and its RGB565 encoding) ****/
// see https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
function HSVtoRGB (h, s, v) {
let c = v*s;
@rozek
rozek / Bangle_MandelbrotSet.js
Last active December 6, 2019 08:48
Bangle.js: displays the famous Mandelbrot set
Bangle.setLCDMode(); // use normal display mode
g.clear();
const Width = g.getWidth();
const Height = g.getHeight();
/**** color mapping (especially for Bangle.js) ****/
function rgb565 (r,g,b) {
return (r << 11) | (g << 5) | b;
@rozek
rozek / Bangle_monitorAccelerometer
Last active January 7, 2020 07:51
Bangle's: monitors accelerometer values
Bangle.setLCDMode('120x120');
g.clear();
g.setFont("6x8");
const Width = g.getWidth();
const Height = g.getHeight();
/**** show screen ****/
g.drawString('Accelerometer', 5,5);
@rozek
rozek / Bangle_listBuiltinFonts
Last active December 6, 2019 08:47
Bangle.js: lists the names of all built in fonts
const CharsPerLine = 60;
const LineHeight = 10;
let yPosition;
/**** clear ****/
function clear () {
Bangle.setLCDMode(); // use normal display mode
g.clear();
g.setFont("4x6");
@rozek
rozek / Bangle_MandelbrotSet_120x120.js
Last active December 6, 2019 08:48
Bangle.js: displays a Mandelbrot set with 120x120 px resolution
Bangle.setLCDMode('120x120');
g.clear();
const Width = g.getWidth();
const Height = g.getHeight();
/**** color mapping (especially for Bangle.js) ****/
function PaletteEntry (r,g,b) { // 8-bit modes use the "web color palette"
return r*36 + g*6 + b;