Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WIDTH = 3;
- HEIGHT = 3;
- SIDE = "back";
- Data = {};
- -- -----------------------------------------------------------------------------------------------
- function Initialize()
- for i = 1, (HEIGHT * WIDTH) do
- Data[i] = false;
- end
- Randomize();
- end
- -- -----------------------------------------------------------------------------------------------
- function Randomize()
- for i = 1, #Data do
- Data[i] = math.random(2) == 1;
- end
- end
- -- -----------------------------------------------------------------------------------------------
- function GetIndex(x, y)
- if (x > WIDTH) then
- print(string.format("ERROR - GetIndex, X out of range: %d of %d", x, WIDTH));
- return nil;
- end
- if (y > HEIGHT) then
- print(string.format("ERROR - GetIndex, Y out of range: %d of %d", y, HEIGHT));
- return nil;
- end
- return ((y - 1) * WIDTH) + x;
- end
- -- -----------------------------------------------------------------------------------------------
- function GetCoords(index)
- local x = math.floor(index / WIDTH) + 1;
- local y = index % WIDTH;
- return x, y;
- end
- -- -----------------------------------------------------------------------------------------------
- function IndexToBitFlag(index)
- return bit.blshift(1, index - 1)
- end
- -- -----------------------------------------------------------------------------------------------
- function Render()
- local output = 0;
- for i = 1, #Data do
- local value = Data[i];
- local flag = IndexToBitFlag(i);
- if (value) then
- output = bit.bor(output, bit);
- else
- output = bit.band(output, bit.bnot(flag));
- end
- end
- rs.setBundledOutput(SIDE, output);
- end
- -- -----------------------------------------------------------------------------------------------
- Initialize();
- -- -----------------------------------------------------------------------------------------------
- while true do
- Randomize();
- Render();
- os.sleep(1);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement