|
|
|
|
using Noise;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
long width = 1024;
|
|
|
|
|
long height = 1024;
|
|
|
|
|
double scaleX = 128.0;
|
|
|
|
|
double scaleY = 128.0;
|
|
|
|
|
|
|
|
|
|
byte[] resBytes = new byte[width*height*3];
|
|
|
|
|
|
|
|
|
|
// Console.WriteLine(PerlinNoise.perlin(3.25 , 0, 0));
|
|
|
|
|
// Console.WriteLine(PerlinNoise.perlin(3.25+256, 0, 0));
|
|
|
|
|
// Console.WriteLine(PerlinNoise.perlin(3.25+512, 0, 0));
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i<width; i++) {
|
|
|
|
|
for(int j = 0; j<height; j++) {
|
|
|
|
|
double res = PerlinNoise.perlin(((double)i)/scaleX, ((double)j)/scaleY, 1.0);
|
|
|
|
|
byte bRes = (byte)(res * 256);
|
|
|
|
|
resBytes[(i*width+j)*3+0] = bRes;
|
|
|
|
|
resBytes[(i*width+j)*3+1] = bRes;
|
|
|
|
|
resBytes[(i*width+j)*3+2] = bRes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var fs = new FileStream("out.rif", FileMode.Create, FileAccess.Write)) {
|
|
|
|
|
// Convert width to a byte array in big-endian order
|
|
|
|
|
byte[] widthBytes = BitConverter.GetBytes(width);
|
|
|
|
|
if (BitConverter.IsLittleEndian)
|
|
|
|
|
Array.Reverse(widthBytes); // Convert to big-endian if the system is little-endian
|
|
|
|
|
|
|
|
|
|
byte[] header = new byte[] {
|
|
|
|
|
// Magic
|
|
|
|
|
0x72, 0x69, 0x66, 0x56, 0x30, 0x30, 0x30, 0x31,
|
|
|
|
|
// Width
|
|
|
|
|
widthBytes[0], widthBytes[1], widthBytes[2], widthBytes[3],
|
|
|
|
|
widthBytes[4], widthBytes[5], widthBytes[6], widthBytes[7],
|
|
|
|
|
// Format (R8G8B8)
|
|
|
|
|
0x00
|
|
|
|
|
};
|
|
|
|
|
fs.Write(header, 0, header.Length);
|
|
|
|
|
fs.Write(resBytes, 0, resBytes.Length);
|
|
|
|
|
}
|