Skip to content

Commit af0ca2c

Browse files
authored
Merge pull request #49 from lancs-acs/master
Randomly select font
2 parents 5e9fa70 + 402fe55 commit af0ca2c

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

web/priv/js_effects/clock.js

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ return class MyEffect {
4646
0x11, 0x22, 0x44, 0x80 // /
4747
];
4848

49-
this.charSet = this.charSet2;
49+
this.charSet = (Math.random( ) < 0.5) ? this.charSet1 : this.charSet2;
5050

5151
this.timePxlWidth = 6;
5252
this.timePxlHeight = 6;
@@ -56,60 +56,63 @@ return class MyEffect {
5656

5757
this.display = display;
5858

59-
this.#clear();
59+
this.#clear( );
6060
}
6161

62-
#clear() {
63-
for (let x = 0; x < this.display.width; x++)
64-
for (let y = 0; y < this.display.height; y++)
65-
this.display.setPixel(x, y, [0, 0, 0]);
62+
#clear( ) {
63+
for ( let x = 0; x < this.display.width; x++ )
64+
for ( let y = 0; y < this.display.height; y++ )
65+
this.display.setPixel( x, y, this.black );
6666

6767
this.display.flush();
6868
}
6969

70-
row(val, x, y, width, offset, colour) {
71-
for( let i = 16; i > 0; i>>=1 ) {
72-
let pxl = (val & i>>1) > 0;
70+
row( val, x, y, width, offset, colour ) {
71+
for( let i = 16; i > 0; i >>= 1 ) {
72+
let pxl = ( val & i >> 1 ) > 0;
7373
for ( let span = 0; span < width; span++ )
74-
this.display.setPixel(x++, y + offset, pxl ? colour : this.black)
74+
this.display.setPixel( x++, y + offset, pxl ? colour : this.black )
7575
}
7676
}
7777

78-
digit(xPos, n, width, height, offset, colour) {
78+
digit( xPos, n, width, height, offset, colour ) {
7979
xPos *= width * 5;
8080
let index = n * 4;
81-
for (let y = 1; y < 5; y++) {
81+
for ( let y = 1; y < 5; y++ ) {
8282
let bitmap = this.charSet[ index++ ];
83-
for (let dy = 0; dy < height*2; dy++)
84-
this.row((dy < height) ? bitmap>>4 : bitmap&15,
85-
xPos, y*height*2+dy, width, offset, colour);
83+
for ( let dy = 0; dy < height * 2; dy++ )
84+
this.row( ( dy < height ) ? bitmap >> 4 : bitmap & 15,
85+
xPos, y * height * 2 + dy, width, offset, colour );
8686
}
8787
}
8888

89-
tdigit(xPos, n, colour) {
90-
this.digit(xPos, n, this.timePxlWidth, this.timePxlHeight, 0, colour);
89+
tdigit( xPos, n, colour ) {
90+
this.digit( xPos, n, this.timePxlWidth, this.timePxlHeight, 0, colour );
9191
}
9292

93-
ddigit(xPos, n) {
94-
this.digit(xPos, n,
95-
this.datePxlWidth, this.datePxlHeight, this.dateOffset, this.white);
93+
ddigit( xPos, n ) {
94+
this.digit( xPos, n,
95+
this.datePxlWidth, this.datePxlHeight,
96+
this.dateOffset, this.white );
9697
}
9798

98-
update() {
99-
let date = new Date();
100-
let hours = date.getHours();
101-
let mins = date.getMinutes();
102-
let secs = date.getSeconds()
99+
update( ) {
100+
let date = new Date( );
101+
let hours = date.getHours( );
102+
let mins = date.getMinutes( );
103+
let secs = date.getSeconds( );
103104
let hcolour = this.colours[ Math.floor(secs / 10) ];
104105
let lcolour = this.colours[ secs % 10 ];
105-
this.tdigit(0, Math.floor(hours / 10), this.white );
106-
this.tdigit(1, hours % 10, this.white );
107-
this.tdigit(2, Math.floor(mins / 10), hcolour );
108-
this.tdigit(3, mins % 10, lcolour );
106+
107+
this.tdigit( 0, Math.floor(hours / 10), this.white );
108+
this.tdigit( 1, hours % 10, this.white );
109+
this.tdigit( 2, Math.floor(mins / 10), hcolour );
110+
this.tdigit( 3, mins % 10, lcolour );
109111

110-
let day = date.getDay();
111-
let month = date.getMonth() + 1;
112-
let year = date.getFullYear();
112+
let day = date.getDay( );
113+
let month = date.getMonth( ) + 1;
114+
let year = date.getFullYear( );
115+
113116
this.ddigit( 1, Math.floor(day / 10) );
114117
this.ddigit( 2, day % 10 );
115118
this.ddigit( 3, 10 );
@@ -121,6 +124,6 @@ return class MyEffect {
121124
this.ddigit( 9, Math.floor(year / 10) % 10 );
122125
this.ddigit(10, year % 10 );
123126

124-
this.display.flush();
127+
this.display.flush( );
125128
}
126129
}

0 commit comments

Comments
 (0)