How to change location of 3x3 cube inside 6x6 cube

65 Views Asked by At

The problem : I can't change the location of 3x3 cube created inside 6x6 cube.

I will put pictures so it's much easier to understand the problem that I'm facing.

Code :

Xstart - starting location on X axis
Ystart - starting location on Y axis
Xend - ending location on X axis
Yend - ending location on Y axis

using (FileStream file = new FileStream("sample.bmp", FileMode.Create, FileAccess.Write))
{
    file.Write(header);
    int l = (1000 + 31) / 32 * 4;
    var t = new byte[1000 * l];
    RecursiveFigure(t, l, 2, 1000, 1000, 0, 0);
    file.Write(t);
}
static void RecursiveFigure(byte[] t,int l, int recursiveCount, double Xend, double Yend, double Xstart, double Ystart)
{
    if (recursiveCount == 1)
    {
        CreateNet(t, l, 3, Xend, Yend, Xstart, Ystart);
        //CreateBlackBox(t, Xend, Yend, l, 3, Xstart, Ystart);
        return;
    }
    CreateNet(t, l, 6, Xend, Yend, Xstart, Ystart);
    //CreateBlackBox(t, Xend, Yend, l, 6, Xstart, Ystart);
    RecursiveFigure(t, l, recursiveCount - 1, Xend / 6, Yend / 6, 0, 0);
}
static void CreateNet(byte[] t, int l, int boxSize, double Xend, double Yend, double Xstart, double Ystart)
{
    for (int i = 0; i < boxSize; i++)
    {
        int k = Convert.ToInt16(i * Yend / boxSize); // boxSize is always 6x6, except when doing last recursion its 3x3
        int x = Convert.ToInt16(i * Xend / boxSize); // boxSize is always 6x6, except when doing last recursion its 3x3
        DrawVerticle(t, x, l, Ystart, Yend);
        DrawHorizontal(t, k, l, Xstart, Xend);
    }
}
static void DrawVerticle(byte[] t, int s, int l, double Ystart, double Yend)
{
    for (int y = (int)Ystart; y < Yend; y++)
    {
        int index = (y * l) + (s / 8);
        if (index < t.Length)
            t[index] |= (byte)(0x80 >> (s % 8));
    }
}
static void DrawHorizontal(byte[] t, int k, int l, double Xstart, double Xend)
{
    for (int x = (int)Xstart; x < Xend; x++)
    {
        int index = (k * l) + (x / 8);
        if (index < t.Length)
            t[index] |= (byte)(0x80 >> (x % 8));
    }
}

[What I currently have] (https://prnt.sc/GKbRNwUL991U)] [Goal] (https://i.stack.imgur.com/s348h.png)

I was wondering if someone might see the problem in the code or solution. Also, maybe someone has seen any kind of youtube video that explains more about structures on BMP file using recursive.

First idea that came to my mind was to connect vertical and horizontal lines methods into 1 method and use double for cycles but that didn't work for me (might have it done wrong).

for (int y = (Height / 6 / 3); y < (Height / 6 / 3) * 2; y++)
{
    for (int x = (Width / 3 + Width / 6) + (Width / 6 / 3); x < ((Width / 3) * 2) - (Width / 6) / 3; x++)
    {
        int index = y * l + x / 8;
        t[index] |= (byte)(0x80 >> (x % 8));
    }
}

This is the method that I'm using to paint the middle cubes black and tried to recreate it to work with lines but it didn't work.

0

There are 0 best solutions below