public static Shape Load(string fn) { if (!System.IO.File.Exists(fn)) throw new System.Exception("File not found: " + fn); System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.FileStream(fn, System.IO.FileMode.Open)); Shape s = new Shape(); s.Width = br.ReadInt32(); s.Height = br.ReadInt32(); s.matrix = new bool[s.Width, s.Height]; try { for (int x = 0; x < s.Width; x++) for (int y = 0; y < s.Height; y++) s.notEmptyCellsCount += (s.matrix[x, y] = br.ReadBoolean()) ? 1 : 0; } catch (System.IO.EndOfStreamException) { throw new System.Exception("Invalid data for shape " + fn); } br.Close(); s.CreateTexture(); return s; }
public static Shape Create(bool[,] matrix) { Shape s = new Shape(); s.Width = matrix.GetLength(0); s.Height = matrix.GetLength(1); s.matrix = new bool[s.Width, s.Height]; for (int x = 0; x < s.Width; x++) for (int y = 0; y < s.Height; y++) s.matrix[x, y] = matrix[x, y]; s.CreateTexture(); return s; }