Matrix Code micro:bit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let frame = 0 | |
let drops: { col: number, row: number }[] = [] | |
let addDrops = 3 | |
let pauseDuration = 100 | |
// Press A: Make animation slower | |
input.onButtonPressed(Button.A, function () { | |
pauseDuration *= 1.1 | |
}) | |
// Press B: Make animation faster | |
input.onButtonPressed(Button.B, function () { | |
pauseDuration *= 0.9 | |
}) | |
basic.forever(function () { | |
frame += 1 | |
// Add a new drop | |
for (let index = 0; index < addDrops; index++) { | |
drops.push({ | |
col: randint(0, 4), | |
row: 0 | |
}) | |
} | |
// Clear screen | |
basic.clearScreen() | |
// Render drops | |
for (let i = 0; i <= drops.length - 1; i++) { | |
led.plot(drops[i].col, drops[i].row) | |
} | |
// Move drops down | |
for (let j = 0; j <= drops.length - 1; j++) { | |
++drops[j].row | |
} | |
// Remove drops that are outside of the screen | |
drops = drops.filter(({row}) => row <= 4) | |
// Wait a little | |
basic.pause(pauseDuration) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment