Skip to content

Instantly share code, notes, and snippets.

@coderbyheart
Last active September 28, 2021 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderbyheart/0943e6938ae2449be6f90fb23d8805c0 to your computer and use it in GitHub Desktop.
Save coderbyheart/0943e6938ae2449be6f90fb23d8805c0 to your computer and use it in GitHub Desktop.
Matrix Code micro:bit
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