Advertisement
Guest User

calliope code

a guest
Oct 19th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. Main.ts
  2. ----
  3. // main.ts
  4. music.beginMelody(collections.duck, MelodyOptions.Once)
  5. utils.plotMatrix(collections.playImage)
  6. basic.pause(1000)
  7. basic.forever(() => {
  8. utils.plotAnimation(collections.numbers, 1000);
  9. utils.plotAnimation(collections.animation, 100);
  10. for (let b = 0; b <= 5 - 1; b++) {
  11. for (let c = 0; c <= 5 - 1; c++) {
  12. led.plot(c, b)
  13. basic.pause(100)
  14. led.unplot(c, b)
  15. }
  16. }
  17. })
  18.  
  19.  
  20.  
  21. ----------------------------------------------------------------------------------
  22. Custom.ts
  23. ----
  24. /**
  25. * Utility Functions
  26. */
  27. //% weight=100 color=#0fbc11 icon=""
  28. namespace utils {
  29. export let breakFunc = false
  30.  
  31. export function plotMatrix(m: Array<Array<NumberFormat>>) {
  32. b: for (let z = 0; z < m.length; z++) {
  33. let r = m[z]
  34. for (let a = 0; a < r.length; a++) {
  35. if (breakFunc) break b;
  36. (r[a] > 0) ? led.plot(a, z) : led.unplot(a, z)
  37. }
  38. }
  39. }
  40.  
  41. export function plotAnimation(a: Array<Array<Array<NumberFormat>>>, p: NumberFormat) {
  42. for (let m of a) {
  43. plotMatrix(m)
  44. basic.pause(p)
  45. }
  46. }
  47.  
  48. export function clear() {
  49. for (let x = 0; x <= 5 - 1; x++) {
  50. for (let y = 0; y <= 5 - 1; y++) {
  51. led.unplot(x, y)
  52. }
  53. }
  54. }
  55. }
  56.  
  57. namespace collections {
  58. 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]]]
  59. 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]]]
  60. 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"]
  61. 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]]
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement