fixing scroll issues
This commit is contained in:
		@@ -92,6 +92,7 @@ namespace ks.rt.micro_bit {
 | 
				
			|||||||
    export function showDigit(v: number) {
 | 
					    export function showDigit(v: number) {
 | 
				
			||||||
        if (!quiet)
 | 
					        if (!quiet)
 | 
				
			||||||
            console.log("DIGIT:", v)
 | 
					            console.log("DIGIT:", v)
 | 
				
			||||||
 | 
					        plotLeds(createImageFromString(v.toString()[0]));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function clearScreen() {
 | 
					    export function clearScreen() {
 | 
				
			||||||
@@ -106,14 +107,15 @@ namespace ks.rt.micro_bit {
 | 
				
			|||||||
    function scrollImage(leds: micro_bit.Image, interval: number, stride: number): void {
 | 
					    function scrollImage(leds: micro_bit.Image, interval: number, stride: number): void {
 | 
				
			||||||
        let cb = getResume()
 | 
					        let cb = getResume()
 | 
				
			||||||
        let off = stride > 0 ? 0 : leds.width - 1;
 | 
					        let off = stride > 0 ? 0 : leds.width - 1;
 | 
				
			||||||
 | 
					        let display = board().image;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        board().animationQ.enqueue({
 | 
					        board().animationQ.enqueue({
 | 
				
			||||||
            interval: interval,
 | 
					            interval: interval,
 | 
				
			||||||
            frame: () => {
 | 
					            frame: () => {
 | 
				
			||||||
                if (off >= leds.width || off < 0)
 | 
					                if (off >= leds.width || off < 0) return false;
 | 
				
			||||||
                    return false;
 | 
					                stride > 0 ? display.shiftLeft(stride) : display.shiftRight(-stride);
 | 
				
			||||||
                let c = Math.min(5, leds.width - off);
 | 
					                let c = Math.min(stride, leds.width - off);
 | 
				
			||||||
                leds.copyTo(off, 5, board().image, 0)
 | 
					                leds.copyTo(off, c, display, 5 - stride)
 | 
				
			||||||
                off += stride;
 | 
					                off += stride;
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -129,7 +131,7 @@ namespace ks.rt.micro_bit {
 | 
				
			|||||||
        if (interval < 0) return;
 | 
					        if (interval < 0) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let leds = createImageFromString(x.toString());
 | 
					        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);
 | 
					        else showLeds(leds, interval * 5);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								sim/state.ts
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								sim/state.ts
									
									
									
									
									
								
							@@ -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 {
 | 
					        public clear(): void {
 | 
				
			||||||
            for (var i = 0; i < this.data.length; ++i)
 | 
					            for (var i = 0; i < this.data.length; ++i)
 | 
				
			||||||
                this.data[i] = 0;
 | 
					                this.data[i] = 0;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user