fixing scroll issues

This commit is contained in:
Peli de Halleux 2016-03-14 21:37:03 -07:00
parent ea325a6ffa
commit fb65711f08
2 changed files with 19 additions and 5 deletions

View File

@ -92,6 +92,7 @@ namespace ks.rt.micro_bit {
export function showDigit(v: number) {
if (!quiet)
console.log("DIGIT:", v)
plotLeds(createImageFromString(v.toString()[0]));
}
export function clearScreen() {
@ -106,14 +107,15 @@ namespace ks.rt.micro_bit {
function scrollImage(leds: micro_bit.Image, interval: number, stride: number): void {
let cb = getResume()
let off = stride > 0 ? 0 : leds.width - 1;
let display = board().image;
board().animationQ.enqueue({
interval: interval,
frame: () => {
if (off >= leds.width || off < 0)
return false;
let c = Math.min(5, leds.width - off);
leds.copyTo(off, 5, board().image, 0)
if (off >= leds.width || off < 0) return false;
stride > 0 ? display.shiftLeft(stride) : display.shiftRight(-stride);
let c = Math.min(stride, leds.width - off);
leds.copyTo(off, c, display, 5 - stride)
off += stride;
return true;
},
@ -129,7 +131,7 @@ namespace ks.rt.micro_bit {
if (interval < 0) return;
let leds = createImageFromString(x.toString());
if (x < 0 || x >= 10) scrollImage(leds, interval, 5);
if (x < 0 || x >= 10) scrollImage(leds, interval, 1);
else showLeds(leds, interval * 5);
}

View File

@ -298,6 +298,18 @@ namespace ks.rt.micro_bit {
}
}
}
public shiftLeft(cols: number) {
for(let x = 0; x < this.width;++x)
for(let y = 0; y < 5;++y)
this.set(x, y, x < this.width - cols ? this.get(x + cols,y) : 0);
}
public shiftRight(cols: number) {
for(let x = this.width -1; x <=0;--x)
for(let y = 0; y < 5;++y)
this.set(x, y, x > cols ? this.get(x - cols,y) : 0);
}
public clear(): void {
for (var i = 0; i < this.data.length; ++i)
this.data[i] = 0;