/// <summary> /// Creates an Map, showing where People died in this Tick. /// </summary> /// <param name="snapshot"></param> /// <param name="palette"></param> /// <returns>savepath</returns> public unsafe string GetDeathMap(TickSnapshot snapshot, EStatField field, EColorPalette palette, string namePrefix) { Color[] pal = GetPalette(palette); Bitmap map = new Bitmap(X, Y); BitmapData bData = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.ReadWrite, map.PixelFormat); PixelData* start = (PixelData*)bData.Scan0.ToPointer(); PixelData* pixelptr = null; foreach (CellSnapshot cell in snapshot.Cells) { Point p = cell.Position.DeFlatten(X); pixelptr = start + p.X + (p.Y * map.Width); pixelptr->Alpha = 255; pixelptr->Blue = 0; pixelptr->Green = 0; pixelptr->Red = 0; } foreach (HumanSnapshot snap in (HumanSnapshotCreteriaMatcher.GetMatchingHumans(snapshot.Deaths, field))) { Point p = ExtensionMethods.DeFlatten(snap.DeathCell, X); pixelptr = start + p.X + (p.Y * map.Width); pixelptr->Alpha = pal[0].A; pixelptr->Blue = pal[0].B; pixelptr->Green = pal[0].G; pixelptr->Red = pal[0].R; } map.UnlockBits(bData); string path = Target + "/" + namePrefix + "_" + snapshot.Tick + "_D-" + (int)field + ".png"; map.Save(path, System.Drawing.Imaging.ImageFormat.Png); GenerateCaption(_steps, pal); return path; }
public void InitializeMaxima(TickSnapshot firstSnapshot) { foreach (CellSnapshot c in firstSnapshot.Cells) { int max = 0; for (int i = 0; i < 8; ++i) { max += c.Values[i]; } if (max > _max) _max = max; } _steps = GenerateSteps(_max, CalculateSteps(_max)); }
/// <summary> /// Creates a map with the given parameters /// </summary> /// <param name="snapshot">The Snapshot to be mapped</param> /// <param name="field">The Field to be visualised</param> /// <param name="palette">The Color Palette to be used</param> /// <returns>savepath</returns> public unsafe string GetMap(TickSnapshot snapshot, EStatField field, EColorPalette palette, string namePrefix) { Color[] pal = GetPalette(palette); Bitmap map = new Bitmap(X, Y); BitmapData bData = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.ReadWrite, map.PixelFormat); PixelData* start = (PixelData*)bData.Scan0.ToPointer(); PixelData* pixelptr = null; List<int> fields = new List<int>(); foreach (EStatField f in Enum.GetValues(typeof(EStatField))) { if ((f & field) == f) fields.Add((int)Math.Log((double)f, 2d)); } foreach (CellSnapshot cell in snapshot.Cells) { int count = 0; foreach (int i in fields) count += cell.Values[i]; Point p = cell.Position.DeFlatten(X); pixelptr = start + p.X + (p.Y * map.Width); if (count == 0) { pixelptr->Alpha = 255; pixelptr->Blue = 0; pixelptr->Green = 0; pixelptr->Red = 0; } else { for (int i = ColorPalette.RANGE - 1; i >= 0; --i) { if (_steps[i] >= count) { pixelptr->Alpha = pal[i].A; pixelptr->Blue = pal[i].B; pixelptr->Green = pal[i].G; pixelptr->Red = pal[i].R; break; } } } } map.UnlockBits(bData); string path = Target + "/" + namePrefix + "_" + snapshot.Tick + "_S-" + (int)field + ".png"; map.Save(path, ImageFormat.Png); GenerateCaption(_steps, pal); return path; }