pWidth = 320
pHeight = 200
head = []
info = []
head = "BM".unpack("C*") + [pWidth * pHeight * 3 + 54].pack("L*").unpack("C*") + [0, 0].pack("S*").unpack("C*") + [54].pack("L*").unpack("C*")
info = [40, pWidth, pHeight, 1, 24, 0, pWidth * pHeight * 3 + 4 - (pWidth * pHeight * 3) % 4, 0, 0, 0, 0].pack("LLLSSLLLLLL").unpack("C*")
bmHeader = head + info
bmClrTable = []
(pWidth * pHeight).times{bmClrTable += [random(256), random(256), random(256)]}
bmFile = bmHeader + bmClrTable
file = File.open(File.dirname(__FILE__) + "\\result.bmp", "wb")
bmFile.each{|x| file.print [x].pack("C*")}
file.close
pWidth = 320
pHeight = 200
head = []
info = []
head = "BM".unpack("C*") + [pWidth * pHeight * 3 + 54].pack("L*").unpack("C*") + [0, 0].pack("S*").unpack("C*") + [54].pack("L*").unpack("C*")
info = [40, pWidth, pHeight, 1, 24, 0, pWidth * pHeight * 3 + 4 - (pWidth * pHeight * 3) % 4, 0, 0, 0, 0].pack("LLLSSLLLLLL").unpack("C*")
bmHeader = head + info
bmClrTable = []
(pWidth * pHeight).times{bmClrTable += [random(256), random(256), random(256)]}
bmFile = bmHeader + bmClrTable
file = File.open(File.dirname(__FILE__) + "\\result.bmp", "wb")
bmFile.each{|x| file.print [x].pack("C*")}
file.close