local monitor = peripheral.find("monitor")
monitor.setTextScale(0.5)

videoFile = fs.open("video.bin", "rb")
videoData = videoFile.readAll()

monitor.clear()

function drawFrame (frame)
	local byteIndex = frame * 24 * 3

	for y = 1, 24 do
		monitor.setCursorPos(5, y + 2)
		for x = 1, 3 do
			byteIndex = byteIndex + 1
			drawByte(videoData:byte(byteIndex))
		end
	end
end

function drawByte (byte)
	local divisor = 0x80

	for i = 1, 8 do
		local bit = ((byte / divisor) % 2) >= 1
		if bit then
			monitor.setBackgroundColor(colors.white)
		else
			monitor.setBackgroundColor(colors.black)
		end
		monitor.write("  ")
		divisor = divisor / 2
	end
end

for index = 1, 2516 do
	drawFrame(index)
	os.sleep(0.1)
	-- os.sleep(0.5)
end
