123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- -- Constructs a set of 2D arrays containing some simple block numbers
- local blob = [[
- 000
- 0 0
- 0 0
- 0 0
- 000
- 0
- 0
- 0
- 0
- 0
- 000
- 0
- 000
- 0
- 000
- 000
- 0
- 000
- 0
- 000
- 0 0
- 0 0
- 000
- 0
- 0
- 000
- 0
- 000
- 0
- 000
- 000
- 0
- 000
- 0 0
- 000
- 000
- 0
- 0
- 0
- 0
- 000
- 0 0
- 000
- 0 0
- 000
- 000
- 0 0
- 000
- 0
- 000
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- ]]
- local Board = require 'board'
- local led = {width = 3, height = 5} -- Array part will be an array of Boards
- local current = nil -- Board currently adding pixels to
- local scanning = false -- False when looking for a blank separator line
- local x, y
- for c in blob:gmatch"." do -- Convert the above string to Boards
- if c == "\n" then -- On newline
- if scanning then -- We are already building a Board
- x = 1
- y = y + 1
- if y > led.height then -- Board is full, push Board to "led" and start over
- scanning = false
- table.insert(led, current)
- current = nil
- end
- else -- We haven't started a board yet, this is the blank line between Boards
- scanning = true
- x, y = 1,1
- current = Board.fill({}, led.width, led.height, false)
- end
- else -- On character
- if scanning then
- if c == "0" then -- 0 is true anything else stays false.
- current[x][y] = true
- end
- x = x + 1
- end
- end
- end
- return led
|