Jump to content

Learning. Trying to make a grid.


Recommended Posts

Shouldn't this give me a grid with gaps of 50 pixels between the lines?

 

However it gives nothing like that. 

#region UICode
int Amount1=0; //[0,100]Slider 1 Description
int Amount2=0; //[0,100]Slider 2 Description
int Amount3=0; //[0,100]Slider 3 Description
#endregion


void Render(Surface dst, Surface src, Rectangle rect)
{
    // Delete any of these lines you don't need
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    int CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    int CenterY = ((selection.Bottom - selection.Top) / 2)+selection.Top;
    ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
    ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
    int BrushWidth = (int)EnvironmentParameters.BrushWidth;


    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y += 50)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x += 50)
        {
            CurrentPixel = src[x,y];
            // TODO: Add pixel processing code here
            // Access RGBA values this way, for example:
             CurrentPixel.R = (byte)PrimaryColor.R;
             CurrentPixel.G = (byte)PrimaryColor.G;
             CurrentPixel.B = (byte)PrimaryColor.B;
             CurrentPixel.A = (byte)PrimaryColor.A;
            dst[x,y] = CurrentPixel;
        }
    }
}

Sometimes I get the whole image black, some times I get only vertical lines, sometimes I get horizontal likes with gap only 1 pixel. What gives?

 

Link to comment
Share on other sites

dylanjosh, set all the destination pixels, but choose the pixel color based of its position. I'm not certain what you intend to do, but for the sake of demonstration, I'll make a white background with black lines in each direction spaced 50 apart (49 pixels in between). If I wanted the grid superimposed on the original image, instead of CurrentPixel = ColorBgra.White, I'd use CurrentPixel = src[x, y].

 

Each call to the render code isn't writing the whole destination window at one time; it's writing a portion, referred to as a Rectangle of Interest. Notice the loop bounds for y aren't 0 to dst.Height, they're rect.Top to rect.Bottom. So you can't step by 50, since the starting point can be anywhere within the destination window.

 

Read BoltBait's CodeLab help pages carefully. They describe most everything you'll need to know to write CodeLab plugins.

 

I'll also mention that, ignoring the other problems, what you're doing would only put pixel dots every 50 pixels rather than pixel lines. Assuming you want lines, every y row of pixels contains some grid pixels, so you can't skip over 50 y rows. (To change my code to draw dots instead of lines, replace the || OR with && AND.)

 

(If I were actually writing code to do this, I might do it slightly differently, but this version is straightforward.)

 ColorBgra CurrentPixel;
 for (int y = rect.Top; y < rect.Bottom; y++)
 {
    if (IsCancelRequested) return;
    for (int x = rect.Left; x < rect.Right; x++)
    {
        // See if it's a grid pixel.
        if ((x % 50 == 0) || (y % 50 == 0))
            CurrentPixel = ColorBgra.Black;    // Grid pixel.
        else
            CurrentPixel = ColorBgra.White;    // Not a grid pixel.
        dst[x, y] = CurrentPixel;
    }
}
Edited by MJW
  • Upvote 1
Link to comment
Share on other sites

Another way is to copy all of the source canvas to the destination in one go, then use the 'G.D.I.+' library to 'draw' the lines.
Example codelab code link below. (Do thoroughly read BoltBait's tutorials first)

 

http://forums.getpaint.net/index.php?/topic/31885-request-tablegrid/

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...