public void PrintBiomes(int[][] map, string imageFileName) { using (var bmp = new Bitmap(map.Length, map.Length, PixelFormat.Format32bppRgb)) { using (LockedBmp lockedBmp = new LockedBmp(bmp)) { unsafe { Parallel.For(0, map.Length, y => { byte *currentLine = lockedBmp.FirstPixel + y * lockedBmp.Stride; for (int x = 0; x < map[y].Length; ++x) { int col = x * lockedBmp.BytesPrPixel; var biome = map[x][y]; var(r, g, b) = ColourMapper.ToBiomeColour255(biome); currentLine[col] = (byte)b; currentLine[col + 1] = (byte)g; currentLine[col + 2] = (byte)r; } }); } } //var filePath = Path.Combine(Paths.PluginPath, $"{imageFileName}.png"); var filePath = Path.Combine("./", $"{imageFileName}.png"); bmp.Save(filePath); } }
public void IntegerToColour255_WhenIdAboveByte_ShouldCarryRemainder() { var(r, g, b) = ColourMapper.IntegerToColor255(300); Assert.AreEqual(0, r); Assert.AreEqual(300 - 255, g); Assert.AreEqual(255, b); }
public void IntegerToColour255() { var(r, g, b) = ColourMapper.IntegerToColor255(0); Assert.AreEqual(0, r); Assert.AreEqual(0, g); Assert.AreEqual(0, b); }
public void MapUserInputtedColourLetterToColours() { var colourMapper = new ColourMapper(); var actual = colourMapper.Map("r,g,y,c"); var expected = new List <Colour>() { Colour.Red, Colour.Green, Colour.Yellow, Colour.Cyan }; Assert.AreEqual(expected, actual); }
public static ImageBuilder SetBiomes(AreaMap areaMap) { var builder = new ImageBuilder(areaMap); for (int x = 0; x < areaMap.MapWidth; ++x) { for (int y = 0; y < areaMap.MapWidth; ++y) { var(r, g, b) = ColourMapper.ToBiomeColour((Heightmap.Biome)areaMap.Biomes[x][y]); builder.image.SetPixel(x, y, new Color(r, g, b)); } } return(builder); }
public static ImageBuilder SetGrayscaleBiomes(AreaMap areaMap) { var builder = new ImageBuilder(areaMap); for (int x = 0; x < areaMap.MapWidth; ++x) { for (int y = 0; y < areaMap.MapWidth; ++y) { var value = areaMap.Biomes[x][y]; var(r, g, b) = ColourMapper.ToBiomeColourGrayscale(value); builder.image.SetPixel(x, y, new Color32((byte)r, (byte)g, (byte)b, 255)); } } return(builder); }
public static ImageBuilder SetRainbowIds(AreaMap areaMap) { var builder = new ImageBuilder(areaMap); for (int x = 0; x < areaMap.MapWidth; ++x) { for (int y = 0; y < areaMap.MapWidth; ++y) { var value = areaMap.AreaIds[x][y]; var(r, g, b) = ColourMapper.Rainbow255(value); Color32 color = new Color32((byte)r, (byte)g, (byte)b, 255); builder.image.SetPixel(x, y, color); } } return(builder); }
private static void PlayGame() { var code = new CodeGenerator(); var codeChecker = new CodeChecker(); var colourMapper = new ColourMapper(); var randomCode = code.Create(); var guess = ""; const string response = "The mark was: "; Console.WriteLine("Welcome to Code Breaker!"); while (guess != "stop") { Console.WriteLine("Please insert your guess (e.g \"r,g,y,c\"): "); guess = Console.ReadLine(); if (guess == "stop") { return; } try { var convertedGuess = colourMapper.Map(guess); var mark = codeChecker.CheckGuess(randomCode, convertedGuess); if (mark == "bbbb") { Console.WriteLine("You have won the game!"); Console.ReadKey(); return; } Console.WriteLine(response + mark + Environment.NewLine); } catch (Exception e) { Console.WriteLine(e.Message + Environment.NewLine); } } Console.ReadKey(); }
public void PrintSquareMap(int[][] map, string imageFileName, bool rainbowOn, int valueRangeMin = 0, int valueRangeMax = 1) { using (var bmp = new Bitmap(map.Length, map.Length, PixelFormat.Format32bppRgb)) { using (LockedBmp lockedBmp = new LockedBmp(bmp)) { unsafe { for (int x = 0; x < map.Length; ++x) { for (int y = 0; y < map.Length; ++y) { byte *currentLine = lockedBmp.FirstPixel + y * lockedBmp.Stride; int col = x * lockedBmp.BytesPrPixel; var id = map[x][y]; if (rainbowOn) { var(r, g, b) = ColourMapper.Rainbow(id); currentLine[col] = (byte)(int)(b * 255); currentLine[col + 1] = (byte)(int)(g * 255); currentLine[col + 2] = (byte)(int)(r * 255); } else { var(r, g, b) = ColourMapper.IntegerToColour3Byte(id); currentLine[col] = (byte)b; currentLine[col + 1] = (byte)g; currentLine[col + 2] = (byte)r; } if (map[x][y] == 0) { currentLine[col] = 255; currentLine[col + 1] = 255; currentLine[col + 2] = 255; } } } /* * Parallel.For(0, map.Length, y => * { * byte* currentLine = lockedBmp.FirstPixel + y * lockedBmp.Stride; * * for (int x = 0; x < map[y].Length; ++x) * { * int col = x * lockedBmp.BytesPrPixel; * * var id = map[y][x]; * if (rainbowOn) * { * var (r, g, b) = ColourMapper.Rainbow(id); * * currentLine[col] = (byte)(int)(b * 255); * currentLine[col + 1] = (byte)(int)(g * 255); * currentLine[col + 2] = (byte)(int)(r * 255); * } * else * { * var (r, g, b) = ColourMapper.IntegerToColor255(id); * currentLine[col] = (byte)b; * currentLine[col + 1] = (byte)g; * currentLine[col + 2] = (byte)r; * } * * if (map[y][x] == 0) * { * currentLine[col] = 255; * currentLine[col + 1] = 255; * currentLine[col + 2] = 255; * } * } * }); */ } } //var filePath = Path.Combine(Paths.PluginPath, $"{imageFileName}.png"); var filePath = Path.Combine("./", $"{imageFileName}.png"); bmp.Save(filePath); } }