<分区>
我正在尝试创建一个程序化的洞穴生成器,到目前为止我已经有了生成完全随机 map 的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace CelularAutomata
{
class Program
{
static int width=512, height=512;
Boolean[,] cellmap = new Boolean[width, height];
static float chanceToStartAlive = 0.45f;
public static Boolean[,] initialiseMap()
{
Boolean[,] map = new Boolean[width, height];
for (int x = 0; x < width; x++)
{
Random rng = new Random();
for (int y = 0; y < height; y++)
{
doube random = rng.NextDouble();
if (random < chanceToStartAlive)
{
map[x,y] = true;
}
}
}
return map;
}
public static Bitmap createImage(Boolean[,] map)
{
Bitmap bmp = new Bitmap(512, 512);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if (map[x, y])
{
bmp.SetPixel(x, y, Color.FromArgb(255, 255, 255));
}
else
{
bmp.SetPixel(x, y, Color.FromArgb(0, 0, 0));
}
}
Console.Write('\n');
}
return bmp;
}
static void Main(string[] args)
{
Boolean[,] map = initialiseMap();
Bitmap bmp = createImage(map);
bmp.Save("C:\\Users\\radu\\Documents\\Sync\\Licenta\\chamber.png");
}
}
}
我要获取的图像是这样的,除了黑白:
我得到的是这样的:
我相信这是因为我使用的随机数生成器(即只是 Random().NextDouble()
)。
有人知道更好的 RNG 吗?