Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main.ts
- ----
- // main.ts
- music.beginMelody(collections.duck, MelodyOptions.Once)
- utils.plotMatrix(collections.playImage)
- basic.pause(1000)
- basic.forever(() => {
- utils.plotAnimation(collections.numbers, 1000);
- utils.plotAnimation(collections.animation, 100);
- for (let b = 0; b <= 5 - 1; b++) {
- for (let c = 0; c <= 5 - 1; c++) {
- led.plot(c, b)
- basic.pause(100)
- led.unplot(c, b)
- }
- }
- })
- ----------------------------------------------------------------------------------
- Custom.ts
- ----
- /**
- * Utility Functions
- */
- //% weight=100 color=#0fbc11 icon=""
- namespace utils {
- export let breakFunc = false
- export function plotMatrix(m: Array<Array<NumberFormat>>) {
- b: for (let z = 0; z < m.length; z++) {
- let r = m[z]
- for (let a = 0; a < r.length; a++) {
- if (breakFunc) break b;
- (r[a] > 0) ? led.plot(a, z) : led.unplot(a, z)
- }
- }
- }
- export function plotAnimation(a: Array<Array<Array<NumberFormat>>>, p: NumberFormat) {
- for (let m of a) {
- plotMatrix(m)
- basic.pause(p)
- }
- }
- export function clear() {
- for (let x = 0; x <= 5 - 1; x++) {
- for (let y = 0; y <= 5 - 1; y++) {
- led.unplot(x, y)
- }
- }
- }
- }
- namespace collections {
- export const numbers = [[[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 1, 0, 1, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]], [[0, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]], [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 1, 1, 0]], [[0, 1, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 1, 1, 0], [0, 0, 0, 1, 0], [0, 1, 1, 0, 0]], [[0, 1, 0, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 1, 0]], [[0, 1, 1, 1, 0], [0, 1, 0, 0, 0], [0, 1, 1, 0, 0], [0, 0, 0, 1, 0], [0, 1, 1, 0, 0]], [[0, 0, 1, 1, 0], [0, 1, 0, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]], [[0, 1, 1, 1, 0], [0, 0, 0, 1, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]], [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]], [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 1, 0], [0, 0, 0, 1, 0], [0, 0, 1, 0, 0]]]
- export const animation = [[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]], [[0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0]], [[0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0]], [[1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 0, 0, 0, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1]], [[1, 1, 0, 1, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [1, 1, 0, 1, 1]], [[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]], [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]]
- export const duck = ["c5:4", "d5:4", "e5:4", "f5:4", "g5:8", "g5:8", "a5:4", "a5:4", "a5:4", "a5:4", "g5:16", "a5:4", "a5:4", "a5:4", "a5:4", "g5:16", "f5:4", "f5:4", "f5:4", "f5:4", "e5:8", "e5:8", "g5:4", "g5:4", "g5:4", "g5:4", "c5:16"]
- export const playImage = [[0, 1, 0, 0, 0], [0, 1, 1, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0]]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement