我正在尝试创建一个程序来像没有 System.drawing 的图片那样递归地将三角形绘制到 bmp 文件
using System;
using System.IO;
namespace bMP
{
internal class Program
{
static void Main(string[] args)
{
using (FileStream file = new FileStream("result.bmp", FileMode.Create, FileAccess.Write))
{
file.Write(
new byte[62]
{
0x42, 0x4d,
0x3e, 0xf4, 0x1, 0x0,
0x0, 0x0, 0x0, 0x0,
0x3e, 0x0, 0x0, 0x0,
0x28, 0x0, 0x0, 0x0,
0xe8, 0x3, 0x0, 0x0,
0xe8, 0x3, 0x0, 0x0,
0x1, 0x0,
0x1, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0xf4, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0xff, 0xff, 0xff, 0x0,
0x0, 0x0, 0x0, 0x0
});
int l = 128;
var t = new byte[1000 * l];
int triang_lenumber = l / 6;
int max = 8;
int deph = 3;
Stack<int> limiter = new Stack<int>();
limiter.Push(0);
t = TriangleRecursive(l, ref t, triang_lenumber, 1000, max, 0.33, 0.33, ref limiter, 0, 0, deph);
file.Write(t);
file.Close();
}
}
public static byte[] TriangleRecursive(int line_length, ref byte[] matrix, int deduction, int scale, int limit, double modx, double mody, ref Stack<int> limiter, int addx, int addy, int depth)
{
limiter.Push(limiter.Peek() + 1);
if (limiter.Peek() >= depth)
{
limiter.Pop();
return matrix;
}
int ls = line_length;
int triang_lenumber = deduction;
int count = 0;
for (int i = ((int)(scale * mody)) + addy; i < ((int)(scale * (mody * 2))) + addy; i++)
{
for (int j = i * ls + ((int)(ls * modx)) + addx + triang_lenumber; j < i * ls + ((int)(ls * (2 * modx))) + addx - triang_lenumber; j++)
{
matrix[j] = 0xFF;
}
if (count != limit)
count++;
else
{
count = 0;
triang_lenumber--;
}
}
if (limiter.Peek() < depth)
{
//limiter.Push(limiter.Peek() + 1);
matrix = TriangleRecursive(ls, ref matrix, deduction / 2, scale, limit, modx / 2, mody * mody, ref limiter, addx, addy, depth);
matrix = TriangleRecursive(ls, ref matrix, deduction / 2, scale, limit, modx / 2, mody * mody, ref limiter, ls / 2, addy, depth);
matrix = TriangleRecursive(ls, ref matrix, deduction / 2, scale, limit, modx / 2, mody * mody, ref limiter, addx, scale * 2 / 3, depth);
matrix = TriangleRecursive(ls, ref matrix, deduction / 2, scale, limit, modx / 2, mody * mody, ref limiter, ls / 2, scale * 2 / 3, depth);
}
return matrix;
}
}
}
我只让它画到一侧,但我认为我让我的代码画到四个边,我得到这个:
也许有人可以看一下并告诉我哪里出错了?