led.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. -- Constructs a set of 2D arrays containing some simple block numbers
  2. local blob = [[
  3. 000
  4. 0 0
  5. 0 0
  6. 0 0
  7. 000
  8. 0
  9. 0
  10. 0
  11. 0
  12. 0
  13. 000
  14. 0
  15. 000
  16. 0
  17. 000
  18. 000
  19. 0
  20. 000
  21. 0
  22. 000
  23. 0 0
  24. 0 0
  25. 000
  26. 0
  27. 0
  28. 000
  29. 0
  30. 000
  31. 0
  32. 000
  33. 000
  34. 0
  35. 000
  36. 0 0
  37. 000
  38. 000
  39. 0
  40. 0
  41. 0
  42. 0
  43. 000
  44. 0 0
  45. 000
  46. 0 0
  47. 000
  48. 000
  49. 0 0
  50. 000
  51. 0
  52. 000
  53. 0
  54. 0
  55. 0
  56. 0
  57. 0
  58. 0
  59. 0
  60. ]]
  61. local Board = require 'board'
  62. local led = {width = 3, height = 5} -- Array part will be an array of Boards
  63. local current = nil -- Board currently adding pixels to
  64. local scanning = false -- False when looking for a blank separator line
  65. local x, y
  66. for c in blob:gmatch"." do -- Convert the above string to Boards
  67. if c == "\n" then -- On newline
  68. if scanning then -- We are already building a Board
  69. x = 1
  70. y = y + 1
  71. if y > led.height then -- Board is full, push Board to "led" and start over
  72. scanning = false
  73. table.insert(led, current)
  74. current = nil
  75. end
  76. else -- We haven't started a board yet, this is the blank line between Boards
  77. scanning = true
  78. x, y = 1,1
  79. current = Board.fill({}, led.width, led.height, false)
  80. end
  81. else -- On character
  82. if scanning then
  83. if c == "0" then -- 0 is true anything else stays false.
  84. current[x][y] = true
  85. end
  86. x = x + 1
  87. end
  88. end
  89. end
  90. return led