This question already has an answer here:
So i'm trying to make a procedural cave generator in c# and so far i have the code for generating a completly random 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");
}
}
}
The image i'm trying to obtain is something like this, except in black and white:
I believe it's because of the random number generator i'm using (i.e. just Random().NextDouble()
). Anyone know a beter RNG for c#?
Aucun commentaire:
Enregistrer un commentaire