public static void BiomesWriteImage(double[,] data, int resolution, string path) { // this takes and array of doubles between 0 and 1 and generates a grey scale image from them var arr = new Vector4[resolution, resolution]; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { if (data[x, y] > 1) { data[x, y] = 1; } if (data[x, y] < 0) { data[x, y] = 0; } Color col = new Color(); if (data[x, y] > 0.80) { col = new Color(0f, 5f, 0f, 1f); } else { col = new Color(0, 0, 0, 0); } arr[x, y] = col.ToVector4(); } } byte[] arrBytes = new byte[resolution * resolution * 4]; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { arrBytes[y * resolution * 4 + x * 4] = (byte)((byte)arr[x, y].X * 255f); arrBytes[y * resolution * 4 + x * 4 + 1] = (byte)((byte)arr[x, y].Y * 255f); arrBytes[y * resolution * 4 + x * 4 + 2] = (byte)((byte)arr[x, y].Z * 255f); arrBytes[y * resolution * 4 + x * 4 + 3] = 255; } } Texture2D tex = new Texture2D(NamelessGame.DebugDevice, resolution, resolution, false, SurfaceFormat.Color); tex.SetData(arrBytes); using (var str = File.OpenWrite(path)) { tex.SaveAsPng(str, resolution, resolution); } tex.Dispose(); }
public static void RiverBordersWriteImage(List <List <TileForGeneration> > riverBorders, float[][] heights, int resolution, string path) { var img = new System.Drawing.Bitmap(resolution, resolution, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { var colorRGB = (float)heights[x][y]; if (heights[x][y] > 1) { colorRGB = 1; } if (heights[x][y] <= TileNoiseInterpreter.SeaLevelThreshold) { colorRGB = 0; } var col = new Color(colorRGB, colorRGB, colorRGB, 1f); img.SetPixel(x, resolution - 1 - y, col.ToColor()); } } var random = new InternalRandom(); foreach (var riverBorder in riverBorders) { var color = new Color(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255), 1f); foreach (var tileForGeneration in riverBorder) { img.SetPixel(tileForGeneration.x, resolution - 1 - tileForGeneration.y, color.ToColor()); } } img.Save(path); // Texture2D tex = new Texture2D(NamelessGame.DebugDevice, resolution, resolution, false, SurfaceFormat.Color); //tex.SetData(arrBytes); //using (var str = File.OpenWrite(path)) //{ // tex.SaveAsPng(str, resolution, resolution); //} //tex.Dispose(); }
void DrawTile(GraphicsDevice device, NamelessGame game, int screenPositionX, int screenPositionY, int positionX, int positionY, AtlasTileData atlasTileData, Color color, Color backGroundColor, TileModel foregroundModel, TileModel backgroundModel) { if (atlasTileData == null) { atlasTileData = new AtlasTileData(1, 1); } int tileHeight = game.GetSettings().GetFontSizeZoomed(); int tileWidth = game.GetSettings().GetFontSizeZoomed(); float textureX = atlasTileData.X * (Constants.tileAtlasTileSize / (float)tileAtlas.Width); float textureY = atlasTileData.Y * (Constants.tileAtlasTileSize / (float)tileAtlas.Height); float textureXend = (atlasTileData.X + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Width); float textureYend = (atlasTileData.Y + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Height); var settings = game.GetSettings(); var arrayPosition = (screenPositionX * 4) + (screenPositionY * settings.GetWidthZoomed() * 4); var foregroundvertices = foregroundModel.Vertices; foregroundvertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureX, textureY)); foregroundvertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureXend, textureY)); foregroundvertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureX, textureYend)); foregroundvertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureXend, textureYend)); var backgroundVertices = backgroundModel.Vertices; backgroundVertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureX, textureY)); backgroundVertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureXend, textureY)); backgroundVertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureX, textureYend)); backgroundVertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(), backGroundColor.ToVector4(), new Vector2(textureXend, textureYend)); }
public static void WaterWriteImage(bool[][] data, float[][] heights, int resolution, string path, Color waterColor) { var img = new System.Drawing.Bitmap(resolution, resolution, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int x = 0; x < resolution; x++) { for (int y = 0; y < resolution; y++) { var colorRGB = (float)heights[x][y]; if (heights[x][y] > 1) { colorRGB = 1; } if (heights[x][y] <= TileNoiseInterpreter.SeaLevelThreshold) { colorRGB = 0; } var col = new Color(colorRGB, colorRGB, colorRGB, 1f); if (data[x][y]) { img.SetPixel(x, resolution - 1 - y, waterColor.ToColor()); } else { img.SetPixel(x, resolution - 1 - y, col.ToColor()); } } } img.Save(path); // Texture2D tex = new Texture2D(NamelessGame.DebugDevice, resolution, resolution, false, SurfaceFormat.Color); //tex.SetData(arrBytes); //using (var str = File.OpenWrite(path)) //{ // tex.SaveAsPng(str, resolution, resolution); //} //tex.Dispose(); }
void DrawTile(GraphicsDevice device, NamelessGame game, int positionX, int positionY, AtlasTileData atlasTileData, Color color, Color backGroundColor) { if (atlasTileData == null) { atlasTileData = new AtlasTileData(1, 1); } var fontsize = game.GetSettings().GetFontSizeZoomed(); var tilesize = tileAtlas.Width / 16; if (fontsize < 4) { _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0); } else { _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, backGroundColor.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0); _spriteBatch.Draw(tileAtlas, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), new Rectangle(atlasTileData.X * tilesize, atlasTileData.Y * tilesize, tilesize, tilesize), color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 1); } }